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   
7   import net.sourceforge.pmd.lang.plsql.symboltable.ClassNameDeclaration;
8   import net.sourceforge.pmd.lang.symboltable.AbstractScope;
9   import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
10  import net.sourceforge.pmd.lang.symboltable.NameOccurrence;
11  
12  
13  public class SourceFileScope extends AbstractScope {
14  
15      private String packageImage;
16  
17      public SourceFileScope() {
18          this("");
19      }
20  
21      public SourceFileScope(String image) {
22          this.packageImage = image;
23      }
24  
25      public String getPackageName() {
26          return packageImage;
27      }
28  
29      /**
30       * {@inheritDoc}
31       * @throws IllegalArgumentException if declaration is not a {@link ClassNameDeclaration}
32       */
33      @Override
34      public void addDeclaration(NameDeclaration declaration) {
35          if (!(declaration instanceof ClassNameDeclaration)) {
36              throw new IllegalArgumentException("A SourceFileScope can only contain classes.");
37          }
38          super.addDeclaration(declaration);
39      }
40  
41      public String toString() {
42          return "SourceFileScope: " + getDeclarations().keySet();
43      }
44  
45      protected NameDeclaration findVariableHere(NameOccurrence occ) {
46          ImageFinderFunction finder = new ImageFinderFunction(occ.getImage());
47          Applier.apply(finder, getDeclarations().keySet().iterator());
48          return finder.getDecl();
49      }
50  
51  }