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