Class AbstractScope
- java.lang.Object
-
- net.sourceforge.pmd.lang.symboltable.AbstractScope
-
-
Constructor Summary
Constructors Constructor Description AbstractScope()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDeclaration(NameDeclaration declaration)
Adds a new declaration to this scope.Set<NameDeclaration>
addNameOccurrence(NameOccurrence occurrence)
Adds aNameOccurrence
to this scope - only call this after getting a true back fromScope.contains(NameOccurrence)
.boolean
contains(NameOccurrence occ)
Tests whether or not aNameOccurrence
is directly contained in the scope.Map<NameDeclaration,List<NameOccurrence>>
getDeclarations()
Gets all the declaration with the occurrences in this scope.<T extends NameDeclaration>
Map<T,List<NameOccurrence>>getDeclarations(Class<T> clazz)
Helper method to get only a specific type of name declarations.<T extends Scope>
TgetEnclosingScope(Class<T> clazz)
Helper method that goes up the parent scopes to find a scope of the specified typeScope
getParent()
Retrieves this scope's parentvoid
setParent(Scope parent)
Points this scope to its parent
-
-
-
Method Detail
-
getParent
public Scope getParent()
Description copied from interface:Scope
Retrieves this scope's parent
-
setParent
public void setParent(Scope parent)
Description copied from interface:Scope
Points this scope to its parent
-
getDeclarations
public Map<NameDeclaration,List<NameOccurrence>> getDeclarations()
Description copied from interface:Scope
Gets all the declaration with the occurrences in this scope.- Specified by:
getDeclarations
in interfaceScope
- Returns:
- map of declarations with occurrences.
-
getDeclarations
public <T extends NameDeclaration> Map<T,List<NameOccurrence>> getDeclarations(Class<T> clazz)
Description copied from interface:Scope
Helper method to get only a specific type of name declarations. The return map elemens have already been casted to the correct type. This method usually returns a subset ofScope.getDeclarations()
.- Specified by:
getDeclarations
in interfaceScope
- Parameters:
clazz
- the type of name declarations to use- Returns:
- map of declarations with occurrences.
-
contains
public boolean contains(NameOccurrence occ)
Description copied from interface:Scope
Tests whether or not aNameOccurrence
is directly contained in the scope. This means, whether the givenNameOccurrence
references a declaration, that has been declared within this scope. Note that this search is just for this scope - it doesn't go diving into any parent scopes.
-
addDeclaration
public void addDeclaration(NameDeclaration declaration)
Description copied from interface:Scope
Adds a new declaration to this scope. Only after the declaration has been added,Scope.contains(NameOccurrence)
andScope.addNameOccurrence(NameOccurrence)
can be used correctly.- Specified by:
addDeclaration
in interfaceScope
- Parameters:
declaration
- the declaration to add
-
getEnclosingScope
public <T extends Scope> T getEnclosingScope(Class<T> clazz)
Description copied from interface:Scope
Helper method that goes up the parent scopes to find a scope of the specified type- Specified by:
getEnclosingScope
in interfaceScope
- Parameters:
clazz
- the type of the Scope to search for- Returns:
- the found scope of the specified type or
null
if no such scope was found.
-
addNameOccurrence
public Set<NameDeclaration> addNameOccurrence(NameOccurrence occurrence)
Description copied from interface:Scope
Adds aNameOccurrence
to this scope - only call this after getting a true back fromScope.contains(NameOccurrence)
.- Specified by:
addNameOccurrence
in interfaceScope
- Returns:
- the
NameDeclaration
s that are referenced by the givenNameOccurrence
, if theNameOccurrence
could be added. Otherwise an empty set is returned.
-
-