Class TypeEnvironment

java.lang.Object
com.aquima.interactions.expressions.environment.TypeEnvironment
All Implemented Interfaces:
ITypeEnvironment

public class TypeEnvironment extends Object implements ITypeEnvironment
This class is an implementation of the ITypeEnvironment interface which uses the TypeScope class to define elements within the scope.
Since:
6.0
Author:
F. van der Meer
  • Constructor Details

    • TypeEnvironment

      public TypeEnvironment(ITypeDefinitions definitions)
      Constructs this object with the initial definitions object. A definitions object contains all information for variables/objects/functions and templates.
      Parameters:
      definitions - The definitions object which is mandatory.
  • Method Details

    • beginScope

      public void beginScope()
      Description copied from interface: ITypeEnvironment
      This function starts a new scope in which types can be declared. It allows for variable (type) hiding until an end scope is called. Which in turn means a cleanup of the current scope.
      Specified by:
      beginScope in interface ITypeEnvironment
    • endScope

      public void endScope()
      Description copied from interface: ITypeEnvironment
      This function ends the current scope and cleans up all the types declared within this scope. If an end scope is called while there was no begin scope called previously an exception is thrown.
      Specified by:
      endScope in interface ITypeEnvironment
    • declareVariableType

      public void declareVariableType(Identifier variableName, Type type)
      Description copied from interface: ITypeEnvironment
      This method declares a variable of a type within this scope. Subsequent calls to lookupVariable will be able to see this variable as an existing variable.
      Specified by:
      declareVariableType in interface ITypeEnvironment
      Parameters:
      variableName - The name of the variable to use.
      type - The type the variable name is bound to.
    • declareFieldType

      public void declareFieldType(String recordTypeName, Identifier name, Type type)
      Description copied from interface: ITypeEnvironment
      This method declares a variable within a record-type object. subsequent calls to lookupRecordVariable will be able to see this variable as an existing variable.
      Specified by:
      declareFieldType in interface ITypeEnvironment
      Parameters:
      recordTypeName - the record type name ( entity type name )
      name - The name of the variable.
      type - The type the name within the record will be bound to.
    • getFunctionDefinitions

      public IFunction[] getFunctionDefinitions(Identifier name)
      Description copied from interface: ITypeEnvironment
      Locates functions based on their name.
      Specified by:
      getFunctionDefinitions in interface ITypeEnvironment
      Parameters:
      name - The name of the function which is mandatory.
      Returns:
      An array containing all matching functions, an empty array is returned when there was no function with the specified name.
    • lookupRecordType

      public Type lookupRecordType(String entityType, Identifier ident)
      Description copied from interface: ITypeEnvironment
      Looks up a record type accessor, person.name (name is a record type). If the type is found it will be returned
      Specified by:
      lookupRecordType in interface ITypeEnvironment
      Parameters:
      entityType - The type name of the record type ( entity )
      ident - The accessor of the record type ( i.e. the attributename )
      Returns:
      The type of the record identifier, null otherwise.
    • lookupRecordType

      public Type lookupRecordType(Identifier recordTypeName)
      Description copied from interface: ITypeEnvironment
      This method checks if there is a record type for the specified name.
      Specified by:
      lookupRecordType in interface ITypeEnvironment
      Parameters:
      recordTypeName - The type name identifier which is mandatory.
      Returns:
      The Type object when available, null otherwise.
    • lookupVariable

      public Type lookupVariable(Identifier typeName)
      Description copied from interface: ITypeEnvironment
      Locates a variable as specified by the name. ( This method only checks the 'scope' and does not do type-as-name tricks )
      Specified by:
      lookupVariable in interface ITypeEnvironment
      Parameters:
      typeName - The variable name which is a mandatory parameter.
      Returns:
      The type of this variable if it is known, null otherwise.
    • lookupVariable

      public Type lookupVariable(String recordTypeName, Identifier instanceName)
      Description copied from interface: ITypeEnvironment
      Locates an object type with the specified instance name for the type name. If the object was not found null will be returned.
      Specified by:
      lookupVariable in interface ITypeEnvironment
      Parameters:
      recordTypeName - The type name of the record-type (entity)
      instanceName - The instance name which is/should be unique for the specified recordTypeName
      Returns:
      The type object when the object could be found.
    • getSharedAncestor

      public String getSharedAncestor(String expectedType, String receivedType)
      Description copied from interface: ITypeEnvironment
      This function locates the shared ancestor type for the 2 passed arguments. It will try to find the 'first' shared ancestor within the ancestry tree. If they do not have a shared ancestor null will be returned.
      Specified by:
      getSharedAncestor in interface ITypeEnvironment
      Parameters:
      expectedType - The first type argument.
      receivedType - The second type argument.
      Returns:
      A string representing the shared ancestor, null when they have no common ancestor.
    • getExpressionTemplate

      public IExpr getExpressionTemplate(Identifier name)
      Description copied from interface: ITypeEnvironment
      Locates an expression template based on its name.
      Specified by:
      getExpressionTemplate in interface ITypeEnvironment
      Parameters:
      name - The name of the expression template which is mandatory.
      Returns:
      The expression template, null when not found.