Commit ed9768f4 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

DSE-CLI: Avoid exceptions in the validator

Issue-Ref: 4058
Issue-Url: https://af3-developer.fortiss.org/issues/4058

Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent 1c09226f
dseml.ecore 9a07a7ea81eff402eeb35bde7b2cebe2482792bb GREEN
dseml.ecore df66fd1e1e45789fc18bcb2d5992eb839188e849 YELLOW
exploration.ecore cab9e5434c3554d3dfb3235c063be1e02653f20f YELLOW
......@@ -201,7 +201,7 @@
<eOperations name="accept" lowerBound="1" eExceptions="#//Exception">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Passes {@code this} {@link IExpression} to the given {@link ExplorationExpressionVisitor} (double dispatch)."/>
<details key="body" value="Object evalResult = visitor.visit(this);&#xD;&#xA;&#x9;&#x9;if(evalResult == null) {&#xD;&#xA;&#x9;&#x9;&#x9;// The eval result is null if the set is empty.&#xD;&#xA;&#x9;&#x9;&#x9;if(java.math.BigInteger.class.isAssignableFrom(evalType)) {&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;return (T)java.math.BigInteger.valueOf(0);&#xD;&#xA;&#x9;&#x9;&#x9;} else if(java.math.BigDecimal.class.isAssignableFrom(evalType)) {&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;return (T)java.math.BigDecimal.valueOf(0);&#xD;&#xA;&#x9;&#x9;&#x9;}&#xD;&#xA;&#x9;&#x9;&#x9;java.lang.reflect.Constructor&lt;T> constructor = evalType.getConstructor();&#xD;&#xA;&#x9;&#x9;&#x9;return constructor.newInstance();&#xD;&#xA;&#x9;&#x9;}&#xD;&#xA;&#x9;&#x9;if(evalType.isAssignableFrom(evalResult.getClass())) {&#xD;&#xA;&#x9;&#x9;&#x9;return (T)evalResult;&#xD;&#xA;&#x9;&#x9;}&#xD;&#xA;&#x9;&#x9;throw new Exception(&quot;The type of the evaluation result of the Expression &quot; + this +&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&quot; is not the expected type &quot; + evalType.getSimpleName() + &quot;.&quot;);"/>
<details key="body" value="Object evalResult = visitor.visit(this);&#xA;if(evalResult == null) {&#xA;&#x9;// The eval result is null if the set is empty.&#xA;&#x9;if(java.math.BigInteger.class.isAssignableFrom(evalType)) {&#xA;&#x9;&#x9;return (T)java.math.BigInteger.valueOf(0);&#xA;&#x9;} else if(java.math.BigDecimal.class.isAssignableFrom(evalType)) {&#xA;&#x9;&#x9;return (T)java.math.BigDecimal.valueOf(0);&#xA;&#x9;} else if(Number.class.isAssignableFrom(evalType)) {&#xA;&#x9;&#x9;// Fallback.&#xA;&#x9;&#x9;return (T)java.math.BigDecimal.valueOf(0);&#xA;&#x9;}&#xA;&#x9;return null;&#xA;}&#xA;if(evalType.isAssignableFrom(evalResult.getClass())) {&#xA;&#x9;return (T)evalResult;&#xA;}&#xA;throw new Exception(&quot;The type of the evaluation result of the Expression &quot; + this +&#xA;&#x9;&#x9;&#x9;&#x9;&quot; is not the expected type &quot; + evalType.getSimpleName() + &quot;.&quot;);"/>
</eAnnotations>
<eGenericType eTypeParameter="#//arithmetic/Sum/accept/T"/>
<eTypeParameters name="T"/>
......
......@@ -72,7 +72,7 @@
<genOperations ecoreOperation="dseml.ecore#//arithmetic/Sum/equals" body="return org.fortiss.af3.exploration.model.arithmetic.impl.ArithmeticStaticImpl.equals(this, other);">
<genParameters ecoreParameter="dseml.ecore#//arithmetic/Sum/equals/other"/>
</genOperations>
<genOperations ecoreOperation="dseml.ecore#//arithmetic/Sum/accept" body="Object evalResult = visitor.visit(this);&#xD;&#xA;&#x9;&#x9;if(evalResult == null) {&#xD;&#xA;&#x9;&#x9;&#x9;// The eval result is null if the set is empty.&#xD;&#xA;&#x9;&#x9;&#x9;if(java.math.BigInteger.class.isAssignableFrom(evalType)) {&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;return (T)java.math.BigInteger.valueOf(0);&#xD;&#xA;&#x9;&#x9;&#x9;} else if(java.math.BigDecimal.class.isAssignableFrom(evalType)) {&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;return (T)java.math.BigDecimal.valueOf(0);&#xD;&#xA;&#x9;&#x9;&#x9;}&#xD;&#xA;&#x9;&#x9;&#x9;java.lang.reflect.Constructor&lt;T> constructor = evalType.getConstructor();&#xD;&#xA;&#x9;&#x9;&#x9;return constructor.newInstance();&#xD;&#xA;&#x9;&#x9;}&#xD;&#xA;&#x9;&#x9;if(evalType.isAssignableFrom(evalResult.getClass())) {&#xD;&#xA;&#x9;&#x9;&#x9;return (T)evalResult;&#xD;&#xA;&#x9;&#x9;}&#xD;&#xA;&#x9;&#x9;throw new Exception(&quot;The type of the evaluation result of the Expression &quot; + this +&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&quot; is not the expected type &quot; + evalType.getSimpleName() + &quot;.&quot;);">
<genOperations ecoreOperation="dseml.ecore#//arithmetic/Sum/accept" body="Object evalResult = visitor.visit(this);&#xA;if(evalResult == null) {&#xA;&#x9;// The eval result is null if the set is empty.&#xA;&#x9;if(java.math.BigInteger.class.isAssignableFrom(evalType)) {&#xA;&#x9;&#x9;return (T)java.math.BigInteger.valueOf(0);&#xA;&#x9;} else if(java.math.BigDecimal.class.isAssignableFrom(evalType)) {&#xA;&#x9;&#x9;return (T)java.math.BigDecimal.valueOf(0);&#xA;&#x9;} else if(Number.class.isAssignableFrom(evalType)) {&#xA;&#x9;&#x9;// Fallback.&#xA;&#x9;&#x9;return (T)java.math.BigDecimal.valueOf(0);&#xA;&#x9;}&#xA;&#x9;return null;&#xA;}&#xA;if(evalType.isAssignableFrom(evalResult.getClass())) {&#xA;&#x9;return (T)evalResult;&#xA;}&#xA;throw new Exception(&quot;The type of the evaluation result of the Expression &quot; + this +&#xA;&#x9;&#x9;&#x9;&#x9;&quot; is not the expected type &quot; + evalType.getSimpleName() + &quot;.&quot;);">
<genParameters ecoreParameter="dseml.ecore#//arithmetic/Sum/accept/visitor"/>
<genParameters ecoreParameter="dseml.ecore#//arithmetic/Sum/accept/evalType"/>
<genTypeParameters ecoreTypeParameter="dseml.ecore#//arithmetic/Sum/accept/T"/>
......
ExecuteDSECommandLineHandler.java 4bdedc9265f4e058b9a44935f30820f0a58c1ab1 GREEN
TestCaseGenerationCommandLineHandler.java ccd942515f5490ff9ed6ece891f3ade206333a08 GREEN
ValidateDSESolutionCommandLineInterface.java 702530b32af8333464e3fc9ca7d40aefe34848f9 GREEN
ValidateDSESolutionCommandLineInterface.java 122c27ebcfa53279084e5ad312dcc859909a16c2 YELLOW
......@@ -33,6 +33,7 @@ import org.fortiss.af3.exploration.model.project.DSE;
import org.fortiss.af3.exploration.model.project.ExplorationStep;
import org.fortiss.af3.exploration.model.project.ModelSnapshot;
import org.fortiss.af3.exploration.model.project.ProcessStep;
import org.fortiss.af3.exploration.model.project.SolutionSelectionStep;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.exploration.model.synthesiscategory.IDeploymentSynthesis;
import org.fortiss.af3.exploration.model.synthesiscategory.ISynthesisCategory;
......@@ -73,7 +74,7 @@ public class ValidateDSESolutionCommandLineInterface implements ICommandLineSwit
}
ProcessStep currentStep = matchingDSE.getCurrentStep();
if(!(currentStep instanceof ExplorationStep)) {
if(!(currentStep instanceof SolutionSelectionStep)) {
error(AF3ExplorationActivator.getDefault(),
"The validator can only be executed if the " +
"current step of a DSE points to an ExplorationStep.");
......@@ -86,41 +87,39 @@ public class ValidateDSESolutionCommandLineInterface implements ICommandLineSwit
return;
}
ExplorationStep expStep = (ExplorationStep)currentStep;
for(SingleExplorationSolution singleSolution : expStep.getSolution().getSolutions()) {
boolean isSolutionValidated = false;
try {
isSolutionValidated = validateSingleSolution(expStep, singleSolution);
} catch(Exception e1) {
error(AF3ExplorationActivator.getDefault(), "The validator for the solver model.");
} finally {
if(isSolutionValidated) {
info(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" passed the validation of the produced SuperSets.");
} else {
error(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" did not pass the validation of the produced SuperSets.");
}
SolutionSelectionStep solStep = (SolutionSelectionStep)currentStep;
SingleExplorationSolution singleSolution = solStep.getSelectedSolution();
boolean isSolutionValidated = false;
try {
isSolutionValidated = validateSingleSolution(solStep);
} catch(Exception e1) {
error(AF3ExplorationActivator.getDefault(), "The validator for the solver model.");
} finally {
if(isSolutionValidated) {
info(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" passed the validation of the produced SuperSets.");
} else {
error(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" did not pass the validation of the produced SuperSets.");
}
}
try {
isSolutionValidated =
validateTransformedSolution(expStep, synthTypes, singleSolution);
} catch(Exception e) {
try {
isSolutionValidated = validateTransformedSolution(solStep, synthTypes, singleSolution);
} catch(Exception e) {
error(AF3ExplorationActivator.getDefault(),
"The validator for the exported solution from the DSE failed.", e);
} finally {
if(isSolutionValidated) {
info(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" passed the validation of the produced model elements.");
} else {
error(AF3ExplorationActivator.getDefault(),
"The validator for the exported solution from the DSE failed.", e);
} finally {
if(isSolutionValidated) {
info(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" passed the validation of the produced model elements.");
} else {
error(AF3ExplorationActivator.getDefault(),
"The solution " + singleSolution.getName() +
" did not pass the validation of the produced model elements.");
}
"The solution " + singleSolution.getName() +
" did not pass the validation of the produced model elements.");
}
}
}
......@@ -131,11 +130,11 @@ public class ValidateDSESolutionCommandLineInterface implements ICommandLineSwit
*
* @throws Exception
*/
private boolean validateSingleSolution(ExplorationStep expStep,
SingleExplorationSolution singleSolution) throws Exception {
private boolean validateSingleSolution(SolutionSelectionStep solStep) throws Exception {
SuperSet<TaskToExecutionUnitAllocationEntry> allocationSet =
singleSolution.getSolutionModel(TaskToExecutionUnitAllocationEntry.class);
solStep.getSolutionSuperSetMap().get(TaskToExecutionUnitAllocationEntry.class);
if(allocationSet != null) {
ExplorationStep expStep = (ExplorationStep)solStep.eContainer();
ExplorationExpressionDeploymentValidator validator =
new ExplorationExpressionDeploymentValidator(allocationSet.getEntries(),
expStep.getRuleSets());
......@@ -149,10 +148,10 @@ public class ValidateDSESolutionCommandLineInterface implements ICommandLineSwit
* Validates the solution exported from the DSE. Thereby, the validation includes the operation
* of {@link IDSESolutionExporterService}.
*/
private boolean validateTransformedSolution(ExplorationStep expStep,
private boolean validateTransformedSolution(SolutionSelectionStep solStep,
Set<Class<? extends ISynthesisCategory>> synthTypes,
SingleExplorationSolution singleSolution) throws Exception {
Collection<IProjectRootElement> rootInputElements = expStep.getInputArtifacts().stream()
Collection<IProjectRootElement> rootInputElements = solStep.getInputArtifacts().stream()
.map(i -> ((ModelSnapshot)i).getRootElement()).collect(toList());
DSESolutionArtifacts solAritfacts =
new DSESolutionArtifacts(rootInputElements, asList(singleSolution));
......@@ -166,6 +165,7 @@ public class ValidateDSESolutionCommandLineInterface implements ICommandLineSwit
TaskToExecutionUnitAllocationTable outArtifact = outArtifactContainer
.getAllocationTable(TaskToExecutionUnitAllocationTable.class);
ExplorationStep expStep = (ExplorationStep)solStep.eContainer();
ExplorationExpressionDeploymentValidator validator =
new ExplorationExpressionDeploymentValidator(outArtifact,
expStep.getUsedRuleSets());
......
ExplorationExpressionDeploymentValidator.java 9f2b3e3fc412c70ee4909e8b1ef1e23eaf744e48 GREEN
ExplorationExpressionEvaluator.java 4f0cd81aae80b59dcf62c41ef0248b85e2374fb2 GREEN
ExplorationExpressionEvaluator.java 276ed06e2af609e79fb990acfa1d1bc6ed977b28 YELLOW
ExpressionVisitorBase.java d3b60238c6685e05f9c75980d1869bd1f0af4132 GREEN
Function.java 9f4dc40006029d2ae58b62936893c2cd0de7e172 GREEN
IExplorationExpressionVisitor.java 6527b9c83dac161a049fff55656e370b332d80ac GREEN
......@@ -302,6 +302,12 @@ public abstract class ExplorationExpressionEvaluator implements IExplorationExpr
return ((BigInteger)lhsVal).multiply((BigInteger)rhsVal);
} else if(lhsVal instanceof BigDecimal && rhsVal instanceof BigDecimal) {
return ((BigDecimal)lhsVal).multiply((BigDecimal)rhsVal);
} else if(lhsVal instanceof BigInteger && rhsVal instanceof BigDecimal) {
return ((BigDecimal)rhsVal)
.multiply(BigDecimal.valueOf(((BigInteger)lhsVal).doubleValue()));
} else if(lhsVal instanceof BigDecimal && rhsVal instanceof BigInteger) {
return ((BigDecimal)lhsVal)
.multiply(BigDecimal.valueOf(((BigInteger)rhsVal).doubleValue()));
}
throw new IncompatibleExpressionTypes(lhsVal.getClass(), rhsVal.getClass(), mul);
......@@ -407,13 +413,13 @@ public abstract class ExplorationExpressionEvaluator implements IExplorationExpr
protected int compare(Number lhsVal, Number rhsVal, IExpression cmpExpr) throws Exception {
if(lhsVal instanceof BigInteger && rhsVal instanceof BigInteger) {
return ((BigInteger)lhsVal).compareTo((BigInteger)rhsVal);
} else if(lhsVal instanceof BigInteger || rhsVal instanceof BigDecimal) {
} else if(lhsVal instanceof BigInteger && rhsVal instanceof BigDecimal) {
lhsVal = BigDecimal.valueOf(((BigInteger)lhsVal).longValueExact());
return ((BigDecimal)lhsVal).compareTo((BigDecimal)rhsVal);
} else if(lhsVal instanceof BigDecimal || rhsVal instanceof BigInteger) {
} else if(lhsVal instanceof BigDecimal && rhsVal instanceof BigInteger) {
rhsVal = BigDecimal.valueOf(((BigInteger)rhsVal).longValueExact());
return ((BigDecimal)lhsVal).compareTo((BigDecimal)rhsVal);
} else if(lhsVal instanceof BigDecimal || rhsVal instanceof BigDecimal) {
} else if(lhsVal instanceof BigDecimal && rhsVal instanceof BigDecimal) {
return ((BigDecimal)lhsVal).compareTo((BigDecimal)rhsVal);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment