View Javadoc

    1   package net.sourceforge.pmd.symboltable;
    2
    3   import net.sourceforge.pmd.util.Applier;
    4
    5   import java.util.ArrayList;
    6   import java.util.HashMap;
    7   import java.util.Map;
    8
    9   public class SourceFileScope extends AbstractScope implements Scope {
    10
    11      protected Map classNames = new HashMap();
    12      private</str<a href="../../../../ong> String packageImage/package-summary.html">ong> String packageImage;
    13
    14      public SourceFileScope() {
    15          this("");
    16      }
    17
    18      public SourceFileScope(String image) {
    19          this.packageImage = image;
    20      }
    21
    22      public ClassScope getEnclosingClassScope() {
    23          throw new RuntimeException("getEnclosingClassScope() called on SourceFileScope");
    24      }
    25
    26      public MethodScope getEnclosingMethodScope() {
    27          throw new RuntimeException("getEnclosingMethodScope() called on SourceFileScope");
    28      }
    29
    30      public String getPackageName() {
    31          return</strong> packageImage;
    32      }
    33
    34      public SourceFileScope getEnclosingSourceFileScope() {
    35          return this;
    36      }
    37
    38      public void addDeclaration(ClassNameDeclaration classDecl) {
    39          classNames.put(classDecl, new ArrayList());
    40      }
    41
    42      public void addDeclaration(MethodNameDeclaration decl) {
    43          throw new RuntimeException("SourceFileScope.addDeclaration(MethodNameDeclaration decl) called");
    44      }
    45
    46      public void addDeclaration(VariableNameDeclaration decl) {
    47          throw new RuntimeException("SourceFileScope.addDeclaration(VariableNameDeclaration decl) called");
    48      }
    49
    50      public Map getClassDeclarations() {
    51          return classNames;
    52      }
    53
    54      public Map getVariableDeclarations() {
    55          throw new RuntimeException("PackageScope.getVariableDeclarations() called");
    56      }
    57
    58      public NameDeclaration addVariableNameOccurrence(NameOccurrence occ) {
    59          return null;
    60      }
    61
    62      public String toString() {
    63          return "SourceFileScope: " + glomNames(classNames.keySet().iterator());
    64      }
    65
    66      protected NameDeclaration findVariableHere(NameOccurrence occ) {
    67          ImageFinderFunction finder = new ImageFinderFunction(occ.getImage());
    68          Applier.apply(finder, classNames.keySet().iterator());
    69          return finder.getDecl();
    70      }
    71
    72  }