diff options
author | Ed Willink | 2015-11-08 17:23:53 +0000 |
---|---|---|
committer | Ed Willink | 2015-11-09 09:48:05 +0000 |
commit | bd2b5c973c22a3713d09e50b2d5e19d77525e573 (patch) | |
tree | 9f42132c115e1e172ba10cff890f91fb8f41ad27 | |
parent | 94a4dc8fc20361242935aa173ce3d075c4bf3023 (diff) | |
download | org.eclipse.ocl-ewillink/479445.tar.gz org.eclipse.ocl-ewillink/479445.tar.xz org.eclipse.ocl-ewillink/479445.zip |
[479445] WIP on Classic OCL Ecore2AS pluginewillink/479445
9 files changed, 417 insertions, 0 deletions
diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/.classpath b/plugins/org.eclipse.ocl.pivot.ecoreocl/.classpath new file mode 100644 index 0000000000..098194ca4b --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/.project b/plugins/org.eclipse.ocl.pivot.ecoreocl/.project new file mode 100644 index 0000000000..b56ff7d074 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ocl.pivot.ecoreocl</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.ocl.pivot.ecoreocl/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..f42de363af --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/META-INF/MANIFEST.MF b/plugins/org.eclipse.ocl.pivot.ecoreocl/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..b354744703 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/META-INF/MANIFEST.MF @@ -0,0 +1,11 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-SymbolicName: org.eclipse.ocl.pivot.ecoreocl;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Require-Bundle: org.eclipse.ocl.pivot;bundle-version="[1.1.0,2.0.0)", + org.eclipse.ocl.ecore;bundle-version="[3.5.0,4.0.0)" +Export-Package: org.eclipse.ocl.pivot.ecoreocl diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/about.html b/plugins/org.eclipse.ocl.pivot.ecoreocl/about.html new file mode 100644 index 0000000000..8d72b763f1 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/about.html @@ -0,0 +1,26 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"><head> + + +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>About</title> +</head><body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 25, 2011</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body></html>
\ No newline at end of file diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/build.properties b/plugins/org.eclipse.ocl.pivot.ecoreocl/build.properties new file mode 100644 index 0000000000..d197157fd0 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/build.properties @@ -0,0 +1,9 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html +additional.bundles = org.eclipse.ocl.jdt.annotation7 +src.includes = about.html diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/plugin.properties b/plugins/org.eclipse.ocl.pivot.ecoreocl/plugin.properties new file mode 100644 index 0000000000..3339ebcd33 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/plugin.properties @@ -0,0 +1,13 @@ +############################################################################### +# Copyright (c) 2015 Willink Transformations and others. +# 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: +# E.D.Willink - initial API and implementation +############################################################################### + +pluginName = OCL support for re-use of Classic OCL +providerName = Eclipse Modeling Project diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/plugin.xml b/plugins/org.eclipse.ocl.pivot.ecoreocl/plugin.xml new file mode 100644 index 0000000000..9318be5d6d --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/plugin.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension point="org.eclipse.ocl.pivot.ecore2as_helper"> + <metamodel class="org.eclipse.ocl.pivot.ecoreocl.EcoreOCL2ASHelper" + uri="http://www.eclipse.org/ocl/1.1.0/Ecore"/> + <model class="org.eclipse.ocl.pivot.ecoreocl.EcoreOCL2ASHelper" + uri="http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore"/> + </extension> + +</plugin> diff --git a/plugins/org.eclipse.ocl.pivot.ecoreocl/src/org/eclipse/ocl/pivot/ecoreocl/EcoreOCL2ASHelper.java b/plugins/org.eclipse.ocl.pivot.ecoreocl/src/org/eclipse/ocl/pivot/ecoreocl/EcoreOCL2ASHelper.java new file mode 100644 index 0000000000..b69170f6e5 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot.ecoreocl/src/org/eclipse/ocl/pivot/ecoreocl/EcoreOCL2ASHelper.java @@ -0,0 +1,305 @@ +/******************************************************************************* + * Copyright (c) 2015 Willink Transformations and others. + * 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: + * E.D.Willink - initial API and implementation + *******************************************************************************/ +package org.eclipse.ocl.pivot.ecoreocl; + +import java.util.List; + +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.ocl.pivot.AnyType; +import org.eclipse.ocl.pivot.BagType; +import org.eclipse.ocl.pivot.CollectionType; +import org.eclipse.ocl.pivot.InvalidType; +import org.eclipse.ocl.pivot.OrderedSetType; +import org.eclipse.ocl.pivot.PivotPackage; +import org.eclipse.ocl.pivot.PrimitiveType; +import org.eclipse.ocl.pivot.SequenceType; +import org.eclipse.ocl.pivot.SetType; +import org.eclipse.ocl.pivot.TupleType; +import org.eclipse.ocl.pivot.Type; +import org.eclipse.ocl.pivot.VoidType; +import org.eclipse.ocl.pivot.internal.ecore.es2as.AbstractEcore2ASHelper; +import org.eclipse.ocl.pivot.internal.ecore.es2as.AbstractExternal2AS; +import org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2ASDeclarationSwitch; +import org.eclipse.ocl.pivot.internal.ecore.es2as.Ecore2ASReferenceSwitch; + +public class EcoreOCL2ASHelper extends AbstractEcore2ASHelper +{ + private static @Nullable EcoreOCL2ASHelper METAMODEL_INSTANCE = null; + private static @Nullable EcoreOCL2ASHelper MODEL_INSTANCE = null; + + public static synchronized @NonNull EcoreOCL2ASHelper getMetamodelInstance() { + if (METAMODEL_INSTANCE == null) { + METAMODEL_INSTANCE = new EcoreOCL2ASHelper(org.eclipse.ocl.ecore.EcorePackage.eNS_URI, false); // Create our own singleton + METAMODEL_INSTANCE.install(); + } + assert METAMODEL_INSTANCE != null; + return METAMODEL_INSTANCE; + } + + public static synchronized @NonNull EcoreOCL2ASHelper getModelInstance() { + if (MODEL_INSTANCE == null) { + MODEL_INSTANCE = new EcoreOCL2ASHelper(org.eclipse.ocl.ecore.EcoreEnvironment.OCL_STANDARD_LIBRARY_NS_URI, true); // Create our own singleton + MODEL_INSTANCE.install(); + } + assert MODEL_INSTANCE != null; + return MODEL_INSTANCE; + } + + public static final class EcoreOCLEcore2ASDeclarationSwitch extends Ecore2ASDeclarationSwitch + { + public final class EcoreOCL2ASDeclarationSwitch extends org.eclipse.ocl.ecore.util.EcoreSwitch<Object> + { + @Override + public Object caseAnyType(org.eclipse.ocl.ecore.AnyType eObject) { + return refreshEcoreOCLClass(AnyType.class, PivotPackage.Literals.ANY_TYPE, eObject); + } + + @Override + public Object caseBagType(org.eclipse.ocl.ecore.BagType eObject) { + BagType pivotElement = refreshEcoreOCLClass(BagType.class, PivotPackage.Literals.BAG_TYPE, eObject); + queueReference(pivotElement); + return pivotElement; + } + + @Override + public Object caseCollectionType(org.eclipse.ocl.ecore.CollectionType eObject) { + CollectionType pivotElement = refreshEcoreOCLClass(CollectionType.class, PivotPackage.Literals.COLLECTION_TYPE, eObject); + queueReference(pivotElement); + return pivotElement; + } + + @Override + public Object caseInvalidType(org.eclipse.ocl.ecore.InvalidType eObject) { + return refreshEcoreOCLClass(InvalidType.class, PivotPackage.Literals.INVALID_TYPE, eObject); + } + + @Override + public Object caseOrderedSetType(org.eclipse.ocl.ecore.OrderedSetType eObject) { + OrderedSetType pivotElement = refreshEcoreOCLClass(OrderedSetType.class, PivotPackage.Literals.ORDERED_SET_TYPE, eObject); + queueReference(pivotElement); + return pivotElement; + } + + @Override + public Object casePrimitiveType(org.eclipse.ocl.ecore.PrimitiveType eObject) { + PrimitiveType pivotElement = converter.refreshElement(PrimitiveType.class, PivotPackage.Literals.PRIMITIVE_TYPE, eObject); + String oldName = pivotElement.getName(); + String newName = technology.getOriginalName(eObject); + boolean nameChange = (oldName != newName) || ((oldName != null) && !oldName.equals(newName)); + if (nameChange) { + org.eclipse.ocl.pivot.Package parentPackage = pivotElement.getOwningPackage(); + if (parentPackage != null) { + parentPackage.getOwnedClasses().remove(pivotElement); + } + } + pivotElement.setName(newName); + copyClassifier(pivotElement, eObject, null); + return pivotElement; + } + + @Override + public Object caseSequenceType(org.eclipse.ocl.ecore.SequenceType eObject) { + SequenceType pivotElement = refreshEcoreOCLClass(SequenceType.class, PivotPackage.Literals.SEQUENCE_TYPE, eObject); + queueReference(pivotElement); + return pivotElement; + } + + @Override + public Object caseSetType(org.eclipse.ocl.ecore.SetType eObject) { + SetType pivotElement = refreshEcoreOCLClass(SetType.class, PivotPackage.Literals.SET_TYPE, eObject); + queueReference(pivotElement); + return pivotElement; + } + + @Override + public Object caseTupleType(org.eclipse.ocl.ecore.TupleType eObject) { + TupleType pivotElement = converter.refreshElement(TupleType.class, PivotPackage.Literals.TUPLE_TYPE, eObject); + String oldName = pivotElement.getName(); + String newName = technology.getOriginalName(eObject); + boolean nameChange = (oldName != newName) || ((oldName != null) && !oldName.equals(newName)); + if (nameChange) { + org.eclipse.ocl.pivot.Package parentPackage = pivotElement.getOwningPackage(); + if (parentPackage != null) { + parentPackage.getOwnedClasses().remove(pivotElement); + } + } + pivotElement.setName(newName); + copyClassifier(pivotElement, eObject, null); + return pivotElement; + } + + @Override + public Object caseTypeType(org.eclipse.ocl.ecore.TypeType eObject) { + return refreshEcoreOCLClass(org.eclipse.ocl.pivot.Class.class, PivotPackage.Literals.CLASS, eObject); + } + + @Override + public Object caseVoidType(org.eclipse.ocl.ecore.VoidType eObject) { + return refreshEcoreOCLClass(VoidType.class, PivotPackage.Literals.VOID_TYPE, eObject); + } + } + + protected final @NonNull EcoreOCL2ASDeclarationSwitch oclSwitch; + + public EcoreOCLEcore2ASDeclarationSwitch(@NonNull AbstractExternal2AS converter) { + super(converter, new EcoreOCLEcore2ASReferenceSwitch(converter)); + oclSwitch = new EcoreOCL2ASDeclarationSwitch(); + } + + @Override + public Object caseEClass(EClass eObject) { + EAnnotation eAnnotation = eObject.getEAnnotation(org.eclipse.ocl.Environment.OCL_NAMESPACE_URI); + if (eAnnotation != null) { + List<EObject> references = eAnnotation.getReferences(); + if (references.size() == 1) { + EObject eShadowObject = references.get(0); + if (eShadowObject instanceof EClassifier) { + org.eclipse.ocl.pivot.Class pivotClass = refreshEcoreOCLClass(org.eclipse.ocl.pivot.Class.class, PivotPackage.Literals.CLASS, (EClassifier)eShadowObject); + doSwitchAll(pivotClass.getOwnedOperations(), eObject.getEOperations()); + doSwitchAll(pivotClass.getOwnedProperties(), eObject.getEStructuralFeatures()); + return this; + } + } + } + return super.caseEClass(eObject); + } + + public Object doSwitch(EObject eObject) { + Object result = oclSwitch.doSwitch(eObject); + if (result == null) { + result = super.doSwitch(eObject); + } + return result != this ? result : null; + } + + protected @NonNull <T extends org.eclipse.ocl.pivot.Class> T refreshEcoreOCLClass(@NonNull Class<T> pivotClass, /*@NonNull*/ EClass pivotEClass, @NonNull EClassifier eObject) { + T pivotElement = converter.refreshElement(pivotClass, pivotEClass, eObject); + copyClassifier(pivotElement, eObject, null); + String oldName = pivotElement.getName(); + String newName = eObject.getName(); + int index = newName.indexOf("("); + if (index > 0) { + newName = newName.substring(0, index); + } + boolean nameChange = (oldName != newName) || ((oldName != null) && !oldName.equals(newName)); + if (nameChange) { + org.eclipse.ocl.pivot.Package parentPackage = pivotElement.getOwningPackage(); + if (parentPackage != null) { + parentPackage.getOwnedClasses().remove(pivotElement); + } + } + pivotElement.setName(newName); +/* List<Operation> pivotOperations = pivotElement.getOwnedOperations(); + List<Constraint> pivotInvariants = pivotElement.getOwnedInvariants(); + for (@SuppressWarnings("null")@NonNull EOperation eOperation : eObject2.getEOperations()) { + if (converter.isInvariant(eOperation)) { + Object pivotObject = doSwitch(eOperation); + pivotInvariants.add((Constraint) pivotObject); + } + else { + Object pivotObject = doSwitch(eOperation); + pivotOperations.add((Operation) pivotObject); + } + } + List<Property> pivotProperties = pivotElement.getOwnedProperties(); + doSwitchAll(pivotProperties, eObject2.getEStructuralFeatures()); + if (duplicatesAnnotation != null) { + for (EObject eContent : duplicatesAnnotation.getContents()) { + if (eContent instanceof EOperation) { + if (converter.isInvariant((EOperation) eContent)) { + Constraint pivotInvariant = (Constraint) doSwitch(eContent); + pivotInvariants.add(pivotInvariant); + } + else { + Operation pivotOperation = (Operation) doSwitch(eContent); + pivotOperations.add(pivotOperation); + } + converter.queueReference(eContent); // For redefinition + } + else if (eContent instanceof EStructuralFeature) { + Property pivotProperty = (Property) doSwitch(eContent); + pivotProperties.add(pivotProperty); + converter.queueReference(eContent); // For redefinition + } + else if (eContent instanceof EAnnotation) { + } + else { + converter.error("Unsupported duplicate " + eContent.eClass().getName()); + } + } + } */ + queueReference(eObject); // For superclasses + return pivotElement; + } + } + + public static final class EcoreOCLEcore2ASReferenceSwitch extends Ecore2ASReferenceSwitch + { + public final class EcoreOCL2ASReferenceSwitch extends org.eclipse.ocl.ecore.util.EcoreSwitch<Object> + { + @Override + public Object caseCollectionType(org.eclipse.ocl.ecore.CollectionType eObject) { + CollectionType pivotCollection = converter.getCreated(CollectionType.class, eObject); + if (pivotCollection != null) { + Type pivotElement = converter.getCreated(Type.class, eObject.getElementType()); + pivotCollection.setElementType(pivotElement); + } + return this; + } + + @Override + public Object defaultCase(EObject object) { + // TODO Auto-generated method stub + return super.defaultCase(object); + } + } + + protected final @NonNull EcoreOCL2ASReferenceSwitch oclSwitch; + + public EcoreOCLEcore2ASReferenceSwitch(@NonNull AbstractExternal2AS converter) { + super(converter); + oclSwitch = new EcoreOCL2ASReferenceSwitch(); + } + + @Override + public Object caseEClass(EClass eObject) { + if (eObject.getEAnnotation(org.eclipse.ocl.Environment.OCL_NAMESPACE_URI) != null) { + // For shadow content + return this; + } + else { + return super.caseEClass(eObject); + } + } + + public Object doSwitch(EObject eObject) { + Object result = oclSwitch.doSwitch(eObject); + if (result == null) { + result = super.doSwitch(eObject); + } + return result != this ? result : null; + } + } + + public EcoreOCL2ASHelper(@NonNull String uri, boolean isModel) { + super(uri, isModel); + } + + @Override + public @NonNull Ecore2ASDeclarationSwitch createEcore2ASDeclarationSwitch(@NonNull AbstractExternal2AS converter) { + return new EcoreOCLEcore2ASDeclarationSwitch(converter); + } +} |