Class Rule
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.ProjectElement
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.RuleBlock
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.AbstractRule
-
- net.ssehub.easy.instantiation.core.model.buildlangModel.Rule
-
- All Implemented Interfaces:
IBuildlangElement,IRuleBlock,ILanguageElement,IParameterizable<VariableDeclaration>,IResolvableOperation<VariableDeclaration>,IMetaOperation,IStringValueProvider
public class Rule extends AbstractRule
Represents a VIL build rule (production strategy).- Author:
- kroeher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRule.SideDefines the rule sides.-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IMetaOperation
IMetaOperation.CompatibilityResult
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description private booleanisProtectedprivate RuleCallExpression[]lhsRuleCallsprivate AbstractRuleMatchExpression[]lhsRuleMatchesprivate VariableDeclaration[]lhsVarsprivate java.util.Map<java.lang.String,VariableDeclaration>namedParamprivate VariableDeclaration[]parametersprivate Scriptparentprivate TypeDescriptor<?>returnTypeprivate VariableDeclaration[]rhsMatchVarsprivate RuleCallExpression[]rhsRuleCallsprivate AbstractRuleMatchExpression[]rhsRuleMatchesprivate VariableDeclaration[]rhsVars
-
Constructor Summary
Constructors Constructor Description Rule()Constructor for serialization.Rule(java.lang.String name, boolean isProtected, VariableDeclaration[] parameters, RuleDescriptor descriptor, Script parent)Create a new rule with the given name.Rule(java.lang.String name, boolean isProtected, TypeDescriptor<?> returnType, VariableDeclaration[] parameters, Script parent)Create a new rule with the given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectaccept(IVisitor visitor)Accepts the visitor for visiting.booleanacceptsNamedParameters()Returns whether the operation accepts named parameters.voidappendCallTo(AbstractRule target, boolean qualifiedCall)Appends a call totargetto the rule body.IMetaTypegetDeclaringType()Returns the declaring type.TypeDescriptor<?>getDefaultReturnType()Returns the default return type that shall not be emitted / does not require return expressions.java.lang.StringgetJavaSignature()Returns the java-like signature of this operation.VariableDeclarationgetMatchVariable(Rule.Side side, int index)Returns the specified match variable.VariableDeclarationgetParameter(int index)Get the parameter of this rule at the specified index.VariableDeclarationgetParameter(java.lang.String name)Returns a named parameter declaration.intgetParameterCount()Get the number of parameters of this rule.IMetaTypegetParameterType(int index)Returns the specified parameter type.ScriptgetParent()Returns the parent script this rule is member of.intgetRequiredParameterCount()Returns the number of required parameters, i.e., non-default and non-named parameters.TypeDescriptor<?>getReturnType()Returns the return type of this operation.RuleCallExpressiongetRuleCall(Rule.Side side, int index)Get the rule call on the given side of this rule at the specified index.intgetRuleCallCount(Rule.Side side)Get the number of rule calls on the given side of this rule.AbstractRuleMatchExpressiongetRuleCondition(Rule.Side side, int index)Get the match conditions of this rule on the given side at the specified index.intgetRuleConditionCount(Rule.Side side)Get the number of match conditions on the given side of this rule.java.lang.StringgetSignature()Returns the signature of the method (in terms of VIL types where possible).java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.VariableDeclarationgetVariable(Rule.Side side, int index)Returns the specified variable.intgetVariablesCount(Rule.Side side)Get the number of variables of this rule on the specified side.booleanhasCondition(Rule.Side side)Returns whether the specified side has either rule calls or a matching condition.java.lang.Objectinvoke(java.lang.Object... args)Invokes the specified operation.IMetaOperation.CompatibilityResultisCompatible(java.lang.Class<?> retType, java.lang.Object... params)Returns whether the operation represented by this instance is compatible to the given return type and parameters.booleanisFirstParameterOperand()Returns whether the first parameter is the operand.booleanisPlaceholder()Returns whether this operation is valid or whether it is a placeholder operation in case that the original operation cannot be resolved but the script shall remain executable.booleanisProtected()Returns whether a rule is declared as protected regarding its visibility.booleanisStatic()Returns whether this operation is static.booleanisVirtual()Returns whether this block is a real block or consists just of a block element without brackets.booleanreturnActualValue()Returns whether this rule shall return an actual value (function) or a rule execution result.private RuleCallExpression[]selectCalls(Rule.Side side)Returns the rule calls on the specified side of this rule.private AbstractRuleMatchExpression[]selectConditions(Rule.Side side)Returns the match conditions on the specified side of this rule.private VariableDeclaration[]selectMatchVars(Rule.Side side)Returns the LHS/RHS match variables on the specified side of this rule.private VariableDeclaration[]selectVars(Rule.Side side)Returns the LHS/RHS variables on the specified side of this rule.voidsetDescriptorInformation(RuleDescriptor descriptor)Sets the information from the given ruledescriptor.protected voidsetParent(ILanguageElement parent)Changes the parent.protected voidsetParentFor(VariableDeclaration var)Changes the parent of the given variable to this.protected voidsetParentFor(VariableDeclaration[] vars)Changes the parents forvarsto this.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.buildlangModel.AbstractRule
isConstructor
-
Methods inherited from class net.ssehub.easy.instantiation.core.model.buildlangModel.RuleBlock
addBodyElement, addBodyElement, append, getBodyElement, getBodyElementCount, setBody
-
Methods inherited from class net.ssehub.easy.instantiation.core.model.buildlangModel.ProjectElement
getName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IMetaOperation
getName
-
-
-
-
Field Detail
-
lhsRuleMatches
private AbstractRuleMatchExpression[] lhsRuleMatches
-
lhsRuleCalls
private RuleCallExpression[] lhsRuleCalls
-
rhsRuleMatches
private AbstractRuleMatchExpression[] rhsRuleMatches
-
rhsRuleCalls
private RuleCallExpression[] rhsRuleCalls
-
parameters
private VariableDeclaration[] parameters
-
namedParam
private java.util.Map<java.lang.String,VariableDeclaration> namedParam
-
isProtected
private boolean isProtected
-
parent
private Script parent
-
lhsVars
private VariableDeclaration[] lhsVars
-
rhsVars
private VariableDeclaration[] rhsVars
-
rhsMatchVars
private VariableDeclaration[] rhsMatchVars
-
returnType
private TypeDescriptor<?> returnType
-
-
Constructor Detail
-
Rule
Rule()
Constructor for serialization.
-
Rule
public Rule(java.lang.String name, boolean isProtected, TypeDescriptor<?> returnType, VariableDeclaration[] parameters, Script parent)Create a new rule with the given name. As no descriptor is given, callsetDescriptorInformation(RuleDescriptor)somewhen before using this rule.- Parameters:
name- The name of the rule.isProtected- if the visibility of the rule is actually restrictedreturnType- the return type (may be null to use the default)parameters- the parameters of this rule (may be null)parent- the parent rule
-
Rule
public Rule(java.lang.String name, boolean isProtected, VariableDeclaration[] parameters, RuleDescriptor descriptor, Script parent)Create a new rule with the given name.- Parameters:
name- The name of the rule.isProtected- if the visibility of the rule is actually restrictedparameters- the parameters of this rule (may be null)descriptor- the descriptorparent- the parent rule- See Also:
setDescriptorInformation(RuleDescriptor)
-
-
Method Detail
-
setDescriptorInformation
public void setDescriptorInformation(RuleDescriptor descriptor)
Sets the information from the given ruledescriptor.- Parameters:
descriptor- the descriptor to be used
-
getParent
public Script getParent()
Description copied from class:AbstractRuleReturns the parent script this rule is member of.- Specified by:
getParentin interfaceILanguageElement- Specified by:
getParentin classAbstractRule- Returns:
- the parent
-
getParameterCount
public int getParameterCount()
Description copied from interface:IParameterizableGet the number of parameters of this rule.- Returns:
- The number of parameters of this rule.
-
getParameter
public VariableDeclaration getParameter(int index)
Description copied from interface:IParameterizableGet the parameter of this rule at the specified index.- Parameters:
index- The 0-based index of the rule parameter to be returned.- Returns:
- The rule parameter at the given index.
-
getRequiredParameterCount
public int getRequiredParameterCount()
Description copied from interface:IParameterizableReturns the number of required parameters, i.e., non-default and non-named parameters.- Returns:
- the number of required parameters
-
getParameter
public VariableDeclaration getParameter(java.lang.String name)
Description copied from interface:IParameterizableReturns a named parameter declaration.- Parameters:
name- the name of the parameter- Returns:
- the declaration or null if there is none
-
getVariable
public VariableDeclaration getVariable(Rule.Side side, int index)
Returns the specified variable.- Parameters:
side- the side (LHS, RHS)index- The 0-based index of the rule element to be returned.- Returns:
- the variable or null if there is none
- Throws:
java.lang.IndexOutOfBoundsException- ifindex < 0 || index >=getVariablesCount(Side)
-
getMatchVariable
public VariableDeclaration getMatchVariable(Rule.Side side, int index)
Returns the specified match variable.- Parameters:
side- the side (LHS, RHS)index- The 0-based index of the rule element to be returned.- Returns:
- the match variable or null if there is none
-
getVariablesCount
public int getVariablesCount(Rule.Side side)
Get the number of variables of this rule on the specified side.- Parameters:
side- the side (LHS, RHS)- Returns:
- the number of variables .
-
selectVars
private VariableDeclaration[] selectVars(Rule.Side side)
Returns the LHS/RHS variables on the specified side of this rule.- Parameters:
side- the side (LHS, RHS)- Returns:
- the rule calls
-
selectMatchVars
private VariableDeclaration[] selectMatchVars(Rule.Side side)
Returns the LHS/RHS match variables on the specified side of this rule.- Parameters:
side- the side (LHS, RHS)- Returns:
- the rule calls
-
selectConditions
private AbstractRuleMatchExpression[] selectConditions(Rule.Side side)
Returns the match conditions on the specified side of this rule.- Parameters:
side- the side (LHS, RHS)- Returns:
- the select conditions
-
selectCalls
private RuleCallExpression[] selectCalls(Rule.Side side)
Returns the rule calls on the specified side of this rule.- Parameters:
side- the side (LHS, RHS)- Returns:
- the rule calls
-
hasCondition
public boolean hasCondition(Rule.Side side)
Description copied from class:AbstractRuleReturns whether the specified side has either rule calls or a matching condition.- Specified by:
hasConditionin classAbstractRule- Parameters:
side- the side (LHS, RHS)- Returns:
- whether the specified side has cinditions at all
-
getRuleConditionCount
public int getRuleConditionCount(Rule.Side side)
Description copied from class:AbstractRuleGet the number of match conditions on the given side of this rule.- Specified by:
getRuleConditionCountin classAbstractRule- Parameters:
side- the side (LHS, RHS)- Returns:
- The number of preconditions (match conditions) of this rule.
-
getRuleCondition
public AbstractRuleMatchExpression getRuleCondition(Rule.Side side, int index)
Description copied from class:AbstractRuleGet the match conditions of this rule on the given side at the specified index.- Specified by:
getRuleConditionin classAbstractRule- Parameters:
side- the side (LHS, RHS)index- The 0-based index of the match condition to be returned.- Returns:
- The match condition at the given index.
-
getRuleCallCount
public int getRuleCallCount(Rule.Side side)
Description copied from class:AbstractRuleGet the number of rule calls on the given side of this rule.- Specified by:
getRuleCallCountin classAbstractRule- Parameters:
side- the side (LHS, RHS)- Returns:
- The number of postconditions of this rule.
-
getRuleCall
public RuleCallExpression getRuleCall(Rule.Side side, int index)
Description copied from class:AbstractRuleGet the rule call on the given side of this rule at the specified index.- Specified by:
getRuleCallin classAbstractRule- Parameters:
side- the side (LHS, RHS)index- The 0-based index of the rule element to be returned.- Returns:
- The rule element at the given index.
-
isProtected
public boolean isProtected()
Description copied from class:AbstractRuleReturns whether a rule is declared as protected regarding its visibility.- Specified by:
isProtectedin classAbstractRule- Returns:
trueif it is protected,falseelse
-
accept
public java.lang.Object accept(IVisitor visitor) throws VilException
Description copied from interface:IBuildlangElementAccepts the visitor for visiting.- Parameters:
visitor- the visitor to be used- Returns:
- the result of visiting this instance (may be null)
- Throws:
VilException- in case that visiting fails (e.g., execution)
-
getParameterType
public IMetaType getParameterType(int index)
Description copied from interface:IMetaOperationReturns the specified parameter type.- Parameters:
index- the index of the parameter to return- Returns:
- the specified parameter type
-
getJavaSignature
public java.lang.String getJavaSignature()
Description copied from interface:IMetaOperationReturns the java-like signature of this operation.- Returns:
- the java-like Java signature of this operation
-
getSignature
public java.lang.String getSignature()
Description copied from interface:IMetaOperationReturns the signature of the method (in terms of VIL types where possible).- Returns:
- the signature of the method
-
getDefaultReturnType
public TypeDescriptor<?> getDefaultReturnType()
Returns the default return type that shall not be emitted / does not require return expressions.- Returns:
- the default return type
-
returnActualValue
public boolean returnActualValue()
Returns whether this rule shall return an actual value (function) or a rule execution result.- Returns:
truein case of an actual value,falseelse
-
getReturnType
public TypeDescriptor<?> getReturnType()
Description copied from interface:IResolvableOperationReturns the return type of this operation.- Returns:
- the return type
-
acceptsNamedParameters
public boolean acceptsNamedParameters()
Description copied from interface:IMetaOperationReturns whether the operation accepts named parameters.- Returns:
trueif it accepts named parameters,falseelse
-
isStatic
public boolean isStatic()
Description copied from interface:IMetaOperationReturns whether this operation is static.- Returns:
trueif it is static,falseelse
-
isFirstParameterOperand
public boolean isFirstParameterOperand()
Description copied from interface:IMetaOperationReturns whether the first parameter is the operand.- Returns:
trueif the first parameter is the operand,falseelse
-
getDeclaringType
public IMetaType getDeclaringType()
Description copied from interface:IMetaOperationReturns the declaring type.- Returns:
- the declaring type (may be null in case of a wrapped external Java method)
-
appendCallTo
public void appendCallTo(AbstractRule target, boolean qualifiedCall) throws VilException
Description copied from class:AbstractRuleAppends a call totargetto the rule body. Currently, this method considers parameters only in the sequence of the parameters of this rule.- Specified by:
appendCallToin classAbstractRule- Parameters:
target- the rule to append the call toqualifiedCall- insert a qualified call iftrue, an unqualified call iffalse- Throws:
VilException- in case that creating / resolving the rule call fails
-
isPlaceholder
public boolean isPlaceholder()
Description copied from interface:IMetaOperationReturns whether this operation is valid or whether it is a placeholder operation in case that the original operation cannot be resolved but the script shall remain executable.- Returns:
trueif this operation is a placeholder,falseelse
-
isVirtual
public boolean isVirtual()
Description copied from interface:IRuleBlockReturns whether this block is a real block or consists just of a block element without brackets.- Returns:
trueif this block is virtual,falseelse
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
setParent
protected void setParent(ILanguageElement parent)
Description copied from class:ProjectElementChanges the parent. Please override if children must be adjusted according. Shall be called only once per instance, but there is no limitation.
-
setParentFor
protected void setParentFor(VariableDeclaration[] vars)
Changes the parents forvarsto this. [convenience]- Parameters:
vars- the variables
-
setParentFor
protected void setParentFor(VariableDeclaration var)
Changes the parent of the given variable to this. [access modifiers]- Parameters:
var- the variable
-
isCompatible
public IMetaOperation.CompatibilityResult isCompatible(java.lang.Class<?> retType, java.lang.Object... params)
Description copied from interface:IMetaOperationReturns whether the operation represented by this instance is compatible to the given return type and parameters. This method does not consider possible unnamed parameter rather than the underlying Java parameter.- Parameters:
retType- the return type (may be null in order to ignore this parameter)params- the parameters (may be null if there are none, may be classes)- Returns:
- an instance of
IMetaOperation.CompatibilityResultdenoting the actual compatibility level
-
invoke
public java.lang.Object invoke(java.lang.Object... args) throws VilExceptionDescription copied from interface:IMetaOperationInvokes the specified operation. This method does not consider possible unnamed parameter rather than the underlying Java parameter. In case ofIMetaOperation.acceptsNamedParameters()the caller must ensure that the last parameter is amap<String, Object>containing the named parameters.- Parameters:
args- the arguments, in case of non-static operations the first argument must be the object to execute on- Returns:
- the result of the execution
- Throws:
VilException- if the invocation fails- See Also:
IMetaOperation.isCompatible(java.lang.Class<?>, java.lang.Object...)
-
-