Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-07-09 15:24:52 +0000
committerEd Willink2016-07-17 16:35:32 +0000
commitaf8957a7b9bef04c0aa0f7cb698cd0f68e66c9bc (patch)
tree0f71c58ad17b167fe3f7dc2754cc4fd9798ec44d
parent5c56f07b7c17a68a7b1c6da92f1490d47b3e81b0 (diff)
downloadorg.eclipse.qvtd-af8957a7b9bef04c0aa0f7cb698cd0f68e66c9bc.tar.gz
org.eclipse.qvtd-af8957a7b9bef04c0aa0f7cb698cd0f68e66c9bc.tar.xz
org.eclipse.qvtd-af8957a7b9bef04c0aa0f7cb698cd0f68e66c9bc.zip
[486722] Trace variables used in when clauses
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java3
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationalTransformationToTracePackage.java40
-rw-r--r--plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java25
3 files changed, 58 insertions, 10 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java
index 33058614a..ef0889045 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java
@@ -975,6 +975,9 @@ import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp;
}
} */
VariablesAnalysis.gatherReferredVariables(rAllDomainVariables, ClassUtil.nullFree(rRelation.getDomain()));
+ if (rWhenPattern != null) {
+ VariablesAnalysis.gatherReferredVariables(rAllDomainVariables, rWhenPattern);
+ }
//
this.rSharedVariables = VariablesAnalysis.getMiddleDomainVariables(rRelation);
//
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationalTransformationToTracePackage.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationalTransformationToTracePackage.java
index cdde33cf5..3c80c49e1 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationalTransformationToTracePackage.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationalTransformationToTracePackage.java
@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Horacio Hoyos - initial API and implementation
******************************************************************************/
@@ -20,14 +20,20 @@ import org.eclipse.ocl.pivot.PivotFactory;
import org.eclipse.ocl.pivot.Type;
import org.eclipse.ocl.pivot.TypedElement;
import org.eclipse.ocl.pivot.Variable;
+import org.eclipse.ocl.pivot.VariableDeclaration;
+import org.eclipse.ocl.pivot.VariableExp;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
import org.eclipse.qvtd.compiler.internal.utilities.CompilerUtil;
import org.eclipse.qvtd.pivot.qvtbase.Domain;
+import org.eclipse.qvtd.pivot.qvtbase.Pattern;
+import org.eclipse.qvtd.pivot.qvtbase.Predicate;
import org.eclipse.qvtd.pivot.qvtbase.Rule;
import org.eclipse.qvtd.pivot.qvtrelation.DomainPattern;
import org.eclipse.qvtd.pivot.qvtrelation.Relation;
+import org.eclipse.qvtd.pivot.qvtrelation.RelationCallExp;
import org.eclipse.qvtd.pivot.qvtrelation.RelationDomain;
import org.eclipse.qvtd.pivot.qvtrelation.RelationalTransformation;
+import org.eclipse.qvtd.pivot.qvtrelation.utilities.QVTrelationUtil;
import org.eclipse.qvtd.pivot.qvttemplate.CollectionTemplateExp;
import org.eclipse.qvtd.pivot.qvttemplate.ObjectTemplateExp;
import org.eclipse.qvtd.pivot.qvttemplate.PropertyTemplateItem;
@@ -75,7 +81,7 @@ import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp;
return null;
}
- private org.eclipse.ocl.pivot.@NonNull Class doRelationToTraceClass(@NonNull Relation rRelation) {
+ private org.eclipse.ocl.pivot.@NonNull Class doRelationToTraceClass(@NonNull Relation rRelation) {
@SuppressWarnings("null")org.eclipse.ocl.pivot.@NonNull Class traceClass = PivotFactory.eINSTANCE.createClass();
qvtr2qvtc.putRelationTrace(rRelation, traceClass);
traceClass.setName("T" + rRelation.getName());
@@ -88,12 +94,32 @@ import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp;
doSubTemplateToTraceClassProps(rDomain, rTemplateExp, traceClass);
}
}
+ Pattern rWhenPattern = rRelation.getWhen();
+ if (rWhenPattern != null) {
+ for (Predicate rWhenPredicate : ClassUtil.nullFree(rWhenPattern.getPredicate())) {
+ OCLExpression rConditionExpression = ClassUtil.nonNullState(rWhenPredicate.getConditionExpression());
+ if (rConditionExpression instanceof RelationCallExp) {
+ RelationCallExp rInvocation = (RelationCallExp)rConditionExpression;
+ List<@NonNull OCLExpression> rArguments = ClassUtil.nullFree(rInvocation.getArgument());
+ for (int i = 0; i < rArguments.size(); i++) {
+ OCLExpression rArgument = rArguments.get(i);
+ if (rArgument instanceof VariableExp) {
+ VariableDeclaration rVariable = ((VariableExp)rArgument).getReferredVariable();
+ assert rVariable != null;
+ RelationDomain rDomain = QVTrelationUtil.getRelationCallExpArgumentDomain(rInvocation, i);
+ createTraceProperty(rDomain, traceClass, rVariable, false);
+ // createTraceProperty(rDomain, rVariable.getType(), rVariable, isMany); // ?? not required for CollectionTemplateExp's
+ }
+ }
+ }
+ }
+ }
CompilerUtil.normalizeNameables(ClassUtil.nullFree(traceClass.getOwnedProperties()));
return traceClass;
}
/**
- * Returns true if there are many subtemplate matches.
+ * Returns true if there are many subtemplate matches.
*/
private boolean doSubTemplateToTraceClassProps(@NonNull Domain rDomain, @NonNull TemplateExp te, org.eclipse.ocl.pivot.@NonNull Class rc) {
boolean isMany = false;
@@ -115,10 +141,10 @@ import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp;
}
argIndex++;
}
-// Variable rv = cte.getRest();
-// if (rv != null) {
-// createTraceProperty(rDomain, rc, rv, isMany);
-// }
+ // Variable rv = cte.getRest();
+ // if (rv != null) {
+ // createTraceProperty(rDomain, rc, rv, isMany);
+ // }
createTraceProperty(rDomain, rc, tv, isMany); // ?? not required for CollectionTemplateExp's
}
else if (te instanceof ObjectTemplateExp) {
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java b/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java
index 5b0c8c889..ed572f7b7 100644
--- a/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java
+++ b/plugins/org.eclipse.qvtd.pivot.qvtrelation/src/org/eclipse/qvtd/pivot/qvtrelation/utilities/QVTrelationUtil.java
@@ -28,6 +28,7 @@ import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseEnvironmentFactory.Create
import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseUtil;
import org.eclipse.qvtd.pivot.qvtrelation.DomainPattern;
import org.eclipse.qvtd.pivot.qvtrelation.Relation;
+import org.eclipse.qvtd.pivot.qvtrelation.RelationCallExp;
import org.eclipse.qvtd.pivot.qvtrelation.RelationDomain;
import org.eclipse.qvtd.pivot.qvtrelation.RelationModel;
import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp;
@@ -44,7 +45,25 @@ public class QVTrelationUtil extends QVTbaseUtil
}
return null;
}
-
+
+ /**
+ * Return the domain of the argumentIndex'th argument of rInvocation
+ */
+ public static @NonNull RelationDomain getRelationCallExpArgumentDomain(@NonNull RelationCallExp rInvocation, int argumentIndex) {
+ Relation rRelation = rInvocation.getReferredRelation();
+ assert rRelation != null;
+ int iFirst = 0;
+ for (@NonNull Domain rDomain : ClassUtil.nullFree(rRelation.getDomain())) {
+ RelationDomain rRelationDomain = (RelationDomain)rDomain;
+ int iNext = iFirst + rRelationDomain.getRootVariable().size();
+ if (argumentIndex < iNext) {
+ return rRelationDomain;
+ }
+ iFirst = iNext;
+ }
+ throw new IndexOutOfBoundsException(argumentIndex + " > " + iFirst + " for " + rRelation);
+ }
+
/**
* Return the domain of a given root variable.
* Throws an IllegalStateException if there is no such domain.
@@ -62,7 +81,7 @@ public class QVTrelationUtil extends QVTbaseUtil
}
throw new IllegalStateException("No RelationDomain for " + rootVariable);
}
-
+
/**
* Return all the root variables of relation in RelationCallExp order.
*/
@@ -78,7 +97,7 @@ public class QVTrelationUtil extends QVTbaseUtil
}
return rootVariables;
}
-
+
/**
* Return all the root variables of relationDomain (in partial RelationCallExp order).
*/

Back to the top