KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > types > Context


1 package polyglot.types;
2
3 import java.util.List JavaDoc;
4
5 import polyglot.util.Copy;
6
7 /**
8  * A context represents a stack of scopes used for looking up types, methods,
9  * and variables. To push a new scope call one of the <code>push*</code>
10  * methods to return a new context. The old context may still be used
11  * and may be accessed directly through a call to <code>pop()</code>.
12  * While the stack of scopes is treated functionally, each individual
13  * scope is updated in place. Names added to the context are added
14  * in the current scope.
15  */

16 public interface Context extends Resolver, Copy
17 {
18     /** The type system. */
19     TypeSystem typeSystem();
20
21     /** Add a variable to the current scope. */
22     void addVariable(VarInstance vi);
23
24     /** Add a method to the current scope. */
25     void addMethod(MethodInstance mi);
26
27     /** Add a named type object to the current scope. */
28     void addNamed(Named t);
29
30     /** Looks up a method in the current scope.
31      * @param formalTypes A list of <code>Type</code>.
32      * @see polyglot.types.Type
33      */

34     MethodInstance findMethod(String JavaDoc name, List JavaDoc formalTypes) throws SemanticException;
35
36     /** Looks up a local variable or field in the current scope. */
37     VarInstance findVariable(String JavaDoc name) throws SemanticException;
38
39     /** Looks up a local variable or field in the current scope. */
40     VarInstance findVariableSilent(String JavaDoc name);
41
42     /** Looks up a local variable in the current scope. */
43     LocalInstance findLocal(String JavaDoc name) throws SemanticException;
44
45     /** Looks up a field in the current scope. */
46     FieldInstance findField(String JavaDoc name) throws SemanticException;
47
48     /**
49      * Finds the class which added a field to the scope.
50      * This is usually a subclass of <code>findField(name).container()</code>.
51      */

52     ClassType findFieldScope(String JavaDoc name) throws SemanticException;
53
54     /**
55      * Finds the class which added a method to the scope.
56      * This is usually a subclass of <code>findMethod(name).container()</code>.
57      */

58     ClassType findMethodScope(String JavaDoc name) throws SemanticException;
59
60     /** Get import table currently in scope. */
61     ImportTable importTable();
62
63     /** Get the outer-most resolver for the source file currently in scope.
64      * This is usually just the import table.
65      */

66     Resolver outerResolver();
67
68     /** Enter the scope of a source file. */
69     Context pushSource(ImportTable it);
70
71     /** Enter the scope of a class. */
72     Context pushClass(ParsedClassType scope, ClassType type);
73
74     /** Enter the scope of a method or constructor. */
75     Context pushCode(CodeInstance f);
76
77     /** Enter the scope of a block. */
78     Context pushBlock();
79
80     /** Enter a static scope. In general, this is only used for
81      * explicit constructor calls; static methods, initializers of static
82      * fields and static initializers are generally handled by pushCode().
83      */

84     Context pushStatic();
85
86     /** Pop the context. */
87     Context pop();
88
89     /** Return whether innermost non-block scope is a code scope. */
90     boolean inCode();
91
92     /** Returns whether the symbol is defined within the current method. */
93     boolean isLocal(String JavaDoc name);
94
95     /**
96      * Returns whether the current context is a static context.
97      * A statement of expression occurs in a static context if and only if the
98      * inner-most method, constructor, instance initializer, static initializer,
99      * field initializer, or explicit constructor statement enclosing the
100      * statement or expressions is a static method, static initializer, the
101      * variable initializer of a static variable, or an explicity constructor
102      * invocation statment. (Java Language Spec, 2nd Edition, 8.1.2)
103      */

104     boolean inStaticContext();
105
106     /** Return the innermost class in scope. */
107     ClassType currentClass();
108  
109     /** Return the innermost class in scope. */
110     ParsedClassType currentClassScope();
111
112     /** Return the innermost method or constructor in scope. */
113     CodeInstance currentCode();
114
115     /** The current package, or null if not in a package. */
116     Package JavaDoc package_();
117 }
118
Popular Tags