01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package net.sourceforge.pmd.symboltable;
04:
05: import java.util.List;
06: import java.util.Map;
07: import java.util.Set;
08:
09: public abstract class AbstractScope implements Scope {
10:
11: private Scope parent;
12:
13: public Map<ClassNameDeclaration, List<NameOccurrence>> getClassDeclarations() {
14: throw new RuntimeException(
15: "AbstractScope.getClassDeclarations() was invoked. That shouldn't happen... bug.");
16: }
17:
18: public MethodScope getEnclosingMethodScope() {
19: return parent.getEnclosingMethodScope();
20: }
21:
22: public ClassScope getEnclosingClassScope() {
23: return parent.getEnclosingClassScope();
24: }
25:
26: public SourceFileScope getEnclosingSourceFileScope() {
27: return parent.getEnclosingSourceFileScope();
28: }
29:
30: public void setParent(Scope parent) {
31: this .parent = parent;
32: }
33:
34: public Scope getParent() {
35: return parent;
36: }
37:
38: public void addDeclaration(MethodNameDeclaration methodDecl) {
39: parent.addDeclaration(methodDecl);
40: }
41:
42: public void addDeclaration(ClassNameDeclaration classDecl) {
43: parent.addDeclaration(classDecl);
44: }
45:
46: public boolean contains(NameOccurrence occurrence) {
47: return findVariableHere(occurrence) != null;
48: }
49:
50: protected abstract NameDeclaration findVariableHere(
51: NameOccurrence occurrence);
52:
53: protected <T> String glomNames(Set<T> s) {
54: StringBuffer result = new StringBuffer();
55: for (T t : s) {
56: result.append(t.toString());
57: result.append(',');
58: }
59: return result.length() == 0 ? "" : result.toString().substring(
60: 0, result.length() - 1);
61: }
62:
63: }
|