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