jdk/src/share/classes/sun/tools/java/Imports.java
author ntoda
Thu, 31 Jul 2014 17:01:24 -0700
changeset 25799 1afc4675dc75
parent 5506 202f599c92aa
permissions -rw-r--r--
8044867: Fix raw and unchecked lint warnings in sun.tools.* Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.java;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This class describes the classes and packages imported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * from a source file. A Hashtable called bindings is maintained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * to quickly map symbol names to classes. This table is flushed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * everytime a new import is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A class name is resolved as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  - if it is a qualified name then return the corresponding class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *  - if the name corresponds to an individually imported class then return that class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  - check if the class is defined in any of the imported packages,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *    if it is then return it, make sure it is defined in only one package
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  - assume that the class is defined in the current package
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * WARNING: The contents of this source file are not part of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * supported API.  Code that depends on them does so at its own risk:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * they are subject to change or removal without notice.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
class Imports implements Constants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The current package, which is implicitly imported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * and has precedence over other imported packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    Identifier currentPackage = idNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * A location for the current package declaration.  Used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * report errors against the current package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    long currentPackageWhere = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * The imported classes, including memoized imports from packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
    70
    Hashtable<Identifier, Identifier> classes = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The imported package identifiers.  This will not contain duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * imports for the same package.  It will also not contain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * current package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
    77
    Vector<IdentifierToken> packages = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * The (originally) imported classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * A vector of IdentifierToken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
    83
    Vector<IdentifierToken> singles = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Are the import names checked yet?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected int checked;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Constructor, always import java.lang.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public Imports(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        addPackage(idJavaLang);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Check the names of the imports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public synchronized void resolve(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (checked != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        checked = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // After all class information has been read, now we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // safely inspect import information for errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // If we did this before all parsing was finished,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // we could get vicious circularities, since files can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // import each others' classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // A note: the resolution of the package java.lang takes place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // in the sun.tools.javac.BatchEnvironment#setExemptPackages().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // Make sure that the current package's name does not collide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // with the name of an existing class. (bug 4101529)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        // This change has been backed out because, on WIN32, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // failed to distinguish between java.awt.event and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // java.awt.Event when looking for a directory.  We will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // add this back in later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // if (currentPackage != idNull) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        //    Identifier resolvedName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        //      env.resolvePackageQualifiedName(currentPackage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        //   Identifier className = resolvedName.getTopName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        //   if (importable(className, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        //      // The name of the current package is also the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        //      // of a class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        //      env.error(currentPackageWhere, "package.class.conflict",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        //                currentPackage, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        //     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   137
        Vector<IdentifierToken> resolvedPackages = new Vector<>();
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   138
        for (Enumeration<IdentifierToken> e = packages.elements() ; e.hasMoreElements() ;) {
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   139
            IdentifierToken t = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            Identifier nm = t.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            long where = t.getWhere();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            // Check to see if this package is exempt from the "exists"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            // check.  See the note in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            // sun.tools.javac.BatchEnvironment#setExemptPackages()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            // for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (env.isExemptPackage(nm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                resolvedPackages.addElement(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            // (Note: This code is moved from BatchParser.importPackage().)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                Identifier rnm = env.resolvePackageQualifiedName(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                if (importable(rnm, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    // This name is a real class; better not be a package too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    if (env.getPackage(rnm.getTopName()).exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        env.error(where, "class.and.package",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                  rnm.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    // Pass an "inner" name to the imports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    if (!rnm.isInner())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        rnm = Identifier.lookupInner(rnm, idNull);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    nm = rnm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                } else if (!env.getPackage(nm).exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    env.error(where, "package.not.found", nm, "import");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                } else if (rnm.isInner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    // nm exists, and rnm.getTopName() is a parent package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    env.error(where, "class.and.package", rnm.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                resolvedPackages.addElement(new IdentifierToken(where, nm));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            } catch (IOException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                env.error(where, "io.exception", "import");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        packages = resolvedPackages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   178
        for (Enumeration<IdentifierToken> e = singles.elements() ; e.hasMoreElements() ;) {
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   179
            IdentifierToken t = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            Identifier nm = t.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            long where = t.getWhere();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            Identifier pkg = nm.getQualifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            // (Note: This code is moved from BatchParser.importClass().)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            nm = env.resolvePackageQualifiedName(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            if (!env.classExists(nm.getTopName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                env.error(where, "class.not.found", nm, "import");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            // (Note: This code is moved from Imports.addClass().)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            Identifier snm = nm.getFlatName().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            // make sure it isn't already imported explicitly
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   194
            Identifier className = classes.get(snm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            if (className != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                Identifier f1 = Identifier.lookup(className.getQualifier(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                                  className.getFlatName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                Identifier f2 = Identifier.lookup(nm.getQualifier(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                                  nm.getFlatName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                if (!f1.equals(f2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    env.error(where, "ambig.class", nm, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            classes.put(snm, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // The code here needs to check to see, if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // are importing an inner class, that all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // enclosing classes are visible to us.  To check this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // we need to construct a definition for the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            // The code here used to call...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            //     ClassDefinition def = env.getClassDefinition(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            // ...but that interfered with the basicCheck()'ing of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // interfaces in certain cases (bug no. 4086139).  Never
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            // fear.  Instead we load the class with a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            // new getClassDefinitionNoCheck() which does no basicCheck() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            // lets us answer the questions we are interested in w/o
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            // interfering with the demand-driven nature of basicCheck().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                // Get a declaration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                ClassDeclaration decl = env.getClassDeclaration(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                // Get the definition (no env argument)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                ClassDefinition def = decl.getClassDefinitionNoCheck(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // Get the true name of the package containing this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // `pkg' from above is insufficient.  It includes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                // names of our enclosing classes.  Fix for 4086815.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                Identifier importedPackage = def.getName().getQualifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                // Walk out the outerClass chain, ensuring that each level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                // is visible from our perspective.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                for (; def != null; def = def.getOuterClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    if (def.isPrivate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                        || !(def.isPublic()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                             || importedPackage.equals(currentPackage))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        env.error(where, "cant.access.class", def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            } catch (AmbiguousClass ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                env.error(where, "ambig.class", ee.name1, ee.name2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            } catch (ClassNotFound ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                env.error(where, "class.not.found", ee.name, "import");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        checked = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Lookup a class, given the current set of imports,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * AmbiguousClass exception is thrown if the name can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * resolved in more than one way. A ClassNotFound exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * is thrown if the class is not found in the imported classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * and packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public synchronized Identifier resolve(Environment env, Identifier nm) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if (tracing) env.dtEnter("Imports.resolve: " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        // If the class has the special ambiguous prefix, then we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // get the original AmbiguousClass exception by removing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // prefix and proceeding in the normal fashion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // (part of solution for 4059855)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (nm.hasAmbigPrefix()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            nm = nm.removeAmbigPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (nm.isQualified()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            // Don't bother it is already qualified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (tracing) env.dtExit("Imports.resolve: QUALIFIED " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return nm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (checked <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            checked = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            resolve(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        // Check if it was imported before
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   283
        Identifier className = classes.get(nm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (className != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (tracing) env.dtExit("Imports.resolve: PREVIOUSLY IMPORTED " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // Note: the section below has changed a bit during the fix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // for bug 4093217.  The current package is no longer grouped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // with the rest of the import-on-demands; it is now checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        // separately.  Also, the list of import-on-demands is now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // guarranteed to be duplicate-free, so the code below can afford
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        // to be a bit simpler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // First we look in the current package.  The current package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // is given precedence over the rest of the import-on-demands,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // which means, among other things, that a class in the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // package cannot be ambiguous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        Identifier id = Identifier.lookup(currentPackage, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (importable(id, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            className = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            // If it isn't in the current package, try to find it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            // our import-on-demands.
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   306
            Enumeration<IdentifierToken> e = packages.elements();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            while (e.hasMoreElements()) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   308
                IdentifierToken t = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                id = Identifier.lookup(t.getName(), nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                if (importable(id, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        // We haven't found any other matching classes yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        // Set className to what we've found and continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        // looking for an ambiguity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        className = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                            env.dtExit("Imports.resolve: AMBIGUOUS " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        // We've found an ambiguity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                        throw new AmbiguousClass(className, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        // Make sure a class was found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (className == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            if (tracing) env.dtExit("Imports.resolve: NOT FOUND " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            throw new ClassNotFound(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // Remember the binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        classes.put(nm, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (tracing) env.dtExit("Imports.resolve: FIRST IMPORT " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Check to see if 'id' names an importable class in `env'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * This method was made public and static for utility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    static public boolean importable(Identifier id, Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (!id.isInner()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return env.classExists(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else if (!env.classExists(id.getTopName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            // load the top class and look inside it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                // There used to be a call to...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                //    env.getClassDeclaration(id.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                // ...here.  It has been replaced with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                // two statements below.  These should be functionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                // the same except for the fact that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                // getClassDefinitionNoCheck() does not call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                // basicCheck().  This allows us to avoid a circular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // need to do basicChecking that can arise with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                // certain patterns of importing and inheritance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                // This is a fix for a variant of bug 4086139.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                // Note: the special case code in env.getClassDefinition()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                // which handles inner class names is not replicated below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                // This should be okay, as we are looking up id.getTopName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                // not id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                ClassDeclaration decl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    env.getClassDeclaration(id.getTopName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                ClassDefinition c =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    decl.getClassDefinitionNoCheck(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                return c.innerClassExists(id.getFlatName().getTail());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            } catch (ClassNotFound ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Suppose a resolve() call has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * This routine can be used silently to give a reasonable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * default qualification (the current package) to the identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * This decision is recorded for future reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public synchronized Identifier forceResolve(Environment env, Identifier nm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (nm.isQualified())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            return nm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   389
        Identifier className = classes.get(nm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (className != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        className = Identifier.lookup(currentPackage, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        classes.put(nm, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Add a class import
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public synchronized void addClass(IdentifierToken t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        singles.addElement(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    // for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public void addClass(Identifier nm) throws AmbiguousClass {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        addClass(new IdentifierToken(nm));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * Add a package import, or perhaps an inner class scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Ignore any duplicate imports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public synchronized void addPackage(IdentifierToken t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        final Identifier name = t.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        // If this is a duplicate import for the current package,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (name == currentPackage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // If this is a duplicate of a package which has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        // added to the list, ignore it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        final int size = packages.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        for (int i = 0; i < size; i++) {
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   428
            if (name == (packages.elementAt(i)).getName()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // Add the package to the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        packages.addElement(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    // for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public void addPackage(Identifier id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        addPackage(new IdentifierToken(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Specify the current package with an IdentifierToken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public synchronized void setCurrentPackage(IdentifierToken t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        currentPackage = t.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        currentPackageWhere = t.getWhere();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Specify the current package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public synchronized void setCurrentPackage(Identifier id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        currentPackage = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Report the current package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public Identifier getCurrentPackage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return currentPackage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Return an unmodifiable list of IdentifierToken representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * packages specified as imports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   467
    public List<IdentifierToken> getImportedPackages() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return Collections.unmodifiableList(packages);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Return an unmodifiable list of IdentifierToken representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * classes specified as imports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
25799
1afc4675dc75 8044867: Fix raw and unchecked lint warnings in sun.tools.*
ntoda
parents: 5506
diff changeset
   475
    public List<IdentifierToken> getImportedClasses() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        return Collections.unmodifiableList(singles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Extend an environment with my resolve() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public Environment newEnvironment(Environment env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return new ImportEnvironment(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
class ImportEnvironment extends Environment {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    Imports imports;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    ImportEnvironment(Environment env, Imports imports) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        super(env, env.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        this.imports = imports;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    public Identifier resolve(Identifier nm) throws ClassNotFound {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return imports.resolve(this, nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public Imports getImports() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return imports;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
}