Package org.ek9lang.compiler.support
Class AggregateFactory
java.lang.Object
org.ek9lang.compiler.support.AggregateFactory
Support for taking one aggregate and manipulating the methods and the like to be applied
to another aggregate.
This is typically used in the phase 3 where we have one aggregate with a set of methods
and what another aggregate to have those methods but in some cases we want to alter the
return types via covariance.
It also has more general uses in creating operators and methods for specific types or
generic types of T.
This is a factory of sorts, not in the pure OO sense; but still a factory.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add all possible synthetic operators to the aggregate.addComparatorOperator
(IAggregateSymbol aggregateSymbol, String comparatorType, Optional<ISymbol> returnType) Adds a form of a comparison operator.void
addComparatorOperator
(IAggregateSymbol aggregateSymbol, IAggregateSymbol arg0, String comparatorType, Optional<ISymbol> returnType) Adds a form of a comparison operator.Add another constructor to type t, but passing in an s as the value in the construction.Add a constructor to the type aggregate with a particular parameter.Create a new constructor for the aggregate with no params.void
addConstructorIfRequired
(IAggregateSymbol aggregateSymbol, List<ISymbol> constructorArguments, boolean synthetic) Add a new constructor if not present, marked as synthetic.void
addEnumerationMethods
(AggregateSymbol enumerationSymbol) Adds all the appropriate methods for a type that is an 'Enumeration'.void
Takes the 'from' aggregate obtains all the methods that are not abstract that have a return the type 'from' and adds them to the 'to' aggregate.addPublicMethod
(AggregateSymbol aggregate, String methodName, List<ISymbol> methodParameters, Optional<ISymbol> returnType) Just add a method to an aggregate with the name and parameters and return type.void
addPurePublicReturnSameTypeMethod
(IAggregateSymbol aggregate, String methodName) addPurePublicSimpleOperator
(IAggregateSymbol aggregateSymbol, String methodName, Optional<ISymbol> returnType) Adds a simple operator, that is 'pure' (no side effects) and accepts no parameters, but just returns a value.void
addSyntheticConstructorIfRequired
(IAggregateSymbol aggregateSymbol) Add a synthetic constructor, if a constructor is not present.void
addSyntheticConstructorIfRequired
(IAggregateSymbol aggregateSymbol, List<ISymbol> constructorArguments) Add a synthetic constructor, if a constructor is not present.cloneMethodWithNewType
(MethodSymbol method, IAggregateSymbol to) createGenericT
(String name, IScope scope) Create a generic parameter of specific name.createMutatorOperator
(IAggregateSymbol aggregateSymbol, String operatorType) Create an operator of the name supplied.createOperator
(IAggregateSymbol aggregateSymbol, String operatorType, boolean isPure) Create an operator of the name supplied.createPureAcceptSameTypeOperatorAndReturnType
(IAggregateSymbol aggregateSymbol, String comparatorType, Optional<ISymbol> returnType) Creates a pure method with an argument the same as the main type.createPureArgumentOperatorAndReturnType
(IAggregateSymbol aggregateSymbol, IAggregateSymbol arg0, String comparatorType, Optional<ISymbol> returnType) Creates a pure method with an argument of a different type as the main type.createPurePublicReturnSameTypeMethod
(IAggregateSymbol aggregateSymbol, String methodName) createPurePublicSimpleOperator
(IAggregateSymbol aggregateSymbol, String methodName, Optional<ISymbol> returnType) Just creates a public operator with the name specified.createToJsonSimpleOperator
(IAggregateSymbol aggregateSymbol) Create operator for json.getAllPossibleDefaultOperators
(IAggregateSymbol aggregate) Provides all the possible default operators.getDefaultOperator
(IAggregateSymbol aggregate, String operator) If the operator provided can be defaulted then a Method symbol with the correct signature will be returned.resolveBoolean
(IScope scope) Resolve Boolean from cached ek9 types of full scope hierarchy resolution.resolveInteger
(IScope scope) Resolve Integer from cached ek9 types of full scope hierarchy resolution.resolveJson
(IScope scope) Resolve JSON from cached ek9 types of full scope hierarchy resolution.resolveString
(IScope scope) Resolve String from cached ek9 types of full scope hierarchy resolution.resolveVoid
(IScope scope) Resolve Void from cached ek9 types of full scope hierarchy resolution.void
updateToConstrainBy
(IAggregateSymbol t, IAggregateSymbol constrainingType) This is the idea where a 'T' is constrained to only be a type or a subtype of that type.
-
Field Details
-
PUBLIC
- See Also:
-
PARAM
- See Also:
-
EK9_LANG
- See Also:
-
EK9_MATH
- See Also:
-
EK9_PATH
- See Also:
-
EK9_VERSION
- See Also:
-
EK9_REGEX
- See Also:
-
EK9_MONEY
- See Also:
-
EK9_COLOUR
- See Also:
-
EK9_RESOLUTION
- See Also:
-
EK9_DIMENSION
- See Also:
-
EK9_MILLISECOND
- See Also:
-
EK9_DURATION
- See Also:
-
EK9_DATETIME
- See Also:
-
EK9_DATE
- See Also:
-
EK9_TIME
- See Also:
-
EK9_CHARACTER
- See Also:
-
EK9_STRING
- See Also:
-
EK9_INTEGER
- See Also:
-
EK9_VOID
- See Also:
-
EK9_FLOAT
- See Also:
-
EK9_BOOLEAN
- See Also:
-
EK9_BITS
- See Also:
-
EK9_JSON
- See Also:
-
EK9_HTTP_REQUEST
- See Also:
-
EK9_HTTP_RESPONSE
- See Also:
-
EK9_EXCEPTION
- See Also:
-
EK9_LIST
- See Also:
-
EK9_ITERATOR
- See Also:
-
EK9_OPTIONAL
- See Also:
-
EK9_DICTIONARY
- See Also:
-
EK9_DICTIONARY_ENTRY
- See Also:
-
EK9_RESULT
- See Also:
-
EK9_SUPPLIER
- See Also:
-
EK9_CONSUMER
- See Also:
-
EK9_FUNCTION
- See Also:
-
EK9_UNARY_OPERATOR
- See Also:
-
EK9_PREDICATE
- See Also:
-
EK9_COMPARATOR
- See Also:
-
-
Constructor Details
-
AggregateFactory
public AggregateFactory() -
AggregateFactory
-
-
Method Details
-
getEk9Types
-
addSyntheticConstructorIfRequired
Add a synthetic constructor, if a constructor is not present. -
addSyntheticConstructorIfRequired
public void addSyntheticConstructorIfRequired(IAggregateSymbol aggregateSymbol, List<ISymbol> constructorArguments) Add a synthetic constructor, if a constructor is not present. -
addConstructorIfRequired
public void addConstructorIfRequired(IAggregateSymbol aggregateSymbol, List<ISymbol> constructorArguments, boolean synthetic) Add a new constructor if not present, marked as synthetic. -
addNonAbstractMethods
Takes the 'from' aggregate obtains all the methods that are not abstract that have a return the type 'from' and adds them to the 'to' aggregate. It makes new constructors for each of the constructors the 'from' has. So take not note all methods get copied across only those with return type of 'from' which is then transformed in to return type 'to'. In general this method is used for defining types that extend another type, but we just want constructors and co-variance returns. Though it could be used in conjunction with other methods to alter the to aggregate.- Parameters:
from
- The aggregate to get the methods fromto
- The aggregate to add the methods to.
-
cloneMethodWithNewType
-
addConstructor
Create a new constructor for the aggregate with no params.- Parameters:
t
- The aggregate type to add the constructor to.
-
addConstructor
Add another constructor to type t, but passing in an s as the value in the construction.- Parameters:
t
- The aggregate type to add the constructor to.s
- The argument - arg with a symbol type to be passed in as a construction parameter.
-
addConstructor
Add a constructor to the type aggregate with a particular parameter. -
createGenericT
Create a generic parameter of specific name. We use the name createGenericT, so it is obvious what we are doing here. These are used in generic classes/functions, and we provide a number of operators that a developer would reasonably expect. So our generic types and functions will compile and all will look OK. But when it comes to use with a concrete type we have to check the actual operators that are supported by those concrete types - this is done in the IR phase. Where are the generic type/functions get checked in the resolve phase.- Parameters:
name
- - The name of the generic type parameterscope
- - The scope it should go in.
-
updateToConstrainBy
This is the idea where a 'T' is constrained to only be a type or a subtype of that type. -
getAllPossibleDefaultOperators
Provides all the possible default operators. Does not add them to the aggregate, but does create them with the aggregate as the enclosing scope. -
getDefaultOperator
If the operator provided can be defaulted then a Method symbol with the correct signature will be returned. Otherwise, the return Optional will be empty (normally indicating an error). -
addAllSyntheticOperators
Add all possible synthetic operators to the aggregate. This is useful for creation conceptual types like 'T'. Because the semantics of the operators is fixed and known it means it is possible to write code in a generic class that uses these operator. Only when the generic type is parameterized with types are the operators on those types checked for existence. If not present then errors of emitted. -
addPublicMethod
public MethodSymbol addPublicMethod(AggregateSymbol aggregate, String methodName, List<ISymbol> methodParameters, Optional<ISymbol> returnType) Just add a method to an aggregate with the name and parameters and return type. The methodParameters can be empty if there are none. -
addEnumerationMethods
Adds all the appropriate methods for a type that is an 'Enumeration'. This allows a developer to use built-in methods on the 'Enumeration' type. -
addPurePublicReturnSameTypeMethod
-
createPurePublicReturnSameTypeMethod
public MethodSymbol createPurePublicReturnSameTypeMethod(IAggregateSymbol aggregateSymbol, String methodName) -
addComparatorOperator
public void addComparatorOperator(IAggregateSymbol aggregateSymbol, IAggregateSymbol arg0, String comparatorType, Optional<ISymbol> returnType) Adds a form of a comparison operator. -
addComparatorOperator
public MethodSymbol addComparatorOperator(IAggregateSymbol aggregateSymbol, String comparatorType, Optional<ISymbol> returnType) Adds a form of a comparison operator. -
createPureAcceptSameTypeOperatorAndReturnType
public MethodSymbol createPureAcceptSameTypeOperatorAndReturnType(IAggregateSymbol aggregateSymbol, String comparatorType, Optional<ISymbol> returnType) Creates a pure method with an argument the same as the main type. -
createPureArgumentOperatorAndReturnType
public MethodSymbol createPureArgumentOperatorAndReturnType(IAggregateSymbol aggregateSymbol, IAggregateSymbol arg0, String comparatorType, Optional<ISymbol> returnType) Creates a pure method with an argument of a different type as the main type. -
addPurePublicSimpleOperator
public MethodSymbol addPurePublicSimpleOperator(IAggregateSymbol aggregateSymbol, String methodName, Optional<ISymbol> returnType) Adds a simple operator, that is 'pure' (no side effects) and accepts no parameters, but just returns a value. -
createToJsonSimpleOperator
Create operator for json. -
createPurePublicSimpleOperator
public MethodSymbol createPurePublicSimpleOperator(IAggregateSymbol aggregateSymbol, String methodName, Optional<ISymbol> returnType) Just creates a public operator with the name specified. -
createOperator
public MethodSymbol createOperator(IAggregateSymbol aggregateSymbol, String operatorType, boolean isPure) Create an operator of the name supplied. The accepts a single argument of the same type as the aggregateSymbol It also returns a value that is the same as the aggregateSymbol. -
createMutatorOperator
Create an operator of the name supplied. The accepts a single argument of the same type as the aggregateSymbol It also returns a value that is the same as the aggregateSymbol. -
resolveVoid
Resolve Void from cached ek9 types of full scope hierarchy resolution. -
resolveBoolean
Resolve Boolean from cached ek9 types of full scope hierarchy resolution. -
resolveInteger
Resolve Integer from cached ek9 types of full scope hierarchy resolution. -
resolveString
Resolve String from cached ek9 types of full scope hierarchy resolution. -
resolveJson
Resolve JSON from cached ek9 types of full scope hierarchy resolution.
-