public abstract class SymbolScope extends Object
Adapted from "Language Implementation Patterns" by Terence Parr, published by The Pragmatic Bookshelf, 2010.
Modifier and Type | Field and Description |
---|---|
protected SymbolScope |
enclosingScope
Parent scope or
null if top level. |
protected String |
name |
protected Map<String,Symbol> |
symbols
Symbols defined within this scope, keyed by name.
|
Constructor and Description |
---|
SymbolScope(String name,
SymbolScope enclosingScope)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Symbol symbol)
Adds a symbol to this scope.
|
void |
add(Symbol symbol,
boolean allowReplacement)
Adds a symbol to this scope, optionally allowing
replacement of any existing symbol with the same name.
|
Symbol |
get(String name)
Searches for a symbol in this scope and, if not found,
any enclosing scopes.
|
Set<String> |
getByType(Symbol.Type type)
Returns name of all symbols with the given type, in the current scope and enclosing scopes
|
SymbolScope |
getDeclaringScope(String name)
Searches for a symbol in this scope and, if not found,
any enclosing scopes.
|
SymbolScope |
getEnclosingScope()
Gets the parent scope or
null if this is the
top scope. |
String |
getName()
Gets the name of this scope instance.
|
boolean |
has(String name)
Tests if a symbol is defined in this scope or any
enclosing scope.
|
protected final String name
protected final SymbolScope enclosingScope
null
if top level.public SymbolScope(String name, SymbolScope enclosingScope)
name
- label for this scopeparent
- scope or null
if top levelpublic String getName()
public SymbolScope getEnclosingScope()
null
if this is the
top scope.public void add(Symbol symbol)
public void add(Symbol symbol, boolean allowReplacement)
public boolean has(String name)
public Symbol get(String name)
IllegalArgumentException
- if the symbol is not foundpublic SymbolScope getDeclaringScope(String name)
IllegalArgumentException
- if the symbol is not foundpublic Set<String> getByType(Symbol.Type type)
type
- Copyright © 2006–2018 GeoSolutions. All rights reserved.