[249114] Inconsistent QVT Standard and java libraries AST modeling
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/models/blackboxlib_237781/blackboxlib_237781.qvto b/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/models/blackboxlib_237781/blackboxlib_237781.qvto
index 7af4ae4..adc611e 100644
--- a/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/models/blackboxlib_237781/blackboxlib_237781.qvto
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/models/blackboxlib_237781/blackboxlib_237781.qvto
@@ -9,4 +9,8 @@
var r := asRenamedSetSingleton(object EClass {}, name);
assert fatal (r->asSequence()->at(1).name = name)
with log('The java library operation did give expected result');
-}
\ No newline at end of file
+
+ var r2 : Set(OclAny) := 'selfString'.oclAnyMyOperation();
+ assert fatal (r2->asSequence()->at(1) = 'selfString')
+ with log('The java library operation ''oclAnyMyOperation'' did give expected result');
+}
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/sources/blackboxlibASTmodel/blackboxlibASTmodel.qvto b/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/sources/blackboxlibASTmodel/blackboxlibASTmodel.qvto
new file mode 100644
index 0000000..6e2c2a4
--- /dev/null
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/parserTestData/sources/blackboxlibASTmodel/blackboxlibASTmodel.qvto
@@ -0,0 +1,16 @@
+import library Strings;
+import library TestBlackboxLibrary;
+
+modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
+
+transformation blackboxlibASTmodel(inout model : ECORE);
+
+main() {
+ model.objects();
+
+ 'a::b::c'.split('::');
+
+ true.oclAnyMyOperation();
+
+ 'aString'.length(); -- oclstdlib operation
+}
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/ParserTests.java b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/ParserTests.java
index 00b1085..b57f38b 100644
--- a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/ParserTests.java
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/ParserTests.java
@@ -18,6 +18,8 @@
public static Test suite() {
TestSuite suite = new TestSuite("QVT parser"); //$NON-NLS-1$
+ suite.addTest(new QvtLibraryASTTest());
+
for (int i = 0; i < ourData.length; i++) {
TestData data = ourData[i];
suite.addTest(new TestQvtParser(data));
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/QvtLibraryASTTest.java b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/QvtLibraryASTTest.java
new file mode 100644
index 0000000..0172b32
--- /dev/null
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/QvtLibraryASTTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * 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:
+ * Borland Software Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2m.tests.qvt.oml;
+
+import java.io.File;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.m2m.internal.qvt.oml.ast.env.QvtOperationalStdLibrary;
+import org.eclipse.m2m.internal.qvt.oml.expressions.Library;
+import org.eclipse.m2m.internal.qvt.oml.expressions.ModuleImport;
+import org.eclipse.m2m.tests.qvt.oml.ParserTests.TestData;
+import org.eclipse.m2m.tests.qvt.oml.util.TestUtil;
+
+
+public class QvtLibraryASTTest extends TestQvtParser {
+
+ private static final String TEST_NAME = "blackboxlibASTmodel"; //$NON-NLS-N$
+
+ private static TestData createTestData() {
+ return new TestData(TEST_NAME, 0, 0);
+ }
+
+ public QvtLibraryASTTest(String testName) {
+ super(createTestData());
+ assertEquals(TEST_NAME, testName);
+ }
+
+ public QvtLibraryASTTest() {
+ super(createTestData()); //$NON-NLS-1$
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ public void runTest() throws Exception {
+ super.runTest();
+
+ checkLibrary((Library)QvtOperationalStdLibrary.INSTANCE.getLibaryModule());
+ EList<ModuleImport> moduleImports = getCompiledResults()[0].getModule().getModule().getModuleImport();
+ assertEquals(moduleImports.size(), 2);
+
+ for (ModuleImport nextImport : moduleImports) {
+ checkLibrary((Library)nextImport.getImportedModule());
+ }
+ }
+
+ private void checkLibrary(Library library) {
+ File libFile = new File(getDestinationFolder(), library.getName());
+ TestUtil.assertPersistableAST(QvtOperationalStdLibrary.INSTANCE.getLibaryModule(),
+ URI.createURI(libFile.toURI().toString(), true)); //$NON-NLS-1$
+
+ assertTrue("library file " + libFile + " must have been saved", libFile.exists()); //$NON-NLS-1$
+ }
+}
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestBlackboxLibrary.java b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestBlackboxLibrary.java
index faaf7d6..f2e2ad2 100644
--- a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestBlackboxLibrary.java
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestBlackboxLibrary.java
@@ -18,9 +18,9 @@
public class TestBlackboxLibrary {
- public Set<ENamedElement> asRenamedSetSingleton(Object arg, String newName) {
- if(arg instanceof ENamedElement) {
- ENamedElement namedElement = (ENamedElement) arg;
+ public Set<ENamedElement> asRenamedSetSingleton(Object self, String newName) {
+ if(self instanceof ENamedElement) {
+ ENamedElement namedElement = (ENamedElement) self;
namedElement.setName(newName);
return Collections.singleton(namedElement);
}
@@ -28,6 +28,11 @@
return Collections.emptySet();
}
+ public final Set<Object> oclAnyMyOperation(Object self) {
+ return Collections.singleton(self);
+ }
+
+
/**
* Metainfo for the native methods should be accessible throu the static
* methods of inner class <code>Metainfo</code> with the same signature
@@ -39,21 +44,26 @@
* array[n+1] - Return type classifier
*/
public static class Metainfo {
- /**
- * array[0] - Context classifier
- * array[n] - Classifier corresponds to the n-th operation parameter
- * array[n+1] - Return type classifier
- */
- private static final String[] RENAMED_SET_SINGLETON = new String[] {
+
+ private static final String[] RENAMED_SET_SINGLETON = new String[] {
"oclstdlib::OclVoid", // Void context -> module owned (context-less) operation
// imported library module is the implicit source object of the call
"oclstdlib::OclAny", // your argument1
"oclstdlib::String", // your argument2
"Set(ecore::ENamedElement)" // return type
};
-
+
+ private static final String[] OCLANY_MYOPERATION = new String[] {
+ "oclstdlib::OclAny",
+ "Set(oclstdlib::OclAny)"
+ };
+
public static final String[] asRenamedSetSingleton(Object arg, String newName) {
return RENAMED_SET_SINGLETON;
}
+
+ public static final String[] oclAnyMyOperation(Object arg) {
+ return OCLANY_MYOPERATION;
+ }
}
}
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestQvtParser.java b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestQvtParser.java
index 43f8cc0..ff9fbd3 100644
--- a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestQvtParser.java
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/TestQvtParser.java
@@ -57,10 +57,13 @@
public TestQvtParser(TestData data) {
super(data.getDir());
- myData = data;
-
+ myData = data;
}
-
+
+ protected QvtCompilationResult[] getCompiledResults() {
+ return myCompiled;
+ }
+
@Override
public void setUp() throws Exception {
TestUtil.turnOffAutoBuilding();
@@ -89,6 +92,7 @@
@Override
public void tearDown() throws Exception {
+ myCompiled = null;
}
public TestProject getTestProject() {
@@ -99,17 +103,17 @@
public void runTest() throws Exception {
copyData("sources/" + myData.getDir(), "parserTestData/sources/" + myData.getDir()); //$NON-NLS-1$ //$NON-NLS-2$
- File folder = new File(myProject.getProject().getLocation().toString() + "/sources/" + myData.getDir()); //$NON-NLS-1$
+ File folder = getDestinationFolder(); //$NON-NLS-1$
assertTrue("Invalid folder " + folder, folder.exists() && folder.isDirectory()); //$NON-NLS-1$
//System.err.println("testParsing: " + folder.getName()); //$NON-NLS-1$
- QvtCompilationResult[] compiled = compile(folder);
+ myCompiled = compile(folder);
- assertTrue("No results", compiled.length > 0); //$NON-NLS-1$
- List<QvtMessage> allErrors = getAllErrors(compiled);
+ assertTrue("No results", myCompiled.length > 0); //$NON-NLS-1$
+ List<QvtMessage> allErrors = getAllErrors(myCompiled);
assertEquals("Wrong error count for '" + folder.getName() + "', error(s)=" + allErrors, myData.getErrCount(), allErrors.size()); //$NON-NLS-1$ //$NON-NLS-2$
if (myData.getWarnings() != null) {
- List<QvtMessage> allWarnings = getAllWarnings(compiled);
+ List<QvtMessage> allWarnings = getAllWarnings(myCompiled);
expectedWarningsCycle : for (String expectedWarning : myData.getWarnings()) {
for (QvtMessage qvtMessage : allWarnings) {
if (expectedWarning.equals(qvtMessage.getMessage())) {
@@ -121,16 +125,16 @@
}
// check the AST is consistent
- for (QvtCompilationResult compilationResult : compiled) {
+ for (QvtCompilationResult compilationResult : myCompiled) {
if(compilationResult.getErrors().length == 0) {
TestUtil.assertAllPersistableAST(compilationResult.getModule());
}
- }
+ }
//
if(myData.usesSourceAnnotations()) {
Set<ProblemSourceAnnotationHelper> helpers = new HashSet<ProblemSourceAnnotationHelper>();
- for (QvtCompilationResult compilationResult : compiled) {
+ for (QvtCompilationResult compilationResult : myCompiled) {
doCompiledUnitCheck(compilationResult.getModule(), helpers);
}
@@ -145,6 +149,10 @@
}
}
}
+
+ protected File getDestinationFolder() {
+ return new File(myProject.getProject().getLocation().toString() + "/sources/" + myData.getDir());
+ }
private void doCompiledUnitCheck(CompiledModule module,Set<ProblemSourceAnnotationHelper> annotationCollector) {
ProblemSourceAnnotationHelper helper = ProblemSourceAnnotationHelper
@@ -248,4 +256,5 @@
private final TestData myData;
private TestProject myProject;
+ private QvtCompilationResult[] myCompiled;
}
diff --git a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/util/TestUtil.java b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/util/TestUtil.java
index 053a812..4a053a8 100644
--- a/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/util/TestUtil.java
+++ b/tests/org.eclipse.m2m.tests.qvt.oml/src/org/eclipse/m2m/tests/qvt/oml/util/TestUtil.java
@@ -13,6 +13,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
@@ -26,6 +27,7 @@
import java.util.Set;
import junit.framework.Assert;
+import junit.framework.TestCase;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -47,7 +49,6 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl;
-import org.eclipse.m2m.internal.qvt.oml.ast.parser.QvtOperationalParserUtil;
import org.eclipse.m2m.internal.qvt.oml.common.MdaException;
import org.eclipse.m2m.internal.qvt.oml.common.io.CFile;
import org.eclipse.m2m.internal.qvt.oml.common.io.FileUtil;
@@ -79,6 +80,24 @@
return result;
}
+ public static void assertPersistableAST(Module module, URI targetUri) {
+ OutputStream os = null;
+ try {
+ os = new ExtensibleURIConverterImpl().createOutputStream(targetUri);
+ module.eResource().save(os, Collections.emptyMap());
+ } catch (Exception e) {
+ TestCase.fail("Failed to serialize AST: " + e.getMessage()); //$NON-NLS-1$
+ } finally {
+ if(os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
public static void assertAllPersistableAST(CompiledModule compiledModule) {
Collection<CompiledModule> all = collectAllCompiledModules(compiledModule, new HashSet<CompiledModule>());
@@ -97,7 +116,7 @@
// FIXME -
EclipseFile source = (EclipseFile)module.getSource();
URI uri = URI.createURI(source.getFile().getLocationURI().toString()).appendFileExtension("xmi"); //$NON-NLS-1$
- Resource res = QvtOperationalParserUtil.getTypeResolverResource(module.getModule());
+ Resource res = module.getModule().eResource();
assertNotNull("A resource must be bound to AST Module: " + uri, res); //$NON-NLS-1$
res.getContents().add(module.getModule());
res.setURI(uri);