Class Imports

java.lang.Object
org.glassfish.rmic.tools.java.Imports
All Implemented Interfaces:
Constants, RuntimeConstants

public class Imports extends Object implements Constants
This class describes the classes and packages imported from a source file. A Hashtable called bindings is maintained to quickly map symbol names to classes. This table is flushed everytime a new import is added. A class name is resolved as follows: - if it is a qualified name then return the corresponding class - if the name corresponds to an individually imported class then return that class - check if the class is defined in any of the imported packages, if it is then return it, make sure it is defined in only one package - assume that the class is defined in the current package WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.
  • Field Details

    • currentPackage

      Identifier currentPackage
      The current package, which is implicitly imported, and has precedence over other imported packages.
    • currentPackageWhere

      long currentPackageWhere
      A location for the current package declaration. Used to report errors against the current package.
    • classes

      The imported classes, including memoized imports from packages.
    • packages

      The imported package identifiers. This will not contain duplicate imports for the same package. It will also not contain the current package.
    • singles

      The (originally) imported classes. A vector of IdentifierToken.
    • checked

      protected int checked
      Are the import names checked yet?
  • Constructor Details

    • Imports

      public Imports(Environment env)
      Constructor, always import java.lang.
  • Method Details

    • resolve

      public void resolve(Environment env)
      Check the names of the imports.
    • resolve

      public Identifier resolve(Environment env, Identifier nm) throws ClassNotFound
      Lookup a class, given the current set of imports, AmbiguousClass exception is thrown if the name can be resolved in more than one way. A ClassNotFound exception is thrown if the class is not found in the imported classes and packages.
      Throws:
      ClassNotFound
    • importable

      public static boolean importable(Identifier id, Environment env)
      Check to see if 'id' names an importable class in `env'. This method was made public and static for utility.
    • forceResolve

      public Identifier forceResolve(Environment env, Identifier nm)
      Suppose a resolve() call has failed. This routine can be used silently to give a reasonable default qualification (the current package) to the identifier. This decision is recorded for future reference.
    • addClass

      public void addClass(IdentifierToken t)
      Add a class import
    • addClass

      public void addClass(Identifier nm) throws AmbiguousClass
      Throws:
      AmbiguousClass
    • addPackage

      public void addPackage(IdentifierToken t)
      Add a package import, or perhaps an inner class scope. Ignore any duplicate imports.
    • addPackage

      public void addPackage(Identifier id)
    • setCurrentPackage

      public void setCurrentPackage(IdentifierToken t)
      Specify the current package with an IdentifierToken.
    • setCurrentPackage

      public void setCurrentPackage(Identifier id)
      Specify the current package
    • getCurrentPackage

      public Identifier getCurrentPackage()
      Report the current package
    • getImportedPackages

      public List<IdentifierToken> getImportedPackages()
      Return an unmodifiable list of IdentifierToken representing packages specified as imports.
    • getImportedClasses

      public List<IdentifierToken> getImportedClasses()
      Return an unmodifiable list of IdentifierToken representing classes specified as imports.
    • newEnvironment

      public Environment newEnvironment(Environment env)
      Extend an environment with my resolve() method.