KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > types > CompoundResolver


1 package polyglot.types;
2
3 import polyglot.ast.*;
4 import polyglot.util.*;
5 import java.util.*;
6
7 /**
8  * An <code>CompoundResolver</code> resolves names using more than one
9  * context.
10  */

11 public class CompoundResolver implements TopLevelResolver {
12     TopLevelResolver head;
13     TopLevelResolver tail;
14
15     /**
16      * Create a compound resolver.
17      * @param head The first resolver to search.
18      * @param tail The second resolver to search.
19      */

20     public CompoundResolver(TopLevelResolver head, TopLevelResolver tail) {
21     this.head = head;
22     this.tail = tail;
23     }
24
25     public String JavaDoc toString() {
26         return "(compound " + head + " " + tail + ")";
27     }
28     
29     /**
30      * Check if a package exists.
31      */

32     public boolean packageExists(String JavaDoc name) {
33     return head.packageExists(name) || tail.packageExists(name);
34     }
35
36     /**
37      * Find a type object by name.
38      */

39     public Named find(String JavaDoc name) throws SemanticException {
40     try {
41         return head.find(name);
42     }
43     catch (NoClassException e) {
44         return tail.find(name);
45     }
46     }
47 }
48
Popular Tags