Class Resolver<V extends IResolvable>
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.Resolver<V>
-
- Type Parameters:
V- the type of variable declarations
- All Implemented Interfaces:
IResolver<V>
- Direct Known Subclasses:
Resolver
public abstract class Resolver<V extends IResolvable> extends java.lang.Object implements IResolver<V>
A basic implementation for a hierarchical resolver.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceResolver.IContextTypeDefines a type for contexts (i.e., constants).private static classResolver.Level<V extends IResolvable>Represents a (nested) resolution level.
-
Field Summary
Fields Modifier and Type Field Description private IRuntimeEnvironmentenvironmentprivate java.util.Stack<Resolver.Level<V>>levelsprivate TypeRegistryregistry
-
Constructor Summary
Constructors Constructor Description Resolver(IRuntimeEnvironment environment)Creates a new resolver considering the runtime environment.Resolver(TypeRegistry registry)Creates a new resolver.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(java.util.List<V> decls)Adds all variable declarations indeclto the actual level.voidadd(V decl)Adds a variable declaration to the actual level.voidadd(V[] decls)Adds all variable declarations indeclto the actual level.protected voidadd(V decl, java.lang.String qualification)Adds a variable declaration to the actual level.voidaddAlias(java.lang.String name, V decl)Adds anamealias fordecl, only ifnamehas not been defined before.booleancontains(java.lang.String name)Returns whether a variable withnameis already known.booleancontains(V decl)Returns whether a variable with the same name asdeclis already known.Resolver.IContextTypegetContextType()Returns the actual context type.IModelgetCurrentModel()Returns the current model.protected abstract Resolver.IContextTypegetDefaultType()Returns the default type.java.lang.ObjectgetIvmlElement(java.lang.String name)Resolves an IVML element.intgetLevelCount()Returns the current number of levels.IRuntimeEnvironmentgetRuntimeEnvironment()Returns the runtime environment.TypeRegistrygetTypeRegistry()Returns the (local) type registry.voidlimitVariablesOnCurrentLevel()Indicates that subsequent resolutions within that scope shall not exceed the actual scope.voidpopLevel()Pops the top resolution level, e.g., when a nested language unit is closed.voidpushLevel()Pushes a resolution level, e.g., when a nested language unit is opened.voidremove(V decl)Removes the given declaration from the actual level.protected voidremove(V decl, java.lang.String qualification)Removes a variable declaration from the actual level.Vresolve(java.lang.String name, boolean local)Resolves a variable.Vresolve(java.lang.String name, boolean local, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, IMessageReceiver receiver)Resolves a variable.TypeDescriptor<?>resolveType(java.lang.String name)Resolves a type within the known contexts / models.voidsetContextType(Resolver.IContextType context)Defines the actual context type.
-
-
-
Field Detail
-
levels
private java.util.Stack<Resolver.Level<V extends IResolvable>> levels
-
environment
private IRuntimeEnvironment environment
-
registry
private TypeRegistry registry
-
-
Constructor Detail
-
Resolver
public Resolver(TypeRegistry registry)
Creates a new resolver.- Parameters:
registry- the local type registry
-
Resolver
public Resolver(IRuntimeEnvironment environment)
Creates a new resolver considering the runtime environment. (for expression resolution only).- Parameters:
environment- the runtime environment
-
-
Method Detail
-
getRuntimeEnvironment
public IRuntimeEnvironment getRuntimeEnvironment()
Returns the runtime environment.- Returns:
- the runtime environment
-
getTypeRegistry
public TypeRegistry getTypeRegistry()
Returns the (local) type registry.- Returns:
- the local type registry (from the
environment).
-
resolve
public V resolve(java.lang.String name, boolean local)
Description copied from interface:IResolverResolves a variable.- Specified by:
resolvein interfaceIResolver<V extends IResolvable>- Parameters:
name- the name of the variablelocal- consider only the local scope or also outside nested scopes- Returns:
- the variable declaration or null
-
resolve
public V resolve(java.lang.String name, boolean local, org.eclipse.emf.ecore.EObject cause, org.eclipse.emf.ecore.EStructuralFeature causeFeature, IMessageReceiver receiver)
Resolves a variable.- Parameters:
name- the name of the variablelocal- consider only the local scope or also outside nested scopescause- the causing EObject (may be null)causeFeature- the causing feature oncause(may be null)receiver- the message receiver for discouraged warnings (may be null, but if not null alsocauseandcauseFeatureshall be given for standard message receivers)- Returns:
- the variable declaration or null
-
getContextType
public Resolver.IContextType getContextType()
Returns the actual context type.- Returns:
- the actual context type
-
setContextType
public void setContextType(Resolver.IContextType context)
Defines the actual context type.- Parameters:
context- the actual context type
-
add
public void add(V decl)
Adds a variable declaration to the actual level.- Parameters:
decl- the variable declaration
-
remove
public void remove(V decl)
Removes the given declaration from the actual level.- Parameters:
decl- the declaration to remove
-
addAlias
public void addAlias(java.lang.String name, V decl)Adds anamealias fordecl, only ifnamehas not been defined before. This method helps to migrate from old to new implicit name conventions.- Parameters:
name- the alias namedecl- the variable declaration
-
add
protected void add(V decl, java.lang.String qualification)
Adds a variable declaration to the actual level.- Parameters:
decl- the variable declarationqualification- the qualification path of the name
-
remove
protected void remove(V decl, java.lang.String qualification)
Removes a variable declaration from the actual level.- Parameters:
decl- the variable declarationqualification- the qualification path of the name
-
limitVariablesOnCurrentLevel
public void limitVariablesOnCurrentLevel()
Indicates that subsequent resolutions within that scope shall not exceed the actual scope.
-
contains
public boolean contains(V decl)
Returns whether a variable with the same name asdeclis already known.- Parameters:
decl- the declaration to search for- Returns:
trueif there is a variable,falseelse- See Also:
contains(IResolvable)
-
contains
public boolean contains(java.lang.String name)
Returns whether a variable withnameis already known.- Parameters:
name- the variable name to search for- Returns:
trueif there is a variable,falseelse
-
add
public void add(V[] decls)
Adds all variable declarations indeclto the actual level.- Parameters:
decls- the declarations to be added (may be null)
-
add
public void add(java.util.List<V> decls)
Adds all variable declarations indeclto the actual level.- Parameters:
decls- the declarations to be added (may be null)
-
getDefaultType
protected abstract Resolver.IContextType getDefaultType()
Returns the default type.- Returns:
- the default type
-
pushLevel
public void pushLevel()
Pushes a resolution level, e.g., when a nested language unit is opened. An opening withpushLevel()shall properly be closed withpopLevel().
-
popLevel
public void popLevel()
Pops the top resolution level, e.g., when a nested language unit is closed. The most basic level cannot be popped.
-
getLevelCount
public int getLevelCount()
Returns the current number of levels. Please note that one basic level is always present, i.e., the number of pushed levels is.getLevelCount()- 1- Returns:
- the current number of levels
-
getIvmlElement
public java.lang.Object getIvmlElement(java.lang.String name)
Description copied from interface:IResolverResolves an IVML element.- Specified by:
getIvmlElementin interfaceIResolver<V extends IResolvable>- Parameters:
name- the name to be resolved- Returns:
- the IVML element (value, containable model element), null else
-
getCurrentModel
public IModel getCurrentModel()
Returns the current model.- Returns:
- the current model (or null if there is none)
-
resolveType
public TypeDescriptor<?> resolveType(java.lang.String name)
Resolves a type within the known contexts / models.- Parameters:
name- the name of the type- Returns:
- the type or null for unknown
-
-