Class Resolver<V extends IResolvable>

  • 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 interface  Resolver.IContextType
      Defines a type for contexts (i.e., constants).
      private static class  Resolver.Level<V extends IResolvable>
      Represents a (nested) resolution level.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.util.List<V> decls)
      Adds all variable declarations in decl to the actual level.
      void add​(V decl)
      Adds a variable declaration to the actual level.
      void add​(V[] decls)
      Adds all variable declarations in decl to the actual level.
      protected void add​(V decl, java.lang.String qualification)
      Adds a variable declaration to the actual level.
      void addAlias​(java.lang.String name, V decl)
      Adds a name alias for decl, only if name has not been defined before.
      boolean contains​(java.lang.String name)
      Returns whether a variable with name is already known.
      boolean contains​(V decl)
      Returns whether a variable with the same name as decl is already known.
      Resolver.IContextType getContextType()
      Returns the actual context type.
      IModel getCurrentModel()
      Returns the current model.
      protected abstract Resolver.IContextType getDefaultType()
      Returns the default type.
      java.lang.Object getIvmlElement​(java.lang.String name)
      Resolves an IVML element.
      int getLevelCount()
      Returns the current number of levels.
      IRuntimeEnvironment getRuntimeEnvironment()
      Returns the runtime environment.
      TypeRegistry getTypeRegistry()
      Returns the (local) type registry.
      void limitVariablesOnCurrentLevel()
      Indicates that subsequent resolutions within that scope shall not exceed the actual scope.
      void popLevel()
      Pops the top resolution level, e.g., when a nested language unit is closed.
      void pushLevel()
      Pushes a resolution level, e.g., when a nested language unit is opened.
      void remove​(V decl)
      Removes the given declaration from the actual level.
      protected void remove​(V decl, java.lang.String qualification)
      Removes a variable declaration from the actual level.
      V resolve​(java.lang.String name, boolean local)
      Resolves a variable.
      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.
      TypeDescriptor<?> resolveType​(java.lang.String name)
      Resolves a type within the known contexts / models.
      void setContextType​(Resolver.IContextType context)
      Defines the actual context type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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: IResolver
        Resolves a variable.
        Specified by:
        resolve in interface IResolver<V extends IResolvable>
        Parameters:
        name - the name of the variable
        local - 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 variable
        local - consider only the local scope or also outside nested scopes
        cause - the causing EObject (may be null)
        causeFeature - the causing feature on cause (may be null)
        receiver - the message receiver for discouraged warnings (may be null, but if not null also cause and causeFeature shall 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 a name alias for decl, only if name has not been defined before. This method helps to migrate from old to new implicit name conventions.
        Parameters:
        name - the alias name
        decl - 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 declaration
        qualification - 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 declaration
        qualification - 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 as decl is already known.
        Parameters:
        decl - the declaration to search for
        Returns:
        true if there is a variable, false else
        See Also:
        contains(IResolvable)
      • contains

        public boolean contains​(java.lang.String name)
        Returns whether a variable with name is already known.
        Parameters:
        name - the variable name to search for
        Returns:
        true if there is a variable, false else
      • add

        public void add​(V[] decls)
        Adds all variable declarations in decl to 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 in decl to 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 with pushLevel() shall properly be closed with popLevel().
      • 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: IResolver
        Resolves an IVML element.
        Specified by:
        getIvmlElement in interface IResolver<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