|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| package net.sourceforge.pmd.symboltable; |
|
5 |
| |
|
6 |
| import java.util.Iterator; |
|
7 |
| import java.util.Map; |
|
8 |
| |
|
9 |
| public abstract class AbstractScope implements Scope { |
|
10 |
| |
|
11 |
| private Scope parent; |
|
12 |
| |
|
13 |
0
| public Map getClassDeclarations() {
|
|
14 |
0
| throw new RuntimeException("AbstractScope.getClassDeclarations() was invoked. That shouldn't happen... bug.");
|
|
15 |
| } |
|
16 |
| |
|
17 |
477
| public MethodScope getEnclosingMethodScope() {
|
|
18 |
477
| return parent.getEnclosingMethodScope();
|
|
19 |
| } |
|
20 |
| |
|
21 |
3658
| public ClassScope getEnclosingClassScope() {
|
|
22 |
3658
| return parent.getEnclosingClassScope();
|
|
23 |
| } |
|
24 |
| |
|
25 |
3104
| public SourceFileScope getEnclosingSourceFileScope() {
|
|
26 |
3104
| return parent.getEnclosingSourceFileScope();
|
|
27 |
| } |
|
28 |
| |
|
29 |
4694
| public void setParent(Scope parent) {
|
|
30 |
4694
| this.parent = parent;
|
|
31 |
| } |
|
32 |
| |
|
33 |
9092
| public Scope getParent() {
|
|
34 |
9092
| return parent;
|
|
35 |
| } |
|
36 |
| |
|
37 |
0
| public void addDeclaration(MethodNameDeclaration methodDecl) {
|
|
38 |
0
| parent.addDeclaration(methodDecl);
|
|
39 |
| } |
|
40 |
| |
|
41 |
6
| public void addDeclaration(ClassNameDeclaration classDecl) {
|
|
42 |
6
| parent.addDeclaration(classDecl);
|
|
43 |
| } |
|
44 |
| |
|
45 |
8664
| public boolean contains(NameOccurrence occurrence) {
|
|
46 |
8664
| return findVariableHere(occurrence) != null;
|
|
47 |
| } |
|
48 |
| |
|
49 |
| protected abstract NameDeclaration findVariableHere(NameOccurrence occurrence); |
|
50 |
| |
|
51 |
0
| protected String glomNames(Iterator i) {
|
|
52 |
0
| StringBuffer result = new StringBuffer();
|
|
53 |
0
| while (i.hasNext()) {
|
|
54 |
0
| result.append(i.next().toString());
|
|
55 |
0
| result.append(',');
|
|
56 |
| } |
|
57 |
0
| return result.length() == 0 ? "" : result.toString().substring(0, result.length() - 1);
|
|
58 |
| } |
|
59 |
| |
|
60 |
| } |