diff options
author | Ed Willink | 2016-04-28 16:33:10 +0000 |
---|---|---|
committer | Ed Willink | 2016-04-28 20:32:00 +0000 |
commit | bebf80cec4cfccf6d325246a428653153f61dc69 (patch) | |
tree | e225ae555538c5c97ce9911cf2031708b6166ae0 | |
parent | 93ec8c0bafa14aa943f0cfe7068fb8caf036ee17 (diff) | |
download | org.eclipse.qvtd-bebf80cec4cfccf6d325246a428653153f61dc69.tar.gz org.eclipse.qvtd-bebf80cec4cfccf6d325246a428653153f61dc69.tar.xz org.eclipse.qvtd-bebf80cec4cfccf6d325246a428653153f61dc69.zip |
[486722] Add casts for variable initialization compatibility
2 files changed, 28 insertions, 3 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/AbstractQVTc2QVTc.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/AbstractQVTc2QVTc.java index 6a18a3691..785d15c84 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/AbstractQVTc2QVTc.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/AbstractQVTc2QVTc.java @@ -37,6 +37,8 @@ import org.eclipse.ocl.pivot.PivotFactory; import org.eclipse.ocl.pivot.PivotPackage; import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.PropertyCallExp; +import org.eclipse.ocl.pivot.StandardLibrary; +import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.Variable; import org.eclipse.ocl.pivot.VariableDeclaration; import org.eclipse.ocl.pivot.VariableExp; @@ -432,6 +434,24 @@ public abstract class AbstractQVTc2QVTc return eOut; } + protected @Nullable OCLExpression createCastCopy(@Nullable OCLExpression eIn, @Nullable Type toType) { + if ((eIn == null) || (toType == null)) { + return null; + } + OCLExpression eOut = copy(eIn); + if (eOut == null) { + return null; + } + Type eType = eOut.getType(); + StandardLibrary standardLibrary = context.getEnvironmentFactory().getStandardLibrary(); + if (eType.conformsTo(standardLibrary, toType)) { + return eOut; + } + assert (toType.conformsTo(standardLibrary, eType)); + QVTcoreHelper helper = context.getHelper(); + return helper.createOperationCallExp(eOut, "oclAsType", helper.createTypeExp(toType)); + } + protected @NonNull Mapping doMapping(@NonNull Mapping mOut) { Mapping mIn = context.equivalentSource(mOut); updateChild(mOut.getGuardPattern()); @@ -618,9 +638,10 @@ public abstract class AbstractQVTc2QVTc vOut.setName(vIn.getName()); vOut.setIsImplicit(vIn.isIsImplicit()); vOut.setIsRequired(vIn.isIsRequired()); - vOut.setOwnedInit(copy(vIn.getOwnedInit())); - vOut.setType(vIn.getType()); + Type tVar = vIn.getType(); + vOut.setType(tVar); vOut.setTypeValue(vIn.getTypeValue()); + vOut.setOwnedInit(createCastCopy(vIn.getOwnedInit(), tVar)); return vIn; } @@ -760,6 +781,10 @@ public abstract class AbstractQVTc2QVTc public @NonNull EnvironmentFactory getEnvironmentFactory() { return environmentFactory; } + + public @NonNull QVTcoreHelper getHelper() { + return helper; + } protected @NonNull TypedModel getMiddleTypedModelTarget() { assert middleTypedModelTarget != null; diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/QVTu2QVTm.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/QVTu2QVTm.java index 26ef91ee0..c16259d58 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/QVTu2QVTm.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/etl/mtc/QVTu2QVTm.java @@ -719,7 +719,7 @@ public class QVTu2QVTm extends AbstractQVTc2QVTc { @Override public void update(@NonNull UpdateVisitor updateVisitor) { - finalMVariable.setOwnedInit(updateVisitor.copy(assignments2.get(0).getValue())); + finalMVariable.setOwnedInit(updateVisitor.createCastCopy(assignments2.get(0).getValue(), finalMVariable.getType())); for (@NonNull VariableAssignment uVariableAssignment : assignments2) { createVisitor.getContext().addTrace(uVariableAssignment, finalMVariable); createVisitor.createAll(uVariableAssignment.getOwnedComments(), finalMVariable.getOwnedComments()); |