[unrelated] Load OCL Standard Library to match imported Pivot.ecore
diff --git a/examples/org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/ecore/Ecore2Pivot.java b/examples/org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/ecore/Ecore2Pivot.java
index ce948c7..78986e5 100644
--- a/examples/org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/ecore/Ecore2Pivot.java
+++ b/examples/org.eclipse.ocl.examples.pivot/src/org/eclipse/ocl/examples/pivot/ecore/Ecore2Pivot.java
@@ -50,6 +50,7 @@
import org.eclipse.ocl.examples.pivot.PivotPackage;
import org.eclipse.ocl.examples.pivot.Type;
import org.eclipse.ocl.examples.pivot.manager.MetaModelManager;
+import org.eclipse.ocl.examples.pivot.model.OCLstdlib;
import org.eclipse.ocl.examples.pivot.utilities.AbstractConversion;
import org.eclipse.ocl.examples.pivot.utilities.AliasAdapter;
import org.eclipse.ocl.examples.pivot.utilities.External2Pivot;
@@ -442,6 +443,9 @@
public Resource importObjects(Collection<EObject> ecoreContents, URI pivotURI) {
Resource pivotResource = metaModelManager.createResource(pivotURI, PivotPackage.eCONTENT_TYPE);
+ if (isPivot(ecoreContents)) {
+ metaModelManager.loadLibrary(new OCLstdlib(OCLstdlib.STDLIB_URI, "ocl", "ocl", ((EPackage)ecoreContents.iterator().next()).getNsURI()));
+ }
pivotRoot = metaModelManager.createPackage(pivotURI.lastSegment(), null);
pivotResource.getContents().add(pivotRoot);
List<org.eclipse.ocl.examples.pivot.Package> packages = pivotRoot.getNestedPackages();
@@ -483,6 +487,30 @@
return type == Ecore2Pivot.class;
}
+ protected boolean isPivot(Collection<EObject> ecoreContents) {
+ if (ecoreContents.size() != 1) {
+ return false;
+ }
+ EObject ecoreRoot = ecoreContents.iterator().next();
+ if (!(ecoreRoot instanceof EPackage)) {
+ return false;
+ }
+ EPackage ecorePackage = (EPackage) ecoreRoot;
+ if (ecorePackage.getEClassifier(PivotPackage.Literals.ENUMERATION_LITERAL.getName()) == null) {
+ return false;
+ }
+ if (ecorePackage.getEClassifier(PivotPackage.Literals.EXPRESSION_IN_OCL.getName()) == null) {
+ return false;
+ }
+ if (ecorePackage.getEClassifier(PivotPackage.Literals.OPERATION_CALL_EXP.getName()) == null) {
+ return false;
+ }
+ if (ecorePackage.getEClassifier(PivotPackage.Literals.TEMPLATE_PARAMETER_SUBSTITUTION.getName()) == null) {
+ return false;
+ }
+ return true;
+ }
+
public void metaModelManagerDisposed(MetaModelManager metaModelManager) {
dispose();
}
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java
index a5d8afd..ac67852 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/test/xtext/LoadTests.java
@@ -104,7 +104,9 @@
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " resolveProxies()");
assertNoUnresolvedProxies("Unresolved proxies", xtextResource);
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validate()");
- //FIXME assertNoValidationErrors("Validation errors", xtextResource.getContents().get(0));
+ if (xtextResource.getContents().size() > 0) {
+ assertNoValidationErrors("Validation errors", xtextResource.getContents().get(0));
+ }
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validated()");
xtextResource.setURI(output2URI);
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " save()");
@@ -128,6 +130,55 @@
return xmiResource;
}
+ public Resource doLoad_OCL(URI inputURI) throws IOException {
+// long startTime = System.currentTimeMillis();
+// System.out.println("Start at " + startTime);
+ ResourceSet resourceSet = new ResourceSetImpl();
+ getProjectMap().initializeResourceSet(resourceSet);
+ String extension = inputURI.fileExtension();
+ String stem = inputURI.trimFileExtension().lastSegment();
+ String outputName = stem + "." + extension + ".xmi";
+ String output2Name = stem + ".saved." + extension;
+ URI outputURI = getProjectFileURI(outputName);
+ URI output2URI = getProjectFileURI(output2Name);
+ if (metaModelManager == null) {
+ metaModelManager = new MetaModelManager();
+ }
+ MetaModelManagerResourceSetAdapter.getAdapter(resourceSet, metaModelManager);
+
+ Resource xtextResource = null;
+ try {
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " getResource()");
+ xtextResource = resourceSet.getResource(inputURI, true);
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " gotResource()");
+ assertNoResourceErrors("Load failed", xtextResource);
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " resolveProxies()");
+ assertNoUnresolvedProxies("Unresolved proxies", xtextResource);
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validate()");
+ assertNoValidationErrors("Validation errors", xtextResource.getContents().get(0));
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validated()");
+ xtextResource.setURI(output2URI);
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " save()");
+ // xtextResource.save(null); -- BUG 361649
+ // System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " saved()");
+ assertNoResourceErrors("Save failed", xtextResource);
+ }
+ finally {
+ if (xtextResource instanceof BaseCSResource) {
+ CS2PivotResourceAdapter adapter = CS2PivotResourceAdapter.getAdapter((BaseCSResource)xtextResource, null);
+ adapter.dispose();
+ }
+ metaModelManager.dispose();
+ }
+ Resource xmiResource = resourceSet.createResource(outputURI);
+ xmiResource.getContents().addAll(xtextResource.getContents());
+// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " save()");
+// xmiResource.save(null);
+// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " saved()");
+// assertNoResourceErrors("Save failed", xmiResource);
+ return xmiResource;
+ }
+
private static ProjectMap projectMap = null;
public static ProjectMap getProjectMap() {
if (projectMap == null) {
@@ -160,7 +211,7 @@
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " resolveProxies()");
assertNoUnresolvedProxies("Unresolved proxies", xtextResource);
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validate()");
- //FIXME assertNoValidationErrors("Validation errors", xtextResource.getContents().get(0));
+ assertNoValidationErrors("Validation errors", xtextResource.getContents().get(0));
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validated()");
xtextResource.setURI(output2URI);
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " save()");
@@ -245,7 +296,7 @@
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " resolveProxies()");
assertNoUnresolvedProxies("Unresolved proxies", pivotResource);
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validate()");
- //FIXME assertNoValidationErrors("Validation errors", xtextResource.getContents().get(0));
+ assertNoValidationErrors("Validation errors", pivotResource.getContents().get(0));
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " validated()");
// xtextResource.setURI(output2URI);
// System.out.println(Long.toString(System.currentTimeMillis() - startTime) + " save()");
@@ -451,6 +502,11 @@
doLoad("Names", "ocl");
}
+ public void testLoad_Pivot_ocl() throws IOException, InterruptedException {
+// Abstract2Moniker.TRACE_MONIKERS.setState(true);
+ doLoad_OCL(URI.createPlatformResourceURI("org.eclipse.ocl.examples.pivot/model/Pivot.ocl", true));
+ }
+
/* FIXME waiting for BUG 361649
public void testLoad_RoyalAndLoyal_ocl() throws IOException, InterruptedException {
// Abstract2Moniker.TRACE_MONIKERS.setState(true);