polyglot.types
Class ImportTable

java.lang.Object
  extended by polyglot.types.ClassResolver
      extended by polyglot.types.ImportTable
All Implemented Interfaces:
Resolver

public class ImportTable
extends ClassResolver

An ImportTable is a type of ClassResolver that corresponds to a particular source file.

It has a set of package and class imports, which caches the results of lookups for future reference.


Field Summary
protected  java.util.List classImports
          List of explicitly imported classes added to the table or pending in the lazyImports list.
protected  java.util.List lazyImports
          List of class imports which will be lazily added to the table at the next lookup.
protected  java.util.Map map
          Map from names to classes found, or to the NOT_FOUND object.
protected  java.util.List packageImports
          A list of all package imports.
protected  Package pkg
          Our package
protected  Resolver resolver
          The underlying resolver.
protected  java.lang.String sourceName
          Source name to use for debugging and error reporting
protected  Position sourcePos
          Position to use for error reporting
protected  TypeSystem ts
           
 
Constructor Summary
ImportTable(TypeSystem ts, Resolver base, Package pkg)
          Create an import table.
ImportTable(TypeSystem ts, Resolver base, Package pkg, java.lang.String src)
          Create an import table.
 
Method Summary
 void addClassImport(java.lang.String className)
          Add a class import.
 void addPackageImport(java.lang.String pkgName)
          Add a package import.
protected  Named cachedFind(java.lang.String name)
          Find a type by name, using the cache and the outer resolver, but not the import table.
 java.util.List classImports()
          List the classes explicitly imported.
 Named find(java.lang.String name)
          Find a type by name, searching the import table.
protected  Named findInPkg(java.lang.String name, java.lang.String pkgName)
           
protected  boolean isVisibleFrom(Named n, java.lang.String pkgName)
          Return whether n in package pkgName is visible from within package pkg.
protected  void lazyImport()
          Load the class imports, lazily.
 Package package_()
          The package of the source we are importing types into.
 java.util.List packageImports()
          List the packages we import from.
 java.lang.String sourceName()
          The name of the source file we are importing into.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ts

protected TypeSystem ts

resolver

protected Resolver resolver
The underlying resolver.


packageImports

protected java.util.List packageImports
A list of all package imports.


map

protected java.util.Map map
Map from names to classes found, or to the NOT_FOUND object.


lazyImports

protected java.util.List lazyImports
List of class imports which will be lazily added to the table at the next lookup.


classImports

protected java.util.List classImports
List of explicitly imported classes added to the table or pending in the lazyImports list.


sourceName

protected java.lang.String sourceName
Source name to use for debugging and error reporting


sourcePos

protected Position sourcePos
Position to use for error reporting


pkg

protected Package pkg
Our package

Constructor Detail

ImportTable

public ImportTable(TypeSystem ts,
                   Resolver base,
                   Package pkg)
Create an import table.

Parameters:
ts - The type system
base - The outermost resolver to use for looking up types.
pkg - The package of the source we are importing types into.

ImportTable

public ImportTable(TypeSystem ts,
                   Resolver base,
                   Package pkg,
                   java.lang.String src)
Create an import table.

Parameters:
ts - The type system
base - The outermost resolver to use for looking up types.
pkg - The package of the source we are importing types into.
src - The name of the source file we are importing into.
Method Detail

package_

public Package package_()
The package of the source we are importing types into.


addClassImport

public void addClassImport(java.lang.String className)
Add a class import.


addPackageImport

public void addPackageImport(java.lang.String pkgName)
Add a package import.


packageImports

public java.util.List packageImports()
List the packages we import from.


classImports

public java.util.List classImports()
List the classes explicitly imported.


sourceName

public java.lang.String sourceName()
The name of the source file we are importing into.


cachedFind

protected Named cachedFind(java.lang.String name)
                    throws SemanticException
Find a type by name, using the cache and the outer resolver, but not the import table.

Throws:
SemanticException

find

public Named find(java.lang.String name)
           throws SemanticException
Find a type by name, searching the import table.

Specified by:
find in interface Resolver
Specified by:
find in class ClassResolver
Throws:
SemanticException

findInPkg

protected Named findInPkg(java.lang.String name,
                          java.lang.String pkgName)
                   throws SemanticException
Throws:
SemanticException

isVisibleFrom

protected boolean isVisibleFrom(Named n,
                                java.lang.String pkgName)
Return whether n in package pkgName is visible from within package pkg. The empty string may be passed in to represent the default package.


lazyImport

protected void lazyImport()
                   throws SemanticException
Load the class imports, lazily.

Throws:
SemanticException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object