Interface Scope
-
- All Known Implementing Classes:
AbstractScope
public interface Scope
A scope is a region within variables and other declarations are visible. Scopes can be nested and form a tree. This is expressed through "parent scopes". Each scope manages its own declarations.
-
-
Method Summary
All Methods Instance Methods Abstract 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 fromcontains(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
Scope getParent()
Retrieves this scope's parent
-
setParent
void setParent(Scope parent)
Points this scope to its parent
-
getEnclosingScope
<T extends Scope> T getEnclosingScope(Class<T> clazz)
Helper method that goes up the parent scopes to find a scope of the specified type- 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.
-
getDeclarations
Map<NameDeclaration,List<NameOccurrence>> getDeclarations()
Gets all the declaration with the occurrences in this scope.- Returns:
- map of declarations with occurrences.
-
getDeclarations
<T extends NameDeclaration> Map<T,List<NameOccurrence>> getDeclarations(Class<T> clazz)
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 ofgetDeclarations()
.- Parameters:
clazz
- the type of name declarations to use- Returns:
- map of declarations with occurrences.
-
contains
boolean contains(NameOccurrence occ)
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
void addDeclaration(NameDeclaration declaration)
Adds a new declaration to this scope. Only after the declaration has been added,contains(NameOccurrence)
andaddNameOccurrence(NameOccurrence)
can be used correctly.- Parameters:
declaration
- the declaration to add
-
addNameOccurrence
Set<NameDeclaration> addNameOccurrence(NameOccurrence occurrence)
Adds aNameOccurrence
to this scope - only call this after getting a true back fromcontains(NameOccurrence)
.- Returns:
- the
NameDeclaration
s that are referenced by the givenNameOccurrence
, if theNameOccurrence
could be added. Otherwise an empty set is returned.
-
-