Class CallArgument
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.expressions.CallArgument
-
public class CallArgument extends java.lang.ObjectDescribes an optionally named call argument.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private Expressionexprprivate booleanfixedprivate java.lang.ObjectfixedValueprivate java.lang.Stringnameprivate TypeDescriptor<?>type
-
Constructor Summary
Constructors Constructor Description CallArgument()Constructor for serialization.CallArgument(java.lang.String name, Expression expr)Creates a named call argument.CallArgument(java.lang.String name, TypeDescriptor<?> type)Creates a named call argument from a given runtime type.CallArgument(Expression expr)Creates an unnamed call argument.CallArgument(TypeDescriptor<?> type)Creates a call argument for runtime operation resolution.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IExpressionVisitor visitor)Visits the expression in this argument.static intcountUnnamedArguments(CallArgument[] arguments)Returns the number of unnamed arguments.static CallArgument[]createUnnamedArguments(Expression... arguments)Creates unnamed arguments.CallArgumentfixValue(java.lang.Object fixedValue)Fixes the value of this argument.java.lang.ObjectfixValue(IExpressionVisitor visitor)Fixes the value that will be returned byaccept(IExpressionVisitor)by callingaccept(IExpressionVisitor).ExpressiongetExpression()Returns the expression specifying the value of the argument.java.lang.StringgetName()Returns the name of the argument.static CallArgument[]getUnnamedArguments(CallArgument[] arguments)Returns the arguments.booleanhasName()Returns whether this argument is named.TypeDescriptor<?>inferType()Infers the type of this expression including the type of the contained sub-expressions.(package private) voidinsertConversion(IMetaOperation operation)Replaces the expression by a transparentCallExpressionexecuting the conversion.(package private) voidinsertConversion(OperationDescriptor operation)Replaces the expression by a transparentCallExpressionexecuting the conversion.voidresolveOperation(TypeDescriptor<?> type, IMetaOperation operation)Resolves an operation, i.e., overwrites the expression.voidsetExpression(Expression expr)Replaces the expression in this argument.java.lang.StringtoString()
-
-
-
Field Detail
-
name
private java.lang.String name
-
expr
private Expression expr
-
type
private TypeDescriptor<?> type
-
fixedValue
private java.lang.Object fixedValue
-
fixed
private boolean fixed
-
-
Constructor Detail
-
CallArgument
CallArgument()
Constructor for serialization.
-
CallArgument
public CallArgument(TypeDescriptor<?> type)
Creates a call argument for runtime operation resolution.- Parameters:
type- the type of the argument
-
CallArgument
public CallArgument(Expression expr)
Creates an unnamed call argument.- Parameters:
expr- the expression specifying the value of the argument
-
CallArgument
public CallArgument(java.lang.String name, Expression expr)Creates a named call argument.- Parameters:
name- the name of the argument (may be null if unnamed)expr- the expression specifying the value of the argument (may be null, e.g., for dynamic dispatch)
-
CallArgument
public CallArgument(java.lang.String name, TypeDescriptor<?> type)Creates a named call argument from a given runtime type.- Parameters:
name- the nametype- the specific type
-
-
Method Detail
-
createUnnamedArguments
public static CallArgument[] createUnnamedArguments(Expression... arguments)
Creates unnamed arguments. [helper]- Parameters:
arguments- the argument expressions- Returns:
- the unnamed arguments
-
countUnnamedArguments
public static int countUnnamedArguments(CallArgument[] arguments)
Returns the number of unnamed arguments. Unnamed must be given before named arguments.- Parameters:
arguments- the arguments to be considered- Returns:
- the number of unnamed arguments
-
getUnnamedArguments
public static CallArgument[] getUnnamedArguments(CallArgument[] arguments)
Returns the arguments.- Parameters:
arguments- the arguments to be considered- Returns:
- the unnamed arguments (may be
arguments)
-
hasName
public boolean hasName()
Returns whether this argument is named.- Returns:
trueif it is named,falseelse
-
getName
public java.lang.String getName()
Returns the name of the argument.- Returns:
- the name of the argument, may be null}.
-
getExpression
public Expression getExpression()
Returns the expression specifying the value of the argument.- Returns:
- the expression specifying the value of the argument
-
inferType
public TypeDescriptor<?> inferType() throws VilException
Infers the type of this expression including the type of the contained sub-expressions.- Returns:
- the type of this expression
- Throws:
VilException- in case that inferring the type fails
-
insertConversion
void insertConversion(OperationDescriptor operation) throws VilException
Replaces the expression by a transparentCallExpressionexecuting the conversion.- Parameters:
operation- the conversion operation (return type, exactly 1 argument)- Throws:
VilException- in case that using the conversion operation is not possible for some reason
-
insertConversion
void insertConversion(IMetaOperation operation) throws VilException
Replaces the expression by a transparentCallExpressionexecuting the conversion.- Parameters:
operation- the conversion operation (return type, exactly 1 argument)- Throws:
VilException- in case that using the conversion operation is not possible for some reason
-
accept
public java.lang.Object accept(IExpressionVisitor visitor) throws VilException
Visits the expression in this argument. [convenience]- Parameters:
visitor- the visitor- Returns:
- the result of visiting this expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
fixValue
public java.lang.Object fixValue(IExpressionVisitor visitor) throws VilException
Fixes the value that will be returned byaccept(IExpressionVisitor)by callingaccept(IExpressionVisitor).- Parameters:
visitor- the visitor- Returns:
- the result of visiting this expression (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
fixValue
public CallArgument fixValue(java.lang.Object fixedValue)
Fixes the value of this argument.Caution:There is no type check, i.e.,fixedValuemust match the type of this argument.- Parameters:
fixedValue- the fixed value- Returns:
- this (builder pattern)
-
resolveOperation
public void resolveOperation(TypeDescriptor<?> type, IMetaOperation operation)
Resolves an operation, i.e., overwrites the expression. Handle with care.- Parameters:
type- the resolvable type (function pointer)operation- the resolving operation (actual base function)
-
setExpression
public void setExpression(Expression expr)
Replaces the expression in this argument. Handle with care!- Parameters:
expr- the new expression
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-