KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > symboltable > AbstractScope


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

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