KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > symboltable > SourceFileScope


1 package net.sourceforge.pmd.symboltable;
2
3 import net.sourceforge.pmd.util.Applier;
4
5 import java.util.ArrayList JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9 public class SourceFileScope extends AbstractScope implements Scope {
10
11     protected Map JavaDoc classNames = new HashMap JavaDoc();
12     private String JavaDoc packageImage;
13
14     public SourceFileScope() {
15         this("");
16     }
17
18     public SourceFileScope(String JavaDoc image) {
19         this.packageImage = image;
20     }
21
22     public ClassScope getEnclosingClassScope() {
23         throw new RuntimeException JavaDoc("getEnclosingClassScope() called on SourceFileScope");
24     }
25
26     public MethodScope getEnclosingMethodScope() {
27         throw new RuntimeException JavaDoc("getEnclosingMethodScope() called on SourceFileScope");
28     }
29
30     public String JavaDoc getPackageName() {
31         return packageImage;
32     }
33
34     public SourceFileScope getEnclosingSourceFileScope() {
35         return this;
36     }
37
38     public void addDeclaration(ClassNameDeclaration classDecl) {
39         classNames.put(classDecl, new ArrayList JavaDoc());
40     }
41
42     public void addDeclaration(MethodNameDeclaration decl) {
43         throw new RuntimeException JavaDoc("SourceFileScope.addDeclaration(MethodNameDeclaration decl) called");
44     }
45
46     public void addDeclaration(VariableNameDeclaration decl) {
47         throw new RuntimeException JavaDoc("SourceFileScope.addDeclaration(VariableNameDeclaration decl) called");
48     }
49
50     public Map JavaDoc getClassDeclarations() {
51         return classNames;
52     }
53
54     public Map JavaDoc getVariableDeclarations() {
55         throw new RuntimeException JavaDoc("PackageScope.getVariableDeclarations() called");
56     }
57
58     public NameDeclaration addVariableNameOccurrence(NameOccurrence occ) {
59         return null;
60     }
61
62     public String JavaDoc toString() {
63         return "SourceFileScope: " + glomNames(classNames.keySet().iterator());
64     }
65
66     protected NameDeclaration findVariableHere(NameOccurrence occ) {
67         ImageFinderFunction finder = new ImageFinderFunction(occ.getImage());
68         Applier.apply(finder, classNames.keySet().iterator());
69         return finder.getDecl();
70     }
71
72 }
73
Popular Tags