mjc

org.multijava.mjc
Class CCompilationUnit

java.lang.Object
  extended byorg.multijava.mjc.CCompilationUnit
All Implemented Interfaces:
CMemberHost

public class CCompilationUnit
extends Object
implements CMemberHost

This class handles namespace management for a compilation unit. Based on the imports and package of a compilation unit, this class includes methods for resolving partially-qualified names. This class also tracks the external members declared in a compilation unit.


Field Summary
private  ArrayList directlyVisibleTypes
          The set of reference types that are directly visible in this compilation unit.
private  JClassOrGFImportType[] importedClasses
           
private  JClassOrGFImportType[] importedGFs
           
private  JPackageImportType[] importedPackages
           
private  Hashtable loadedClasses
          Maps from type names to classes.
private  CGFCollectionMap loadedGFCollections
          Maps from identifiers to sets of external generic function collections that are in scope and loaded for this compilation unit.
private static TokenReference NO_TOKEN
          Used for error reporting.
private  String packageName
           
private  HashSet resolvedGFNames
          Tracks the names of the generic functions for which we have completed the package and import-on-demand search.
private  HashSet visibleMethods
          Tracks the methods that are referenced within this.
 
Constructor Summary
CCompilationUnit(String packageName)
          Constructs a minimal compilation unit context for hosting CBinaryClasses.
 
Method Summary
 boolean descendsFrom(CClass maybeSuper)
          Indicates whether this host is a subclass of the given class, where "subclass" is the reflexive, transitive closure of the extends relation.
 Collection directlyVisibleTypes()
          Returns the set of (non-reference) types that are directly visible in this compilation unit.
 CMemberHost host()
          Returns the host of this host, that is, the context in which this host is declared.
 String ident()
          Gives the identifier for this host, or null for a compilation unit.
 JClassOrGFImportType[] importedClasses()
           
 JPackageImportType[] importedPackages()
           
 boolean isAccessibleFrom(CMemberHost from)
          Indicates whether this is accessible from the given host.
 boolean isClass()
          Indicates whether this host is a class.
 boolean isCompilationUnit()
          Indicates whether this host is a compilation unit
 boolean isDefinedInside(CMemberHost maybeOutside)
          Indicates whether this is defined inside the given host.
 boolean isInnerClass()
          Indicates whether this host is an inner class, i.e., a non-static member class.
 boolean isNestedType()
          Indicates whether this host is a nested type, i.e., a member type, a type declared within another type.
 CClass lookupClass(String name, CContextType context)
          Searches for a class with the given simple name according the procedure in JLS2 6.5.5.
 boolean nestedDescendsFrom(CClass maybeOuterSuper)
          Returns true if this host is a subclass of the given class or if some host of this host is a subclass of the given class.
 String packageName()
          Gives the package name for this host.
(package private)  void registerGFDecl(String ident, CGenericFunctionCollection coll)
          Registers the declaration of an external generic function in this compilation unit.
 void registerVisibleMethod(CMethod method)
          Registers that a declaration of the given method occurs in the compilation unit represented by this.
 void registerVisibleType(CType type)
          Registers that a reference to the given type occurs in the compilation unit represented by this.
 void resolveMaybeExtMethodRef(CCompilationUnitContextType context, String name)
          Searches for any imported external generic functions.
 void update(JClassOrGFImportType[] importedClasses, JClassOrGFImportType[] importedGFs, JPackageImportType[] importedPackages, Hashtable loadedClasses, CGFCollectionMap loadedGFCollections)
          Updates the compilation unit after completion of grouping open methods.
 Collection visibleMethods()
          Returns a string representation of this.
 Collection visibleTypes()
          Returns the set of (non-reference) types that are directly or transitively visible in this compilation unit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

packageName

private final String packageName

importedClasses

private JClassOrGFImportType[] importedClasses

importedGFs

private JClassOrGFImportType[] importedGFs

importedPackages

private JPackageImportType[] importedPackages

loadedClasses

private Hashtable loadedClasses
Maps from type names to classes. Tracks all classes referenced within this compilation unit. Used to efficiently resolve short class names to their fully qualified types. Invariant: all values stored in table are of type CClassType and have had checkType called on them.

See Also:
CClassType, JCompilationUnit, JCompilationUnit.allLoadedClasses

loadedGFCollections

private CGFCollectionMap loadedGFCollections
Maps from identifiers to sets of external generic function collections that are in scope and loaded for this compilation unit. Single-gf-import-on-demand clauses and local external generic function declarations are loaded as early as possible. Generic functions that are in scope because of the package declaration or import-on-demand clauses are added to the map lazily.

See Also:
alias to this field in JCompilatoinUnit

resolvedGFNames

private HashSet resolvedGFNames
Tracks the names of the generic functions for which we have completed the package and import-on-demand search.

See Also:
resolveMaybeExtMethodRef(CCompilationUnitContextType,String)

visibleMethods

private HashSet visibleMethods
Tracks the methods that are referenced within this.


directlyVisibleTypes

private ArrayList directlyVisibleTypes
The set of reference types that are directly visible in this compilation unit. It's important for this field to be an ordered collection, because otherwise we see some cross-platform discrepancies in the error messages produced.


NO_TOKEN

private static final TokenReference NO_TOKEN
Used for error reporting.

Constructor Detail

CCompilationUnit

public CCompilationUnit(String packageName)
Constructs a minimal compilation unit context for hosting CBinaryClasses.

Parameters:
packageName - the packageName of the compilation unit
Method Detail

lookupClass

public CClass lookupClass(String name,
                          CContextType context)
                   throws UnpositionedError
Searches for a class with the given simple name according the procedure in JLS2 6.5.5. By the time the search reaches this method the first three bullet points of the procedure have been checked. This method checks the remaining bullet points:

Parameters:
name - the class name, without qualifiers
context - used for error reporting
Returns:
the class if found, null otherwise
Throws:
UnpositionedError - if search fails

resolveMaybeExtMethodRef

public void resolveMaybeExtMethodRef(CCompilationUnitContextType context,
                                     String name)
Searches for any imported external generic functions. Handles implicit imports (generic functions in the current package or in imported packages.)

Parameters:
context - the compilation unit context in which the generic functions found are to be visible
name - the name of the generic function to search for

registerGFDecl

void registerGFDecl(String ident,
                    CGenericFunctionCollection coll)
Registers the declaration of an external generic function in this compilation unit.


registerVisibleMethod

public void registerVisibleMethod(CMethod method)
Registers that a declaration of the given method occurs in the compilation unit represented by this.


registerVisibleType

public void registerVisibleType(CType type)
Registers that a reference to the given type occurs in the compilation unit represented by this.


update

public void update(JClassOrGFImportType[] importedClasses,
                   JClassOrGFImportType[] importedGFs,
                   JPackageImportType[] importedPackages,
                   Hashtable loadedClasses,
                   CGFCollectionMap loadedGFCollections)
Updates the compilation unit after completion of grouping open methods.

Parameters:
importedClasses - the single-type imports
importedGFs - the single-GF imports
importedPackages - the import-on-demand imports
loadedClasses - the classes actually loaded by this, initialized in JCompilationUnit based on declarations and imports, and then maintained here for other references
loadedGFCollections - the external GFs actually loaded
See Also:
JCompilationUnitType.checkInterface( Main )

isAccessibleFrom

public boolean isAccessibleFrom(CMemberHost from)
Indicates whether this is accessible from the given host.

Specified by:
isAccessibleFrom in interface CMemberHost
Parameters:
from - the host that wants access
Returns:
true iff the given host is allowed access to this host's members

isDefinedInside

public boolean isDefinedInside(CMemberHost maybeOutside)
Indicates whether this is defined inside the given host.

Specified by:
isDefinedInside in interface CMemberHost
Parameters:
maybeOutside - the host that this may be inside
Returns:
true if the given host is a (possibly reflexive and transitive) host of this

descendsFrom

public boolean descendsFrom(CClass maybeSuper)
Indicates whether this host is a subclass of the given class, where "subclass" is the reflexive, transitive closure of the extends relation.

Specified by:
descendsFrom in interface CMemberHost
Parameters:
maybeSuper - the potential superclass

nestedDescendsFrom

public boolean nestedDescendsFrom(CClass maybeOuterSuper)
Returns true if this host is a subclass of the given class or if some host of this host is a subclass of the given class.

Specified by:
nestedDescendsFrom in interface CMemberHost
Parameters:
maybeOuterSuper - the potential superclass

isClass

public boolean isClass()
Indicates whether this host is a class.

Specified by:
isClass in interface CMemberHost
Returns:
true iff this host represents a class

isNestedType

public boolean isNestedType()
Indicates whether this host is a nested type, i.e., a member type, a type declared within another type.

Specified by:
isNestedType in interface CMemberHost

isInnerClass

public boolean isInnerClass()
Indicates whether this host is an inner class, i.e., a non-static member class.

Specified by:
isInnerClass in interface CMemberHost

isCompilationUnit

public boolean isCompilationUnit()
Indicates whether this host is a compilation unit

Specified by:
isCompilationUnit in interface CMemberHost
Returns:
true iff this host represents a compilation unit

ident

public String ident()
Gives the identifier for this host, or null for a compilation unit.

Specified by:
ident in interface CMemberHost

packageName

public String packageName()
Gives the package name for this host.

Specified by:
packageName in interface CMemberHost

host

public CMemberHost host()
Returns the host of this host, that is, the context in which this host is declared. This value is null except for inner classes.

Specified by:
host in interface CMemberHost
Returns:
the host of this host

visibleMethods

public Collection visibleMethods()
Returns a string representation of this.

Returns:
a string representation of this Returns the methods that are declared within this compilation unit.

directlyVisibleTypes

public Collection directlyVisibleTypes()
Returns the set of (non-reference) types that are directly visible in this compilation unit.


visibleTypes

public Collection visibleTypes()
Returns the set of (non-reference) types that are directly or transitively visible in this compilation unit. For efficiency this method caches its result. The method should only be called after all members of the compilation unit have been typechecked.


importedClasses

public JClassOrGFImportType[] importedClasses()

importedPackages

public JPackageImportType[] importedPackages()

mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.