edu.rice.cs.dynamicjava.interpreter
Class ImportContext

java.lang.Object
  extended by edu.rice.cs.dynamicjava.interpreter.DelegatingContext
      extended by edu.rice.cs.dynamicjava.interpreter.ImportContext
All Implemented Interfaces:
TypeContext

public class ImportContext
extends DelegatingContext

The context at the top level of a source file or local block. Manages package and import statements.


Constructor Summary
ImportContext(java.lang.ClassLoader loader, Options opt)
          Make a top-level context that delegates to a LibraryContext based on the given class loader.
ImportContext(TypeContext next, Options opt)
          Make a top-level context that delegates to the given context.
 
Method Summary
 Access.Module accessModule()
          Get the current access module.
protected  TypeContext duplicate(TypeContext next)
          Create a copy of this context with the given context enclosing it.
 boolean fieldExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope field
 boolean functionExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope method or local function
 java.lang.Iterable<Type> getDeclaredThrownTypes()
          The types that are allowed to be thrown in the current context.
 java.lang.Iterable<LocalFunction> getLocalFunctions(java.lang.String name, TypeSystem ts, java.lang.Iterable<LocalFunction> partial)
          Helper for getLocalFunctions: list all matching functions, including those provided.
 LocalVariable getLocalVariable(java.lang.String name, TypeSystem ts)
          Return the variable object for the given name, or null if it does not exist.
 Type getReturnType()
          The expected type of a return statement in the given context, or null if return statements should not appear here.
 DJClass getThis()
          Return the type of this in the current context, or null if there is no such value (for example, in a static context).
 DJClass getThis(java.lang.String className)
          Return the type of className.this in the current context, or null if there is no such value (for example, in a static context).
 DJClass getThis(Type expected, TypeSystem ts)
          Return the innermost "this" class with the given type in the current context, or null if there is no such value (for example, in a static context).
 DJClass getTopLevelClass(java.lang.String name, TypeSystem ts)
          Return the top-level class with the given name, or null if it does not exist.
 TypeContext importField(DJClass c, java.lang.String name)
          Import the field(s) of c with the given name
 TypeContext importMemberClass(DJClass outer, java.lang.String name)
          Import the member class(es) of outer with the given name
 TypeContext importMemberClasses(DJClass outer)
          Import on demand all member classes of the given class
 TypeContext importMethod(DJClass c, java.lang.String name)
          Import the method(s) of c with the given name
 TypeContext importStaticMembers(DJClass c)
          Import on demand all static members of the given class
 TypeContext importTopLevelClass(DJClass c)
          Import the given top-level class
 TypeContext importTopLevelClasses(java.lang.String pkg)
          Import on demand all top-level classes in the given package
 DJClass initializingClass()
          Class which is being initialized (via a constructor or initialization block); null otherwise.
 boolean localFunctionExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope local function
 boolean localVariableExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope local variable
 java.lang.String makeAnonymousClassName()
          Return a full name for an anonymous class declared here.
 java.lang.String makeClassName(java.lang.String n)
          Return a full name for a class with the given name declared here.
 boolean memberClassExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope member class
 boolean methodExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope method
 TypeContext setPackage(java.lang.String name)
          Set the current package to the given package name
 boolean topLevelClassExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope top-level class
 ClassType typeContainingField(java.lang.String name, TypeSystem ts)
          Return the most inner type containing a field with the given name, or null if there is no such type.
 ClassType typeContainingMemberClass(java.lang.String name, TypeSystem ts)
          Return the most inner type containing a class with the given name, or null if there is no such type.
 Type typeContainingMethod(java.lang.String name, TypeSystem ts)
          Return the most inner type containing a method with the given name, or null if there is no such type.
 boolean typeExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope top-level class, member class, or type variable
 boolean variableExists(java.lang.String name, TypeSystem ts)
          Test whether name is an in-scope field or local variable
 
Methods inherited from class edu.rice.cs.dynamicjava.interpreter.DelegatingContext
getClassLoader, getLocalFunctions, getTypeVariable, typeVariableExists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImportContext

public ImportContext(java.lang.ClassLoader loader,
                     Options opt)
Make a top-level context that delegates to a LibraryContext based on the given class loader. The context is initialized with an on-demand import of "java.lang".


ImportContext

public ImportContext(TypeContext next,
                     Options opt)
Make a top-level context that delegates to the given context. The context is initialized with an on-demand import of "java.lang".

Method Detail

duplicate

protected TypeContext duplicate(TypeContext next)
Description copied from class: DelegatingContext
Create a copy of this context with the given context enclosing it.

Specified by:
duplicate in class DelegatingContext

setPackage

public TypeContext setPackage(java.lang.String name)
Set the current package to the given package name

Specified by:
setPackage in interface TypeContext
Overrides:
setPackage in class DelegatingContext

importTopLevelClasses

public TypeContext importTopLevelClasses(java.lang.String pkg)
Import on demand all top-level classes in the given package

Specified by:
importTopLevelClasses in interface TypeContext
Overrides:
importTopLevelClasses in class DelegatingContext

importMemberClasses

public TypeContext importMemberClasses(DJClass outer)
Import on demand all member classes of the given class

Specified by:
importMemberClasses in interface TypeContext
Overrides:
importMemberClasses in class DelegatingContext

importStaticMembers

public TypeContext importStaticMembers(DJClass c)
Import on demand all static members of the given class

Specified by:
importStaticMembers in interface TypeContext
Overrides:
importStaticMembers in class DelegatingContext

importTopLevelClass

public TypeContext importTopLevelClass(DJClass c)
Import the given top-level class

Specified by:
importTopLevelClass in interface TypeContext
Overrides:
importTopLevelClass in class DelegatingContext

importMemberClass

public TypeContext importMemberClass(DJClass outer,
                                     java.lang.String name)
Import the member class(es) of outer with the given name

Specified by:
importMemberClass in interface TypeContext
Overrides:
importMemberClass in class DelegatingContext

importField

public TypeContext importField(DJClass c,
                               java.lang.String name)
Import the field(s) of c with the given name

Specified by:
importField in interface TypeContext
Overrides:
importField in class DelegatingContext

importMethod

public TypeContext importMethod(DJClass c,
                                java.lang.String name)
Import the method(s) of c with the given name

Specified by:
importMethod in interface TypeContext
Overrides:
importMethod in class DelegatingContext

typeExists

public boolean typeExists(java.lang.String name,
                          TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope top-level class, member class, or type variable

Specified by:
typeExists in interface TypeContext
Overrides:
typeExists in class DelegatingContext

topLevelClassExists

public boolean topLevelClassExists(java.lang.String name,
                                   TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope top-level class

Specified by:
topLevelClassExists in interface TypeContext
Overrides:
topLevelClassExists in class DelegatingContext

getTopLevelClass

public DJClass getTopLevelClass(java.lang.String name,
                                TypeSystem ts)
                         throws AmbiguousNameException
Description copied from class: DelegatingContext
Return the top-level class with the given name, or null if it does not exist.

Specified by:
getTopLevelClass in interface TypeContext
Overrides:
getTopLevelClass in class DelegatingContext
Throws:
AmbiguousNameException

memberClassExists

public boolean memberClassExists(java.lang.String name,
                                 TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope member class

Specified by:
memberClassExists in interface TypeContext
Overrides:
memberClassExists in class DelegatingContext

typeContainingMemberClass

public ClassType typeContainingMemberClass(java.lang.String name,
                                           TypeSystem ts)
                                    throws AmbiguousNameException
Description copied from class: DelegatingContext
Return the most inner type containing a class with the given name, or null if there is no such type.

Specified by:
typeContainingMemberClass in interface TypeContext
Overrides:
typeContainingMemberClass in class DelegatingContext
Throws:
AmbiguousNameException

variableExists

public boolean variableExists(java.lang.String name,
                              TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope field or local variable

Specified by:
variableExists in interface TypeContext
Overrides:
variableExists in class DelegatingContext

fieldExists

public boolean fieldExists(java.lang.String name,
                           TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope field

Specified by:
fieldExists in interface TypeContext
Overrides:
fieldExists in class DelegatingContext

typeContainingField

public ClassType typeContainingField(java.lang.String name,
                                     TypeSystem ts)
                              throws AmbiguousNameException
Description copied from class: DelegatingContext
Return the most inner type containing a field with the given name, or null if there is no such type.

Specified by:
typeContainingField in interface TypeContext
Overrides:
typeContainingField in class DelegatingContext
Throws:
AmbiguousNameException

localVariableExists

public boolean localVariableExists(java.lang.String name,
                                   TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope local variable

Specified by:
localVariableExists in interface TypeContext
Overrides:
localVariableExists in class DelegatingContext

getLocalVariable

public LocalVariable getLocalVariable(java.lang.String name,
                                      TypeSystem ts)
Description copied from class: DelegatingContext
Return the variable object for the given name, or null if it does not exist.

Specified by:
getLocalVariable in interface TypeContext
Overrides:
getLocalVariable in class DelegatingContext

functionExists

public boolean functionExists(java.lang.String name,
                              TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope method or local function

Specified by:
functionExists in interface TypeContext
Overrides:
functionExists in class DelegatingContext

methodExists

public boolean methodExists(java.lang.String name,
                            TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope method

Specified by:
methodExists in interface TypeContext
Overrides:
methodExists in class DelegatingContext

typeContainingMethod

public Type typeContainingMethod(java.lang.String name,
                                 TypeSystem ts)
Description copied from class: DelegatingContext
Return the most inner type containing a method with the given name, or null if there is no such type.

Specified by:
typeContainingMethod in interface TypeContext
Overrides:
typeContainingMethod in class DelegatingContext

localFunctionExists

public boolean localFunctionExists(java.lang.String name,
                                   TypeSystem ts)
Description copied from class: DelegatingContext
Test whether name is an in-scope local function

Specified by:
localFunctionExists in interface TypeContext
Overrides:
localFunctionExists in class DelegatingContext

getLocalFunctions

public java.lang.Iterable<LocalFunction> getLocalFunctions(java.lang.String name,
                                                           TypeSystem ts,
                                                           java.lang.Iterable<LocalFunction> partial)
Description copied from interface: TypeContext
Helper for getLocalFunctions: list all matching functions, including those provided.

Specified by:
getLocalFunctions in interface TypeContext
Overrides:
getLocalFunctions in class DelegatingContext

accessModule

public Access.Module accessModule()
Description copied from interface: TypeContext
Get the current access module.

Specified by:
accessModule in interface TypeContext
Overrides:
accessModule in class DelegatingContext

makeClassName

public java.lang.String makeClassName(java.lang.String n)
Return a full name for a class with the given name declared here.

Specified by:
makeClassName in interface TypeContext
Overrides:
makeClassName in class DelegatingContext

makeAnonymousClassName

public java.lang.String makeAnonymousClassName()
Return a full name for an anonymous class declared here.

Specified by:
makeAnonymousClassName in interface TypeContext
Overrides:
makeAnonymousClassName in class DelegatingContext

getThis

public DJClass getThis()
Return the type of this in the current context, or null if there is no such value (for example, in a static context).

Specified by:
getThis in interface TypeContext
Overrides:
getThis in class DelegatingContext

getThis

public DJClass getThis(java.lang.String className)
Return the type of className.this in the current context, or null if there is no such value (for example, in a static context).

Specified by:
getThis in interface TypeContext
Overrides:
getThis in class DelegatingContext

getThis

public DJClass getThis(Type expected,
                       TypeSystem ts)
Description copied from interface: TypeContext
Return the innermost "this" class with the given type in the current context, or null if there is no such value (for example, in a static context).

Specified by:
getThis in interface TypeContext
Overrides:
getThis in class DelegatingContext

initializingClass

public DJClass initializingClass()
Description copied from interface: TypeContext
Class which is being initialized (via a constructor or initialization block); null otherwise.

Specified by:
initializingClass in interface TypeContext
Overrides:
initializingClass in class DelegatingContext

getReturnType

public Type getReturnType()
The expected type of a return statement in the given context, or null if return statements should not appear here.

Specified by:
getReturnType in interface TypeContext
Overrides:
getReturnType in class DelegatingContext

getDeclaredThrownTypes

public java.lang.Iterable<Type> getDeclaredThrownTypes()
The types that are allowed to be thrown in the current context. If there is no such declaration, the list will be empty.

Specified by:
getDeclaredThrownTypes in interface TypeContext
Overrides:
getDeclaredThrownTypes in class DelegatingContext