Changeset 12303


Ignore:
Timestamp:
Jan 29, 2019 1:23:05 PM (11 months ago)
Author:
mjohnsson
Message:

#5726 Clean up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-5726-orginal-annotation/Compiler/ModelicaFrontEnd/src/jastadd/util/Annotations.jrag

    r12298 r12303  
    19091909    }
    19101910   
     1911    /**
     1912     * obtaining the owning source modification or entity. Primary used to
     1913     * obtain the Component / ComponentModification
     1914     */
     1915    syn SrcAnnotatable InstModification.getElementModification() = getSrcModification();
     1916    eq InstValueModification.getElementModification() = elementModification();
     1917   
     1918    inh SrcAnnotatable InstValueModification.elementModification();
     1919    eq  InstModification.getChild().elementModification() = getSrcModification();
     1920    eq  InstComponentDecl.getChild().elementModification() = getSrcComponentDecl();
     1921    eq  InstClassDecl.getChild().elementModification() = getSrcClassDecl();
     1922    eq  InstNode.getChild().elementModification() = null;
     1923
    19111924    SrcModificationOrRedeclareElement extends SrcAnnotatable;
    19121925    SrcClassDecl implements SrcAnnotatable;
     
    19211934    }
    19221935
    1923    
    1924     /**
    1925      * Find the topMost enclosing component.
    1926      * Return null if enclosingComponentDecl.
    1927      */
    1928     inh InstComponentDecl InstComponentDecl.topMostComponentDecl();
    1929     eq InstComponentDecl.getChild().topMostComponentDecl() {
    1930         InstComponentDecl next = topMostComponentDecl();
    1931         return next != null ? next : this;
    1932     }
    1933     eq InstRoot.getChild().topMostComponentDecl() = null;
    1934 
    1935     /**
    1936      * Find the enclosing class to the topmost component
    1937      */
    1938     public InstClassDecl InstComponentDecl.enclosingClassTopMostComponentDecl() {
    1939         InstComponentDecl topComponent = topMostComponentDecl();
    1940         topComponent = topComponent != null ? topComponent : this;
    1941         return !topComponent.isUnknown() ? topComponent.enclosingInstClassDecl() : null;
    1942     }
    1943 
    19441936    /**
    1945      * Match the qualified name for a component or class against modifications in the enviroment
    1946      * Returns something annotatable either of
    1947      */
    1948     public SrcAnnotatable InstNode.matchFromEnviroment(String qualifiedName) {
     1937     * Search for the applicable annotation from the enviroment. FilteredEnviroment
     1938     * is not used since it peeling which is undesireable
     1939     */
     1940    public SrcAnnotatable InstNode.srcannotatableFromEnviroment() {
    19491941        Environment enviroment = myEnvironment();
    19501942        for (InstModification im : enviroment) {
    1951             if (im.qualifiedMatches(qualifiedName)) {
     1943            if (im.matches(name())) {
    19521944                SrcAnnotatable annotatable = im.getElementModification();
    19531945                SrcAnnotationProvider provider = annotatable.srcAnnotationProvider();
     
    19651957
    19661958    /**
    1967     * Includes the qualified class name for the class containing the topmost enclosing component.
    1968     * Equivalent to enclosingClassTopMostComponentDecl().qualifiedName()+ "." + qualifiedName()
    1969     */
    1970     syn String InstComponentDecl.fullyQualifiedName() =
    1971         enclosingClassTopMostComponentDecl().qualifiedName() + "." + qualifiedName();
    1972 
    1973     syn String InstClassDecl.fullyQualifiedName() {
    1974         InstComponentDecl icomp = containingInstComponent();
    1975         if (icomp != null) {
    1976             return icomp.myInstClass().fullyQualifiedName() + "." + name();
    1977         }
    1978         return qualifiedName();
    1979     }
    1980 
    1981     syn String InstComponentDecl.fullyQualifiedTypeName() {
    1982         String qualifiedName =  qualifiedName();
    1983         int dot = qualifiedName.indexOf(".");
    1984         if (dot > -1) {
    1985             qualifiedName = qualifiedName.substring(dot + 1);
    1986         }
    1987         return topMostComponentDecl().myInstClass().qualifiedName() + "." + qualifiedName;
    1988     }
    1989 
    1990     /**
    1991      * obtaining the owning source modification or entity.
    1992      */
    1993     syn SrcAnnotatable InstModification.getElementModification() = getSrcModification();
    1994     eq InstValueModification.getElementModification() = elementModification();
    1995    
    1996     inh SrcAnnotatable InstValueModification.elementModification();
    1997     eq  InstModification.getChild().elementModification() = getSrcModification();
    1998     eq  InstComponentDecl.getChild().elementModification() = getSrcComponentDecl();
    1999     eq  InstClassDecl.getChild().elementModification() = getSrcClassDecl();
    2000     eq  InstNode.getChild().elementModification() = null;
    2001    
    2002     /** Match the correct modification and function  */
    2003     syn boolean InstModification.qualifiedMatches(String qualifiedName) =
    2004         qualifiedNameWithClass().equals(qualifiedName);
    2005    
    2006     /**
    2007      * Obtain the fully qualified name including containing class name of this component.
    2008      * Allows matching with the name provided from InstComponentDecl.fullyQualifiedName().
    2009      */
    2010     public String InstModification.qualifiedNameWithClass() {
    2011         return " ";
    2012     }
    2013    
    2014     public String InstValueModification.qualifiedNameWithClass() {
    2015         InstModification parent = parentInstModification();
    2016         if (parent != null && parent != this) {
    2017             return parent.qualifiedNameWithClass();
    2018         }
    2019         return myTargetComponent().fullyQualifiedName();
    2020     }
    2021 
    2022     public String InstNamedModification.qualifiedNameWithClass() {
    2023         InstComponentDecl targetComponent = myTargetComponent();
    2024      
    2025         String fullName = "";
    2026         if (targetComponent.isUnknown()) {
    2027             InstClassDecl enclosingClass = enclosingInstClassDecl();
    2028             if (enclosingClass != null) {
    2029                 fullName = enclosingClass.qualifiedName() + ".";
    2030             }
    2031             fullName = fullName + name();
    2032         }else {
    2033             fullName = targetComponent.fullyQualifiedName() + "." + name();
    2034         }
    2035         return fullName;
    2036     }
    2037 
     1959     * Obtaines the orginal annotatable for a class or component.
     1960     *   
     1961     */
    20381962    syn SrcAnnotatable InstClassDecl.orginalAnnotatable() = getSrcClassDecl();
    20391963    syn SrcAnnotatable InstComponentDecl.orginalAnnotatable() = getSrcComponentDecl();
    2040     eq InstReplacingComposite.orginalAnnotatable() = getOriginalInstComponent().getSrcComponentDecl();
     1964    eq InstReplacingComposite.orginalAnnotatable() {
     1965        InstComponentDecl component = getOriginalInstComponent();
     1966        if (!component.isUnknown()) {
     1967            return component.getSrcComponentDecl();
     1968        }
     1969        // Throw or raise suitable exception
     1970        return getSrcComponentDecl();
     1971    }
    20411972   
    20421973    public SrcAnnotatable InstReplacingShortClassDecl.orginalAnnotatable() {
     
    20481979            }
    20491980        }
     1981        // Throw or raise suitable exception
    20501982        return getSrcClassDecl();
    20511983    }
     
    20702002
    20712003    public SrcAnnotatable InstComponentDecl.mySrcAnnotatable() {
    2072         SrcAnnotatable annotatable = matchFromEnviroment(fullyQualifiedName());
    2073         if (annotatable != null) {
    2074             return annotatable;
    2075         }
    2076         if (topMostComponentDecl()!= null) {
    2077             annotatable = matchFromEnviroment(fullyQualifiedTypeName());
    2078             if (annotatable != null) {
    2079                 return annotatable;
    2080             }
    2081         }
    2082         SrcAnnotatable orginal = getSrcComponentDecl();
    2083         if (orginal.srcAnnotationProvider().hasAnnotation()) {
    2084             return orginal;
    2085         }
    2086         return myInstClass().mySrcAnnotatable();
     2004        SrcAnnotatable annotatable = srcannotatableFromEnviroment();
     2005        if (annotatable != null) {
     2006            return annotatable;
     2007        }
     2008        SrcAnnotatable orginal = getSrcComponentDecl();
     2009        if (orginal.srcAnnotationProvider().hasAnnotation()) {
     2010            return orginal;
     2011        }
     2012        return myInstClass().mySrcAnnotatable();
    20872013    }
    20882014   
     
    20952021        boolean hasAnnotations = getSrcClassDecl().srcAnnotationProvider().hasAnnotation();
    20962022        if (!hasAnnotations) {
    2097             SrcAnnotatable annotatable = matchFromEnviroment(qualifiedName());
    2098             if (annotatable != null) {
    2099                 return annotatable;
    2100             }
    2101             annotatable = matchFromEnviroment(fullyQualifiedName());
     2023            SrcAnnotatable annotatable = srcannotatableFromEnviroment();
    21022024            if (annotatable != null) {
    21032025                return annotatable;
Note: See TracChangeset for help on using the changeset viewer.