1 package net.sourceforge.pmd.lang.java.symboltable;
2
3
4 import java.util.ArrayList;
5 import java.util.List;
6 import java.util.HashMap;
7 import java.util.Map;
8
9 public class SourceFileScope extends AbstractScope {
10
11 protected Map<ClassNameDeclaration, List<NameOccurrence>> classNames = new HashMap<ClassNameDeclaration, List<NameOccurrence>>();
12 private String packageImage;
13
14 public SourceFileScope() {
15 this("");
16 }
17
18 public SourceFileScope(String image) {
19 this.packageImage = image;
20 }
21
22 public ClassScope getEnclosingClassScope() {
23 throw new RuntimeException("getEnclosingClassScope() called on SourceFileScope");
24 }
25
26 public MethodScope getEnclosingMethodScope() {
27 throw new RuntimeException("getEnclosingMethodScope() called on SourceFileScope");
28 }
29
30 public String 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<NameOccurrence>());
40 }
41
42 public void addDeclaration(MethodNameDeclaration decl) {
43 throw new RuntimeException("SourceFileScope.addDeclaration(MethodNameDeclaration decl) called");
44 }
45
46 public void addDeclaration(VariableNameDeclaration decl) {
47 throw new RuntimeException("SourceFileScope.addDeclaration(VariableNameDeclaration decl) called");
48 }
49
50 public Map<ClassNameDeclaration, List<NameOccurrence>> getClassDeclarations() {
51 return classNames;
52 }
53
54 public Map<VariableNameDeclaration, List<NameOccurrence>> getVariableDeclarations() {
55 throw new RuntimeException("PackageScope.getVariableDeclarations() called");
56 }
57
58 public NameDeclaration addVariableNameOccurrence(NameOccurrence occ) {
59 return null;
60 }
61
62 public String toString() {
63 return "SourceFileScope: " + glomNames(classNames.keySet());
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 }