View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.plsql.symboltable;
5   
6   import net.sourceforge.pmd.lang.symboltable.AbstractScope;
7   import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
8   import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
9   
10  public class SourceFileScope extends AbstractScope {
11  
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 String getPackageName() {
23          return packageImage;
24      }
25  
26      /**
27       * {@inheritDoc}
28       * @throws IllegalArgumentException if declaration is not a {@link ClassNameDeclaration}
29       */
30      @Override
31      public void addDeclaration(NameDeclaration declaration) {
32          if (!(declaration instanceof ClassNameDeclaration)) {
33              throw new IllegalArgumentException("A SourceFileScope can only contain classes.");
34          }
35          super.addDeclaration(declaration);
36      }
37  
38      public String toString() {
39          return "SourceFileScope: " + getDeclarations().keySet();
40      }
41  
42      protected NameDeclaration findVariableHere(NameOccurrence occ) {
43          ImageFinderFunction finder = new ImageFinderFunction(occ.getImage());
44          Applier.apply(finder, getDeclarations().keySet().iterator());
45          return finder.getDecl();
46      }
47  
48  }