edu.rice.cs.dynamicjava.interpreter
Class DelegatingContext

java.lang.Object
  extended by edu.rice.cs.dynamicjava.interpreter.DelegatingContext
All Implemented Interfaces:
TypeContext
Direct Known Subclasses:
ClassContext, ClassSignatureContext, FunctionContext, FunctionSignatureContext, ImportContext, InitializerContext, LibraryContext, LocalContext, TryBlockContext

public abstract class DelegatingContext
extends Object
implements TypeContext

An abstract context that delegates to an enclosing context by default.


Constructor Summary
protected DelegatingContext(TypeContext next)
           
 
Method Summary
 Access.Module accessModule()
          Get the current access module.
protected abstract  TypeContext duplicate(TypeContext next)
          Create a copy of this context with the given context enclosing it.
 boolean fieldExists(String name, TypeSystem ts)
          Test whether name is an in-scope field
 boolean functionExists(String name, TypeSystem ts)
          Test whether name is an in-scope method or local function
 ClassLoader getClassLoader()
          Return the class loader for the current scope.
 Iterable<Type> getDeclaredThrownTypes()
          The types that are allowed to be thrown in the current context.
 Iterable<LocalFunction> getLocalFunctions(String name, TypeSystem ts)
          List all local functions that match the given name (empty if there are none).
 Iterable<LocalFunction> getLocalFunctions(String name, TypeSystem ts, Iterable<LocalFunction> partial)
          Helper for getLocalFunctions: list all matching functions, including those provided.
 LocalVariable getLocalVariable(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 class of this in the current context, or null if there is no such value (for example, in a static context).
 DJClass getThis(String className)
          Return the class 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(String name, TypeSystem ts)
          Return the top-level class with the given name, or null if it does not exist.
 VariableType getTypeVariable(String name, TypeSystem ts)
          Return the type variable with the given name, or null if it does not exist.
 TypeContext importField(DJClass c, String name)
          Import the field(s) of c with the given name
 TypeContext importMemberClass(DJClass outer, 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, 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(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(String name, TypeSystem ts)
          Test whether name is an in-scope local function
 boolean localVariableExists(String name, TypeSystem ts)
          Test whether name is an in-scope local variable
 String makeAnonymousClassName()
          Return a full name for an anonymous class declared here.
 String makeClassName(String n)
          Return a full name for a class with the given name declared here.
 boolean memberClassExists(String name, TypeSystem ts)
          Test whether name is an in-scope member class
 boolean methodExists(String name, TypeSystem ts)
          Test whether name is an in-scope method
 TypeContext setPackage(String name)
          Set the current package to the given package name
 boolean topLevelClassExists(String name, TypeSystem ts)
          Test whether name is an in-scope top-level class
 ClassType typeContainingField(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(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(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(String name, TypeSystem ts)
          Test whether name is an in-scope top-level class, member class, or type variable
 boolean typeVariableExists(String name, TypeSystem ts)
          Test whether name is an in-scope type variable.
 boolean variableExists(String name, TypeSystem ts)
          Test whether name is an in-scope field or local variable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingContext

protected DelegatingContext(TypeContext next)
Method Detail

duplicate

protected abstract TypeContext duplicate(TypeContext next)
Create a copy of this context with the given context enclosing it.


setPackage

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

Specified by:
setPackage in interface TypeContext

importTopLevelClasses

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

Specified by:
importTopLevelClasses in interface TypeContext

importMemberClasses

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

Specified by:
importMemberClasses in interface TypeContext

importStaticMembers

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

Specified by:
importStaticMembers in interface TypeContext

importTopLevelClass

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

Specified by:
importTopLevelClass in interface TypeContext

importMemberClass

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

Specified by:
importMemberClass in interface TypeContext

importField

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

Specified by:
importField in interface TypeContext

importMethod

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

Specified by:
importMethod in interface TypeContext

typeExists

public boolean typeExists(String name,
                          TypeSystem ts)
Test whether name is an in-scope top-level class, member class, or type variable

Specified by:
typeExists in interface TypeContext

topLevelClassExists

public boolean topLevelClassExists(String name,
                                   TypeSystem ts)
Test whether name is an in-scope top-level class

Specified by:
topLevelClassExists in interface TypeContext

getTopLevelClass

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

Specified by:
getTopLevelClass in interface TypeContext
Throws:
AmbiguousNameException

memberClassExists

public boolean memberClassExists(String name,
                                 TypeSystem ts)
Test whether name is an in-scope member class

Specified by:
memberClassExists in interface TypeContext

typeContainingMemberClass

public ClassType typeContainingMemberClass(String name,
                                           TypeSystem ts)
                                    throws AmbiguousNameException
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
Throws:
AmbiguousNameException

typeVariableExists

public boolean typeVariableExists(String name,
                                  TypeSystem ts)
Test whether name is an in-scope type variable.

Specified by:
typeVariableExists in interface TypeContext

getTypeVariable

public VariableType getTypeVariable(String name,
                                    TypeSystem ts)
Return the type variable with the given name, or null if it does not exist.

Specified by:
getTypeVariable in interface TypeContext

variableExists

public boolean variableExists(String name,
                              TypeSystem ts)
Test whether name is an in-scope field or local variable

Specified by:
variableExists in interface TypeContext

fieldExists

public boolean fieldExists(String name,
                           TypeSystem ts)
Test whether name is an in-scope field

Specified by:
fieldExists in interface TypeContext

typeContainingField

public ClassType typeContainingField(String name,
                                     TypeSystem ts)
                              throws AmbiguousNameException
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
Throws:
AmbiguousNameException

localVariableExists

public boolean localVariableExists(String name,
                                   TypeSystem ts)
Test whether name is an in-scope local variable

Specified by:
localVariableExists in interface TypeContext

getLocalVariable

public LocalVariable getLocalVariable(String name,
                                      TypeSystem ts)
Return the variable object for the given name, or null if it does not exist.

Specified by:
getLocalVariable in interface TypeContext

functionExists

public boolean functionExists(String name,
                              TypeSystem ts)
Test whether name is an in-scope method or local function

Specified by:
functionExists in interface TypeContext

methodExists

public boolean methodExists(String name,
                            TypeSystem ts)
Test whether name is an in-scope method

Specified by:
methodExists in interface TypeContext

typeContainingMethod

public Type typeContainingMethod(String name,
                                 TypeSystem ts)
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

localFunctionExists

public boolean localFunctionExists(String name,
                                   TypeSystem ts)
Test whether name is an in-scope local function

Specified by:
localFunctionExists in interface TypeContext

getLocalFunctions

public final Iterable<LocalFunction> getLocalFunctions(String name,
                                                       TypeSystem ts)
List all local functions that match the given name (empty if there are none). Overridden for convenience, delegating to a trivial instance of getLocalFunctions(String, TypeSystem, Iterable).

Specified by:
getLocalFunctions in interface TypeContext

getLocalFunctions

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

Specified by:
getLocalFunctions in interface TypeContext

accessModule

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

Specified by:
accessModule in interface TypeContext

makeClassName

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

Specified by:
makeClassName in interface TypeContext

makeAnonymousClassName

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

Specified by:
makeAnonymousClassName in interface TypeContext

getThis

public DJClass getThis()
Return the class 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

getThis

public DJClass getThis(String className)
Return the class 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

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

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

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

getDeclaredThrownTypes

public 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

getClassLoader

public ClassLoader getClassLoader()
Description copied from interface: TypeContext
Return the class loader for the current scope. Allows class loaders to be defined in later scopes with the returned loader as a parent.

Specified by:
getClassLoader in interface TypeContext