Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-10-20 15:22:22 +0000
committerEd Willink2016-10-30 11:38:45 +0000
commit3cc5dc7ff76317ff8c5cdae607930b9df68cd7d9 (patch)
tree0ced0fd0b7e76eabd9bc31472e1ccfd359fd4b87
parentb279f137130ca1fd38903590461b7d23b09fa2d1 (diff)
downloadorg.eclipse.qvtd-3cc5dc7ff76317ff8c5cdae607930b9df68cd7d9.tar.gz
org.eclipse.qvtd-3cc5dc7ff76317ff8c5cdae607930b9df68cd7d9.tar.xz
org.eclipse.qvtd-3cc5dc7ff76317ff8c5cdae607930b9df68cd7d9.zip
[506228] Test that QVTr's qvti is loadable.
-rw-r--r--plugins/org.eclipse.qvtd.xtext.qvtimperative/src/org/eclipse/qvtd/xtext/qvtimperative/as2cs/QVTimperativeDeclarationVisitor.java6
-rw-r--r--plugins/org.eclipse.qvtd.xtext.qvtrelation/src/org/eclipse/qvtd/xtext/qvtrelation/cs2as/QVTrelationCSLeft2RightVisitor.java17
-rw-r--r--tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java89
3 files changed, 100 insertions, 12 deletions
diff --git a/plugins/org.eclipse.qvtd.xtext.qvtimperative/src/org/eclipse/qvtd/xtext/qvtimperative/as2cs/QVTimperativeDeclarationVisitor.java b/plugins/org.eclipse.qvtd.xtext.qvtimperative/src/org/eclipse/qvtd/xtext/qvtimperative/as2cs/QVTimperativeDeclarationVisitor.java
index 31da6ae8f..c91df2cf8 100644
--- a/plugins/org.eclipse.qvtd.xtext.qvtimperative/src/org/eclipse/qvtd/xtext/qvtimperative/as2cs/QVTimperativeDeclarationVisitor.java
+++ b/plugins/org.eclipse.qvtd.xtext.qvtimperative/src/org/eclipse/qvtd/xtext/qvtimperative/as2cs/QVTimperativeDeclarationVisitor.java
@@ -457,7 +457,7 @@ public class QVTimperativeDeclarationVisitor extends QVTbaseDeclarationVisitor i
GuardParameterCS csUnrealizedVariable = context.refreshNamedElement(GuardParameterCS.class, QVTimperativeCSPackage.Literals.GUARD_PARAMETER_CS, asVariable);
csUnrealizedVariable.setPivot(asVariable);
csUnrealizedVariable.setReferredTypedModel(asTypedModel);
- csUnrealizedVariable.setOwnedType(createTypeRefCS(asVariable.getType(), asUsedPackage));
+ csUnrealizedVariable.setOwnedType(createTypeRefCS(asVariable.getType(), null));
return csUnrealizedVariable;
}
@@ -663,7 +663,7 @@ public class QVTimperativeDeclarationVisitor extends QVTbaseDeclarationVisitor i
ImperativeTypedModel asTypedModel = asNewStatement.getReferredTypedModel();
org.eclipse.ocl.pivot.Package asUsedPackage = asTypedModel.getUsedPackage().size() > 0 ? asTypedModel.getUsedPackage().get(0) : null;
NewStatementCS csNewStatement = context.refreshNamedElement(NewStatementCS.class, QVTimperativeCSPackage.Literals.NEW_STATEMENT_CS, asNewStatement);
- csNewStatement.setOwnedType(createTypeRefCS(asNewStatement.getType(), asUsedPackage));
+ csNewStatement.setOwnedType(createTypeRefCS(asNewStatement.getType(), null));
csNewStatement.setReferredTypedModel(asTypedModel);
csNewStatement.setOwnedExpression(context.visitDeclaration(ExpCS.class, asNewStatement.getOwnedExpression()));
refreshObservedProperties(asNewStatement, csNewStatement.getObservedProperties(), ClassUtil.nullFree(asNewStatement.getObservedProperties()));
@@ -733,7 +733,7 @@ public class QVTimperativeDeclarationVisitor extends QVTbaseDeclarationVisitor i
SimpleParameterCS csUnrealizedVariable = context.refreshNamedElement(SimpleParameterCS.class, QVTimperativeCSPackage.Literals.SIMPLE_PARAMETER_CS, asVariable);
csUnrealizedVariable.setPivot(asVariable);
csUnrealizedVariable.setReferredTypedModel(asTypedModel);
- csUnrealizedVariable.setOwnedType(createTypeRefCS(asVariable.getType(), asUsedPackage));
+ csUnrealizedVariable.setOwnedType(createTypeRefCS(asVariable.getType(), null));
return csUnrealizedVariable;
}
diff --git a/plugins/org.eclipse.qvtd.xtext.qvtrelation/src/org/eclipse/qvtd/xtext/qvtrelation/cs2as/QVTrelationCSLeft2RightVisitor.java b/plugins/org.eclipse.qvtd.xtext.qvtrelation/src/org/eclipse/qvtd/xtext/qvtrelation/cs2as/QVTrelationCSLeft2RightVisitor.java
index 3bb94f45a..4cf671524 100644
--- a/plugins/org.eclipse.qvtd.xtext.qvtrelation/src/org/eclipse/qvtd/xtext/qvtrelation/cs2as/QVTrelationCSLeft2RightVisitor.java
+++ b/plugins/org.eclipse.qvtd.xtext.qvtrelation/src/org/eclipse/qvtd/xtext/qvtrelation/cs2as/QVTrelationCSLeft2RightVisitor.java
@@ -24,6 +24,7 @@ import org.eclipse.ocl.pivot.OperationCallExp;
import org.eclipse.ocl.pivot.PivotPackage;
import org.eclipse.ocl.pivot.Type;
import org.eclipse.ocl.pivot.Variable;
+import org.eclipse.ocl.pivot.VariableDeclaration;
import org.eclipse.ocl.pivot.internal.messages.PivotMessagesInternal;
import org.eclipse.ocl.pivot.internal.scoping.EnvironmentView;
import org.eclipse.ocl.pivot.internal.scoping.ScopeFilter;
@@ -74,11 +75,11 @@ public class QVTrelationCSLeft2RightVisitor extends AbstractQVTrelationCSLeft2Ri
return (object instanceof Operation) || (object instanceof Rule);
}
}
-
+
public static class ResolvedRuleInvocation implements Invocations
{
protected final @NonNull Rule invocation;
-
+
public ResolvedRuleInvocation(@NonNull Rule invocation) {
this.invocation = invocation;
}
@@ -87,7 +88,7 @@ public class QVTrelationCSLeft2RightVisitor extends AbstractQVTrelationCSLeft2Ri
public @NonNull NamedElement getSingleResult() {
return invocation;
}
-
+
@Override
public @NonNull Type getSourceType() {
return ClassUtil.nonNullState(invocation.getTransformation());
@@ -173,7 +174,7 @@ public class QVTrelationCSLeft2RightVisitor extends AbstractQVTrelationCSLeft2Ri
}
Function function = getBestFunction(invocations);
if (function != null) {
-// Operation baseOperation = metamodelManager.resolveBaseOperation(function);
+ // Operation baseOperation = metamodelManager.resolveBaseOperation(function);
OperationCallExp operationCallExp = context.refreshModelElement(OperationCallExp.class, PivotPackage.Literals.OPERATION_CALL_EXP, csNameExp);
context.setReferredOperation(operationCallExp, function);
context.setType(operationCallExp, function.getType(), function.isIsRequired());
@@ -181,7 +182,7 @@ public class QVTrelationCSLeft2RightVisitor extends AbstractQVTrelationCSLeft2Ri
resolveOperationArguments(csRoundBracketedClause, function, operationCallExp);
Type owningClass = function.getOwningClass();
if (owningClass instanceof RelationalTransformation) {
- Variable thisVariable = QVTbaseUtil.getContextVariable(standardLibrary, (RelationalTransformation) owningClass);
+ VariableDeclaration thisVariable = QVTbaseUtil.getContextVariable(standardLibrary, (RelationalTransformation) owningClass);
operationCallExp.setOwnedSource(PivotUtil.createVariableExp(thisVariable));
}
return operationCallExp;
@@ -214,7 +215,7 @@ public class QVTrelationCSLeft2RightVisitor extends AbstractQVTrelationCSLeft2Ri
int csArgumentCount = csArguments.size();
if (csArgumentCount > 0) {
if (csArguments.get(0).getRole() != NavigationRole.EXPRESSION) {
- context.addDiagnostic(csNameExp, "Relation calls can only specify expressions");
+ context.addDiagnostic(csNameExp, "Relation calls can only specify expressions");
}
for (int argIndex = 0; argIndex < csArgumentCount; argIndex++) {
NavigatingArgCS csArgument = csArguments.get(argIndex);
@@ -232,11 +233,11 @@ public class QVTrelationCSLeft2RightVisitor extends AbstractQVTrelationCSLeft2Ri
}
if ((csArgumentCount != patternsCount) && (relation != standardLibrary.getOclInvalidOperation())) {
String boundMessage = StringUtil.bind(PivotMessagesInternal.MismatchedArgumentCount_ERROR_, csArgumentCount, patternsCount);
- context.addDiagnostic(csNameExp, boundMessage);
+ context.addDiagnostic(csNameExp, boundMessage);
}
context.refreshList(relationCallExp.getArgument(), pivotArguments);
}
-
+
protected void resolveRelationArgumentTypes(@Nullable List<Variable> rootVariables, @NonNull RoundBracketedClauseCS csRoundBracketedClause) {
int argIndex = 0;
for (NavigatingArgCS csArgument : csRoundBracketedClause.getOwnedArguments()) {
diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
index 8126fe06a..4ae8560ef 100644
--- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
+++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java
@@ -32,10 +32,15 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.codegen.dynamic.OCL2JavaFileObject;
+import org.eclipse.ocl.pivot.PivotTables;
import org.eclipse.ocl.pivot.internal.manager.MetamodelManagerInternal;
+import org.eclipse.ocl.pivot.messages.StatusCodes;
import org.eclipse.ocl.pivot.model.OCLstdlib;
import org.eclipse.ocl.pivot.resource.ASResource;
+import org.eclipse.ocl.pivot.resource.CSResource;
+import org.eclipse.ocl.pivot.resource.ProjectManager;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
+import org.eclipse.ocl.pivot.utilities.OCL;
import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.ocl.xtext.base.services.BaseLinkingService;
import org.eclipse.qvtd.codegen.qvti.QVTiCodeGenOptions;
@@ -45,6 +50,7 @@ import org.eclipse.qvtd.compiler.CompilerChain.Key;
import org.eclipse.qvtd.compiler.QVTrCompilerChain;
import org.eclipse.qvtd.compiler.internal.qvtp2qvts.QVTp2QVTs;
import org.eclipse.qvtd.pivot.qvtbase.Transformation;
+import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbase;
import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTransformation;
import org.eclipse.qvtd.pivot.qvtimperative.evaluation.BasicQVTiExecutor;
import org.eclipse.qvtd.pivot.qvtimperative.evaluation.QVTiEnvironmentFactory;
@@ -58,8 +64,10 @@ import org.eclipse.qvtd.xtext.qvtbase.tests.utilities.TestsXMLUtil;
import org.eclipse.qvtd.xtext.qvtcore.tests.QVTcTestUtil;
import org.eclipse.qvtd.xtext.qvtimperative.tests.ModelNormalizer;
import org.eclipse.qvtd.xtext.qvtimperative.tests.QVTiTestUtil;
+import org.eclipse.qvtd.xtext.qvtimperativecs.QVTimperativeCSPackage;
import org.eclipse.qvtd.xtext.qvtrelation.tests.forward2reverse.Forward2ReverseNormalizer;
import org.eclipse.qvtd.xtext.qvtrelation.tests.hstm2fstm.FlatStateMachineNormalizer;
+import org.eclipse.xtext.resource.XtextResource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -162,7 +170,14 @@ public class QVTrCompilerTests extends LoadTestCase
QVTrCompilerChain.setOption(options, CompilerChain.GENMODEL_STEP, CompilerChain.GENMODEL_OPTIONS_KEY, genModelOptions);
URI prefixURI = testFolderURI.appendSegment(testFileName);
compilerChain = new QVTrCompilerChain(getEnvironmentFactory(), prefixURI, options);
- return compilerChain.compile(outputName);
+ ImperativeTransformation transformation = compilerChain.compile(outputName);
+ URI txURI = transformation.eResource().getURI();
+ if (txURI != null) {
+ URI inputURI = txURI;
+ URI serializedURI = txURI.trimFileExtension().appendFileExtension("serialized.qvti");
+ doSerialize(inputURI, serializedURI);
+ }
+ return transformation;
}
public @NonNull Class<? extends Transformer> createGeneratedClass(@NonNull Transformation asTransformation, @NonNull String @NonNull... genModelFiles) throws Exception {
@@ -324,6 +339,78 @@ public class QVTrCompilerTests extends LoadTestCase
}
}
+ // FIXME move following clones to a Util class
+ protected static @NonNull XtextResource pivot2cs(@NonNull OCL ocl, @NonNull ResourceSet resourceSet, @NonNull ASResource asResource, @NonNull URI outputURI) throws IOException {
+ XtextResource xtextResource = ClassUtil.nonNullState((XtextResource) resourceSet.createResource(outputURI, QVTimperativeCSPackage.eCONTENT_TYPE));
+ ocl.as2cs(asResource, (CSResource) xtextResource);
+ assertNoResourceErrors("Conversion failed", xtextResource);
+ assertNoDiagnosticErrors("Concrete Syntax validation failed", xtextResource);
+ try {
+ xtextResource.save(TestsXMLUtil.defaultSavingOptions);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ URI xmiURI = outputURI.appendFileExtension(".xmi");
+ Resource xmiResource = resourceSet.createResource(xmiURI);
+ xmiResource.getContents().addAll(ClassUtil.nullFree(xtextResource.getContents()));
+ xmiResource.save(TestsXMLUtil.defaultSavingOptions);
+ fail(e.toString());
+ }
+ return xtextResource;
+ }
+
+ protected static XtextResource doSerialize(@NonNull URI inputURI, @NonNull URI serializedURI) throws IOException {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ //
+ // Load QVTiAS
+ //
+ OCL ocl = QVTbase.newInstance(OCL.NO_PROJECTS);
+ ocl.getEnvironmentFactory().setSeverity(PivotTables.STR_Variable_c_c_CompatibleInitialiserType, StatusCodes.Severity.IGNORE);
+ try {
+ ASResource asResource = loadQVTiAS(ocl, inputURI);
+ assertNoResourceErrors("Normalisation failed", asResource);
+ assertNoUnresolvedProxies("Normalisation invalid", asResource);
+ assertNoValidationErrors("Normalisation invalid", asResource);
+ //
+ // Pivot to CS
+ //
+ XtextResource xtextResource = pivot2cs(ocl, resourceSet, asResource, serializedURI);
+ resourceSet.getResources().clear();
+
+ QVTimperative qvti = QVTimperative.newInstance(ProjectManager.NO_PROJECTS, null);
+ try {
+ Resource asResource2 = QVTimperativeUtil.loadTransformation(qvti.getEnvironmentFactory(), serializedURI, false).eResource();
+ assertNoResourceErrors("Load failed", asResource2);
+ assertNoUnresolvedProxies("Load invalid", asResource2);
+ assertNoValidationErrors("Load invalid", asResource2);
+ }
+ finally {
+ qvti.dispose();
+ qvti = null;
+ }
+
+
+ return xtextResource;
+ }
+ finally {
+ ocl.dispose();
+ ocl = null;
+ }
+ }
+
+ protected static @NonNull ASResource loadQVTiAS(@NonNull OCL ocl, @NonNull URI inputURI) {
+ Resource asResource = ocl.getMetamodelManager().getASResourceSet().getResource(inputURI, true);
+ assert asResource != null;
+ // List<String> conversionErrors = new ArrayList<String>();
+ // RootPackageCS documentCS = Ecore2OCLinEcore.importFromEcore(resourceSet, null, ecoreResource);
+ // Resource eResource = documentCS.eResource();
+ assertNoResourceErrors("Load failed", asResource);
+ // Resource xtextResource = resourceSet.createResource(outputURI, OCLinEcoreCSTPackage.eCONTENT_TYPE);
+ // XtextResource xtextResource = (XtextResource) resourceSet.createResource(outputURI);
+ // xtextResource.getContents().add(documentCS);
+ return (ASResource) asResource;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.qvtd.xtext.qvtbase.tests.LoadTestCase#setUp()
*/

Back to the top