Changeset 12863


Ignore:
Timestamp:
May 27, 2019 10:58:19 AM (7 months ago)
Author:
mjohnsson
Message:

#5771 Updated java doc and corrected behaviour for encapsulated classes.

Location:
branches/dev-2154/Compiler/ModelicaFrontEnd
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-2154/Compiler/ModelicaFrontEnd/src/jastadd/source/SimpleLookup.jrag

    r12843 r12863  
    8585
    8686    /**
     87     * Lookup the class referenced by the QualifiedName.
     88     * Lookup is both uncached and only among the class members and imported.
     89     * This method is intended as a entry point
     90     */
     91     public SrcClassDecl SrcClassDecl.LookupMyMembers(QualifiedName qName) {
     92        SrcClassDecl cd = this;
     93        cd = simpleLookupMemberScope(qName.next()).getClassDecl();
     94
     95        while (cd != null && qName.hasNext()) {
     96            cd = cd.simpleLookupMemberScope(qName.next()).getClassDecl();
     97            if (cd == null) {
     98                return null;
     99            }
     100        }
     101        return cd;
     102    }
     103
     104    /**
    87105     * Lookup the class referenced by the QualifiedName. The QualifiedName
    88106     * determines if the lookup is in relative or global scope.
     107     * This method is intended as a entry point
    89108     *
    90109     */
     
    103122            }
    104123        }
     124
     125        if (cd.isUnknown() && !qName.isGlobal() && enclosingClassDecl() != null) {
     126            if (!qName.isGlobal() && enclosingClassDecl() != null && !isEncapsulated()) {
     127                return enclosingClassDecl().simpleLookupClass(qName.resetedCopy());
     128            }
     129        }
    105130        return cd;
    106131    }
     
    110135    * Support lookup of both global and relative qualified names.
    111136    * Returns null when the class isn't found.
     137    * This method is intended as entry point.
    112138    */
    113139    public SrcClassDecl Program.simpleLookupClass(String name) {
     
    331357    /**
    332358     * Lookup in contained elements, extended classes, imports and surrounding classes.
    333      *  Has to be an unqualified classname.
     359     * Has to be an simple (unqualified) classname.
     360     * Result is Cached.
    334361     */
    335362    syn lazy ResolvedAccess SrcFullClassDecl.simpleLookupDefaultScope(String name) {
     
    367394    /**
    368395     * Lookup simple name in contained classes, extends and imports but not in surrounding classes.
    369      * Has to be an unqualified classname.
     396     * Has to be an simple (unqualified) classname.
     397     * Result is Cached.
    370398     */
    371399    syn ResolvedAccess SrcClassDecl.simpleLookupIncludeImports(String name) = simpleLookupMemberScope(name);
     
    379407
    380408    /**
    381      * Lookup in contained classes, components, imports and surrounding classes. Has to be an unqualified classname.
     409     * Lookup in contained classes, components, imports and surrounding classes.
     410     * Has to be an unqualified name.
     411     * Result is cached.
    382412     */
    383413    syn lazy ResolvedAccess SrcFullClassDecl.simpleLookupLocalScope(String name) {
     
    404434    /**
    405435     * Lookup in contained classes and extended classes. Has to be an unqualified classname.
     436     * Internal helper method resolving a simple (unqualified) name. Result is Cached.
    406437     */
    407438    syn ResolvedAccess SrcClassDecl.simpleLookupMemberScope(String name);
     
    412443    /**
    413444     * Lookup in contained classes, components and extended classes.
    414      * Has to be an unqualified classname.
     445     * Has to be an simple (unqualified) name.
    415446     * Method doesn't lookup in surrounding classes.
    416447     * This method returns the unknown class when the class isn't found.
     448     * Result is Cached.
    417449     */
    418450    syn lazy ResolvedAccess SrcFullClassDecl.simpleLookupMemberScope(String name) {
     
    479511
    480512    /**
    481     * Helper method which search for the class in the imported class.
    482     * Has to be an unqualified classname.
     513    * Internal helper method which search for the class in the imported class.
     514    * Has to be an simple (unqualified) classname.
     515    * Result is Cached.
    483516    */
    484517    syn ResolvedAccess SrcImportClause.simpleLookupInImport(String name) =
     
    489522
    490523    /**
    491      * Helper method which looks for the class with the given name among this class's imported classes.
     524     * Internal helper method which looks for the class with the given name among this class's imported classes.
    492525     * Has to be an unqualified classname.
    493526     * This method returns the unknown class when the class isn't found.
     527     * Result is Cached.
    494528     */
    495529    protected ResolvedAccess SrcFullClassDecl.simpleLookupInImports(String name) {
     
    506540
    507541    /**
    508      * Helper method which looks for the class with the given name among this class's super classes.
    509      * Has to be an unqualified classname.
     542     * Internal helper method which looks for the class with the given name among this class's super classes.
     543     * Has to be an simpe (unqualified) classname.
    510544     * This method returns the unknown class when the class isn't found.
     545     * Result is Cached.
    511546     */
    512547    protected ResolvedAccess SrcFullClassDecl.simpleLookupInExtends(String name) {
     
    521556        return unknownAccess();
    522557    }
    523 
     558   
     559   /**
     560    *  Internal helper method resolving a simple (unqualified) name. Result is Cached.
     561    */
    524562    protected ResolvedAccess SrcComponentDecl.simpleLookupFromModification(String name) {
    525563        ResolvedAccess res = findClassDecl().simpleLookupMemberScope(name);
  • branches/dev-2154/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/junit/TreeJModelicaRunner.java

    r12628 r12863  
    1919import java.io.FilenameFilter;
    2020import java.util.ArrayList;
    21 import java.util.Collections;
    2221import java.util.List;
    2322
  • branches/dev-2154/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/QualifiedName.java

    r12834 r12863  
    6464   
    6565    private final boolean isGlobal;
    66     private final ArrayList<String> names = new ArrayList<>();
     66    private final ArrayList<String> names;
    6767    private final boolean isUnQualifiedImport;
    6868    private final Iterator<String> iterator;
     
    7171        isUnQualifiedImport = name.endsWith(".*");
    7272        isGlobal = name.startsWith(".");
     73        names = new ArrayList<>();
    7374        splitQualifiedClassName(name);
    7475        iterator = names.iterator();
     76    }
     77   
     78    private QualifiedName(QualifiedName orginal) {
     79        isUnQualifiedImport = orginal.isUnQualifiedImport;
     80        isGlobal = orginal.isGlobal;
     81        names = orginal.names;
     82        iterator =names.iterator();
     83    }
     84   
     85    public QualifiedName resetedCopy() {
     86        return new QualifiedName(this);
    7587    }
    7688
     
    7890    public QualifiedName(String name, boolean isGlobal) {
    7991        isUnQualifiedImport = name.endsWith(".*");
     92        names = new ArrayList<>();
    8093        splitQualifiedClassName(name);
    8194        this.isGlobal = isGlobal; // Note: must be set after splitting
  • branches/dev-2154/Compiler/ModelicaFrontEnd/test/modelica/SimpleLookup.mo

    r12843 r12863  
    224224end SurroundingLookup;
    225225
     226model EncapsulatedLookup
     227    encapsulated model A
     228        model B
     229            model encapsulatedLookup
     230            annotation(__JModelica(UnitTesting(tests={
     231            SourceMethodTestCase(
     232                name="Relative",
     233                description="External functions: simple func, all default",
     234                methodName="testSimpleClassLookup",
     235                argumentTypes={"[Ljava.lang.String;"},
     236                arguments={{"SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup", "EncapsulatedLookup",
     237                            "SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup", "A",
     238                            "SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup", "B",
     239                            "SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup", "SimpleLookup.EncapsulatedLookup.A.B",
     240                            "SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup", ".SimpleLookup.EncapsulatedLookup.A.B"
     241                            }
     242                },
     243                methodResult="
     244SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup
     245->
     246Unknown
     247
     248SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup
     249->
     250Unknown
     251
     252SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup
     253->
     254SimpleLookup.EncapsulatedLookup.A.B
     255
     256SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup
     257->
     258Unknown
     259
     260SimpleLookup.EncapsulatedLookup.A.B.encapsulatedLookup
     261->
     262SimpleLookup.EncapsulatedLookup.A.B
     263
     264
     265       
     266            ")})));
     267            end encapsulatedLookup;
     268        end B;
     269    end A;
     270
     271end EncapsulatedLookup;
     272
    226273model RelativeLookup
    227274    model A
Note: See TracChangeset for help on using the changeset viewer.