KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > types > ClassContextResolver


1 package polyglot.types;
2
3 import polyglot.util.*;
4 import polyglot.main.Report;
5 import java.util.*;
6
7 /**
8  * A <code>ClassContextResolver</code> looks up type names qualified with a class name.
9  * For example, if the class is "A.B", the class context will return the class
10  * for member class "A.B.C" (if it exists) when asked for "C".
11  */

12 public class ClassContextResolver extends ClassResolver {
13     TypeSystem ts;
14     ClassType type;
15
16     /**
17      * Construct a resolver.
18      * @param ts The type system.
19      * @param type The type in whose context we search for member types.
20      */

21     public ClassContextResolver(TypeSystem ts, ClassType type) {
22     this.ts = ts;
23     this.type = type;
24     }
25
26     public String JavaDoc toString() {
27         return "(class-context " + type + ")";
28     }
29
30     /**
31      * Find a type object in the context of the class.
32      * @param name The name to search for.
33      */

34     public Named find(String JavaDoc name) throws SemanticException {
35         if (Report.should_report(TOPICS, 2))
36         Report.report(2, "Looking for " + name + " in " + this);
37
38         if (! StringUtil.isNameShort(name)) {
39             throw new InternalCompilerError(
40                 "Cannot lookup qualified name " + name);
41         }
42
43         // Check if the name is for a member class.
44
ClassType inner = ts.findMemberClass(type, name);
45
46         if (inner != null) {
47             if (Report.should_report(TOPICS, 2))
48                 Report.report(2, "Found member class " + inner);
49             return inner;
50         }
51
52         throw new NoClassException(name, type);
53     }
54
55     /**
56      * The class in whose context we look.
57      */

58     public ClassType classType() {
59     return type;
60     }
61
62     private static final Collection TOPICS =
63             CollectionUtil.list(Report.types, Report.resolver);
64
65 }
66
Popular Tags