View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.lang.java.symboltable;
    5
    6   import java.util.List;
    7   import java.util.Map;
    8
    9   /**
    10   * Provides methods which all scopes must implement
    11   * <p/>
    12   * See JLS 6.3 for a description of scopes
    13   */
    14  public interface Scope {
    15
    16      /**
    17       * Returns a Map (VariableNameDeclaration->List(NameOccurrence,NameOccurrence)) of declarations that
    18       * exist at this scope
    19       */
    20      Map<VariableNameDeclaration, List<NameOccurrence>> getVariableDeclarations();
    21
    22      /**
    23       * Returns a Map (VariableNameDeclaration->List(NameOccurrence,NameOccurrence)) of declarations that
    24       * exist at this scope
    25       */
    26      Map<ClassNameDeclaration, List<NameOccurrence>> getClassDeclarations();
    27
    28      /**
    29       * Add a class declaration to this scope
    30       */
    31      void addDeclaration(ClassNameDeclaration decl);
    32
    33      /**
    34       * Add a variable declaration to this scope
    35       */
    36      void addDeclaration(VariableNameDeclaration decl);
    37
    38      /**
    39       * Add a method declaration to this scope
    40       */
    41      void addDeclaration(MethodNameDeclaration decl);
    42
    43      /**
    44       * Tests whether or not a NameOccurrence is directly contained in the scope
    45       * Note that this search is just for this scope - it doesn't go diving into any
    46       * child scopes.
    47       */
    48      boolean contains(NameOccurrence occ);
    49
    50      /**
    51       * Adds a NameOccurrence to this scope - only call this after getting
    52       * a true back from contains()
    53       */
    54      NameDeclaration addVariableNameOccurrence(NameOccurrence occ);
    55
    56      /**
    57       * Points this scope to its parent
    58       */
    59      void setParent(Scope parent);
    60
    61      /**
    62       * Retrieves this scope's parent
    63       */
    64      Scope getParent();
    65
    66      /**
    67       * Goes searching up the tree for this scope's enclosing ClassScope
    68       * This is handy if you're buried down in a LocalScope and need to
    69       * hop up to the ClassScope to find a method name.
    70       */
    71      ClassScope getEnclosingClassScope();
    72
    73      /**
    74       * Goes searching up the tree for this scope's enclosing SourceFileScope
    75       * This is handy if you're buried down in a LocalScope and need to
    76       * hop up to the SourceFileScope to find a class name.
    77       */
    78      SourceFileScope getEnclosingSourceFileScope();
    79
    80      /**
    81       * Goes searching up the tree for this scope's enclosing MethodScope
    82       * This is handy if you're buried down in a LocalScope and need to
    83       * hop up to the MethodScope to find a method parameter.
    84       */
    85      MethodScope getEnclosingMethodScope();
    86  }