Changeset 12297


Ignore:
Timestamp:
Jan 28, 2019 1:48:17 PM (11 months ago)
Author:
mjohnsson
Message:

#5726 Working solution

File:
1 edited

Legend:

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

    r12296 r12297  
    19311931     * Returns something annotatable either of 
    19321932     */
    1933     public SrcAnnotatable InstClassDecl.matchFromEnviroment(String qualifiedName) {
    1934         Environment enviroment = myInstClass().myEnvironment();
    1935         for (InstModification im : enviroment) {
    1936             if (im.qualifiedMatches(qualifiedName)) {
    1937                 SrcAnnotatable annotatable = im.getSrcModification();
    1938                 SrcAnnotationProvider provider = annotatable.srcAnnotationProvider();
    1939                 annotatable = provider.isClassRedeclare() ?
    1940                         provider.getSrcClassRedeclare() : annotatable;
    1941                 if (annotatable.srcAnnotationProvider().hasAnnotation()) {
    1942                     return annotatable;
    1943                 }
    1944             }
    1945         }
    1946         return null;
    1947     }
    1948    
    1949     /**
    1950      *
    1951      */
    1952     public SrcAnnotatable InstComponentDecl.matchFromEnviroment(String qualifiedName) {
    1953         Environment enviroment = filteredEnvironment();
     1933    public SrcAnnotatable InstNode.matchFromEnviroment(String qualifiedName) {
     1934        Environment enviroment = myEnvironment();
    19541935        for (InstModification im : enviroment) {
    19551936            if (im.qualifiedMatches(qualifiedName)) {
     
    19591940                        provider.getSrcClassRedeclare() : annotatable;
    19601941                annotatable = provider.isComponentRedeclare() ?
    1961                         provider.getSrcClassRedeclare() : annotatable;
     1942                        provider.getSrcComponentRedeclare() : annotatable;
    19621943                if (annotatable.srcAnnotationProvider().hasAnnotation()) {
    19631944                    return annotatable;
     
    19671948        return null;
    19681949    }
    1969    
     1950
    19701951    /**
    19711952    * Includes the qualified class name for the class containing the topmost enclosing component.
     
    19821963        return qualifiedName();
    19831964    }
    1984    
    1985     syn String InstComponentDecl.fullyQualifiedTypeName() =
    1986         topMostComponentDecl().qualifiedTypeName() + "." + qualifiedName().replaceFirst(".*\\.", "");
    1987    
     1965
     1966    syn String InstComponentDecl.fullyQualifiedTypeName() {
     1967        String qualifiedName =  qualifiedName();
     1968        int dot = qualifiedName.indexOf(".");
     1969        if (dot > -1) {
     1970            qualifiedName = qualifiedName.substring(dot + 1);
     1971        }
     1972        return topMostComponentDecl().myInstClass().qualifiedName() + "." + qualifiedName;
     1973    }
     1974
     1975    /**
     1976     * obtaining the owning source modification or entity.
     1977     */
    19881978    syn SrcAnnotatable InstModification.getElementModification() = getSrcModification();
    19891979    eq InstValueModification.getElementModification() = elementModification();
     
    19961986   
    19971987    /** Match the correct modification and function  */
    1998     public boolean InstModification.qualifiedMatches(String qualifiedName) {
    1999         return qualifiedNameWithClass().equals(qualifiedName);
    2000     }
     1988    syn boolean InstModification.qualifiedMatches(String qualifiedName) =
     1989        qualifiedNameWithClass().equals(qualifiedName);
    20011990   
    20021991    /**
     
    20322021    }
    20332022
    2034    
    2035     public SrcAnnotatable InstClassDecl.orginalAnnotatable() {
    2036         return getSrcClassDecl();
    2037     }
    2038    
    2039     public SrcAnnotatable InstComponentDecl.orginalAnnotatable() = getSrcComponentDecl();
     2023    syn SrcAnnotatable InstClassDecl.orginalAnnotatable() = getSrcClassDecl();
     2024    syn SrcAnnotatable InstComponentDecl.orginalAnnotatable() = getSrcComponentDecl();
     2025    eq InstReplacingComposite.orginalAnnotatable() = getOriginalInstComponent().getSrcComponentDecl();
    20402026   
    20412027    public SrcAnnotatable InstReplacingShortClassDecl.orginalAnnotatable() {
     
    20612047    }
    20622048
     2049    /**
     2050     * Obtain the SrcAnnotationProvider respecting the inheritance.
     2051     */
    20632052    public SrcAnnotationProvider InstClassDecl.myAnnotation() {
    20642053        return mySrcAnnotatable().srcAnnotationProvider();
     
    20702059            return annotatable;
    20712060        }
    2072         return getSrcComponentDecl();
     2061        if (topMostComponentDecl()!= null) {
     2062            annotatable = matchFromEnviroment(fullyQualifiedTypeName());
     2063            if (annotatable != null) {
     2064                return annotatable;
     2065            }
     2066        }
     2067        SrcAnnotatable orginal = getSrcComponentDecl();
     2068        if (orginal.srcAnnotationProvider().hasAnnotation()) {
     2069            return orginal;
     2070        }
     2071        return myInstClass().mySrcAnnotatable();
    20732072    }
    20742073   
     2074    /**
     2075     * Obtain the source node which is responsable for providing the annotation.
     2076     * A match against this with the same qualifiedName and same fullyQualifiedName is made in the
     2077     * Enviroment.
     2078     */
    20752079    public SrcAnnotatable InstAbstractShortClassDecl.mySrcAnnotatable() {
    20762080        boolean hasAnnotations = getSrcClassDecl().srcAnnotationProvider().hasAnnotation();
    20772081        if (!hasAnnotations) {
    2078             if (myInstClass() != null) {
    2079                 SrcAnnotatable annotatable = matchFromEnviroment(qualifiedName());
    2080                 if (annotatable != null) {
    2081                     return annotatable;
    2082                 }
    2083                 annotatable = matchFromEnviroment(fullyQualifiedName());
    2084                 if (annotatable != null) {
    2085                     return annotatable;
    2086                 }
    2087                 return orginalAnnotatable();
    2088             }
     2082            SrcAnnotatable annotatable = matchFromEnviroment(qualifiedName());
     2083            if (annotatable != null) {
     2084                return annotatable;
     2085            }
     2086            annotatable = matchFromEnviroment(fullyQualifiedName());
     2087            if (annotatable != null) {
     2088                return annotatable;
     2089            }
     2090            return orginalAnnotatable();
    20892091        }
    20902092        return getSrcClassDecl();
     
    20922094
    20932095    /**
    2094      * Obtain the source node which is responsable for annotations.
     2096     * Obtain the source node which is responsable for providing the annotation.
    20952097     */
    20962098    public SrcAnnotatable InstClassDecl.mySrcAnnotatable() {
     
    21002102    /**
    21012103     * Test method which obtains the string representation of the
    2102      * annotation for the only inner class to this class.
    2103      * Should not when multiple internal classes are present.
    2104      *
    2105      */
    2106     public String InstClassDecl.testOnlyAnnotation() {
    2107         InstClassDecl iclass = allInstClassDeclsIterator().next();
    2108         if (iclass == null  || iclass.isUnknown())
    2109             iclass = allInstClassDeclsIterator().next();
    2110        
     2104     * annotation for the inner class with the given name.
     2105     * This method is only intended for testing
     2106     */
     2107    public String InstClassDecl.testClassAnnotations(String name) {
     2108        InstClassDecl iclass = null;
     2109        for (InstClassDecl icd :  allInstClassDecls()) {
     2110            if (icd.matches(name)) {
     2111                iclass = icd;
     2112                break;
     2113            }
     2114        }
    21112115        Iterator<AnnotationNode> iter = iclass.annotation().iterator();
    21122116        return iter.hasNext() ? iter.next().toString() : "";
     
    21142118
    21152119    /**
    2116      *  Test method which can obtain either a class or component of a given name from a
    2117      *  component in the current class.
     2120     *  Test method which can obtain either a inner class or inner component of a given name from a
     2121     *  component in the current class.
     2122     *  Requires there to only be one component with a inner class or inner component with the given name.
     2123     *  This method is only intended for testing
    21182124     */
    21192125    public String InstClassDecl.testComponentAnnotations(boolean clazz, String name) {
Note: See TracChangeset for help on using the changeset viewer.