aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorghillairet2012-02-24 11:23:07 (EST)
committermgolubev2012-02-24 11:23:07 (EST)
commit4d43380ef62e9acf50d4f91eb22a91915d4a0ad5 (patch)
tree3090bd648df203790c12b267bc2fff82c3bbd66b
parentd7642267e9446e6f63bcf5279f760f875ac6b7aa (diff)
downloadorg.eclipse.gmf-tooling-4d43380ef62e9acf50d4f91eb22a91915d4a0ad5.zip
org.eclipse.gmf-tooling-4d43380ef62e9acf50d4f91eb22a91915d4a0ad5.tar.gz
org.eclipse.gmf-tooling-4d43380ef62e9acf50d4f91eb22a91915d4a0ad5.tar.bz2
Tests for bugs:
#369562 #369428 Signed-off-by: ghillairet <hillairet@montages.com>
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java2
-rw-r--r--plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java6
-rw-r--r--plugins/org.eclipse.gmf.bridge/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.gmf.bridge/build.properties3
-rw-r--r--plugins/org.eclipse.gmf.bridge/plugin.xml21
-rw-r--r--plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/QVTDiagramGenModelTransformer.java20
-rw-r--r--plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/VisualIdentifierDispenserFacade.java87
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto93
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto1
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto2
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto72
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/XpandFacadeAccess.java16
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java3
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerBasicRTTest.java42
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerSimpleTest.java340
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerTest.java389
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerVisualIDWithTraceTest.java165
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtLabelMappingTransformTest.java536
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtPaletteTransformationTest.java491
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareAbstractTest.java87
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareTestSupport.java357
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformModeledViewmapTest.java2
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/TransformToGenModelOperationTest.java22
23 files changed, 1546 insertions, 1213 deletions
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java
index b801fbd..cace222 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformOptions.java
@@ -193,7 +193,7 @@ public class TransformOptions extends AbstractPreferenceInitializer {
node.putBoolean(PREF_USE_RUNTIME_FIGURES, true);
node.putBoolean(PREF_IGNORE_MAPMODEL_VALIDATION, false);
node.putBoolean(PREF_IGNORE_GMFGEN_VALIDATION, false);
-
+ node.putBoolean(PREF_USE_IN_TRANSFORMATION_CODE_GEN, true);
}
static boolean checkLiteOptionPresent() {
diff --git a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java
index a905e3c..cd4d407 100644
--- a/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java
+++ b/plugins/org.eclipse.gmf.bridge.ui/src/org/eclipse/gmf/internal/bridge/transform/TransformToGenModelOperation.java
@@ -260,7 +260,7 @@ public class TransformToGenModelOperation {
idDispenser.acquire();
GenModelProducer t = createGenModelProducer(idDispenser);
-
+
monitor.subTask(Messages.TransformToGenModelOperation_task_generate);
GenEditorGenerator genEditor = t.process(getMapping(), new SubProgressMonitor(monitor, 20));
if (monitor.isCanceled()) {
@@ -396,8 +396,8 @@ public class TransformToGenModelOperation {
context.setConfigProperty("useFullRunTime", getOptions().getUseRuntimeFigures());
context.setConfigProperty("useInTransformationCodeGen", getOptions().getUseInTransformationCodeGen());
- final QVTDiagramGenModelTransformer transformer = new QVTDiagramGenModelTransformer(getResourceSet());
-
+ final QVTDiagramGenModelTransformer transformer = new QVTDiagramGenModelTransformer(getResourceSet(), idDespenser.get());
+
return new GenModelProducer() {
public GenEditorGenerator process(Mapping mapping, IProgressMonitor progress) throws CoreException {
progress.beginTask(null, 1);
diff --git a/plugins/org.eclipse.gmf.bridge/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmf.bridge/META-INF/MANIFEST.MF
index 2103d1c..976116f 100644
--- a/plugins/org.eclipse.gmf.bridge/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmf.bridge/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.gmf.bridge
+Bundle-SymbolicName: org.eclipse.gmf.bridge;singleton:=true
Bundle-Version: 1.1.100.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.gmf.bridge/build.properties b/plugins/org.eclipse.gmf.bridge/build.properties
index 48465e6..66eba4c 100644
--- a/plugins/org.eclipse.gmf.bridge/build.properties
+++ b/plugins/org.eclipse.gmf.bridge/build.properties
@@ -14,4 +14,5 @@ bin.includes = META-INF/,\
.,\
plugin.properties,\
about.html,\
- transforms/
+ transforms/,\
+ plugin.xml
diff --git a/plugins/org.eclipse.gmf.bridge/plugin.xml b/plugins/org.eclipse.gmf.bridge/plugin.xml
new file mode 100644
index 0000000..35f852b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/plugin.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.m2m.qvt.oml.javaBlackboxUnits">
+ <unit
+ name="VisualIdentifierDispenser"
+ namespace="gmf">
+ <library
+ class="org.eclipse.gmf.internal.bridge.genmodel.VisualIdentifierDispenserFacade">
+ </library>
+ </unit>
+ </extension>
+ <extension
+ point="org.eclipse.m2m.qvt.oml.runtime.qvtTransformation">
+ <library
+ file="transforms/Map2Gen.qvto"
+ id="transforms.Map2Gen">
+ </library>
+ </extension>
+</plugin>
diff --git a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/QVTDiagramGenModelTransformer.java b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/QVTDiagramGenModelTransformer.java
index d8510a8..f4d0d10 100644
--- a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/QVTDiagramGenModelTransformer.java
+++ b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/QVTDiagramGenModelTransformer.java
@@ -21,6 +21,7 @@ import org.eclipse.emf.ecore.EPackage.Registry;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.gmf.internal.bridge.VisualIdentifierDispenser;
import org.eclipse.gmf.mappings.Mapping;
import org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor;
import org.eclipse.m2m.internal.qvt.oml.trace.Trace;
@@ -40,8 +41,9 @@ public class QVTDiagramGenModelTransformer {
private final ResourceSet resourceSet;
private Registry registry;
- public QVTDiagramGenModelTransformer(ResourceSet resourceSet) {
+ public QVTDiagramGenModelTransformer(ResourceSet resourceSet, VisualIdentifierDispenser idDespenser) {
this.resourceSet = resourceSet;
+ VisualIdentifierDispenserFacade.Provider.setDispenser(idDespenser);
}
public ExecutionDiagnostic transform(final Mapping m, final GenModel genModel, final ModelExtent output, final ExecutionContext context) {
@@ -86,30 +88,18 @@ public class QVTDiagramGenModelTransformer {
if (outputGenModel == null) {
return result;
}
-// final QvtBridgeExtensionContentAdapter adapter = new QvtBridgeExtensionContentAdapter();
-// outputGenModel.eAdapters().add(adapter);
+
output = getModelExtent(outputGenModel);
for (URI extension: extensions) {
final InternalTransformationExecutor exec = registry == null ?
new InternalTransformationExecutor(extension) : new InternalTransformationExecutor(extension, registry);
exec.loadTransformation();
-
-// adapter.errors().clear();
+
if (1 == exec.getTransformation().getModelParameter().size()) {
result = exec.execute(context, output);
} else {
result = exec.execute(context, getModelExtent(m), getModelExtent(myTrace), output);
}
-
-// if (!adapter.errors().isEmpty()) {
-// result = new ExecutionDiagnosticImpl(
-// Diagnostic.ERROR,
-// 0,
-// "Extension transformation should not modify already set values",
-// adapter.errors().toArray()
-// );
-// return result;
-// }
}
return result;
diff --git a/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/VisualIdentifierDispenserFacade.java b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/VisualIdentifierDispenserFacade.java
new file mode 100644
index 0000000..d896632
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/src/org/eclipse/gmf/internal/bridge/genmodel/VisualIdentifierDispenserFacade.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+* Copyright (c) 2011, 2012 Montages A.G.
+* 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:
+* Guillaume Hillairet (Montages A.G.) : initial implementation
+*******************************************************************************/
+package org.eclipse.gmf.internal.bridge.genmodel;
+
+import org.eclipse.gmf.codegen.gmfgen.GenChildNode;
+import org.eclipse.gmf.codegen.gmfgen.GenCompartment;
+import org.eclipse.gmf.codegen.gmfgen.GenDiagram;
+import org.eclipse.gmf.codegen.gmfgen.GenLink;
+import org.eclipse.gmf.codegen.gmfgen.GenLinkLabel;
+import org.eclipse.gmf.codegen.gmfgen.GenNodeLabel;
+import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
+import org.eclipse.gmf.codegen.gmfgen.ToolGroup;
+import org.eclipse.gmf.internal.bridge.NaiveIdentifierDispenser;
+import org.eclipse.gmf.internal.bridge.VisualIdentifierDispenser;
+import org.eclipse.m2m.qvt.oml.blackbox.java.Operation;
+import org.eclipse.m2m.qvt.oml.blackbox.java.Operation.Kind;
+
+/**
+ * {@link VisualIdentifierDispenserFacade} is a QVTO black box providing access to
+ * a {@link VisualIdentifierDispenser}.
+ *
+ */
+public class VisualIdentifierDispenserFacade {
+
+ public VisualIdentifierDispenserFacade() {}
+
+ @Operation(contextual = true, kind = Kind.QUERY)
+ public int getVisualID(Object self) {
+ assert Provider.dispenser != null;
+
+ int visualID = -1;
+
+ if (self instanceof GenDiagram)
+ visualID = Provider.getDisenser().get((GenDiagram) self);
+
+ else if (self instanceof GenTopLevelNode)
+ visualID = Provider.getDisenser().get((GenTopLevelNode) self);
+
+ else if (self instanceof GenChildNode)
+ visualID = Provider.getDisenser().get((GenChildNode) self);
+
+ else if (self instanceof GenCompartment)
+ visualID = Provider.getDisenser().get((GenCompartment) self);
+
+ else if (self instanceof GenNodeLabel)
+ visualID = Provider.getDisenser().get((GenNodeLabel) self);
+
+ else if (self instanceof GenLink)
+ visualID = Provider.getDisenser().get((GenLink) self);
+
+ else if (self instanceof GenLinkLabel)
+ visualID = Provider.getDisenser().get((GenLinkLabel) self);
+
+ else if (self instanceof ToolGroup)
+ visualID = Provider.getDisenser().get((ToolGroup) self);
+
+ return visualID;
+ }
+
+ /**
+ * {@link Provider} is a singleton holding the current visual identifier dispenser.
+ */
+ public static final class Provider {
+
+ private static VisualIdentifierDispenser dispenser;
+
+ public static VisualIdentifierDispenser getDisenser() {
+ if (dispenser == null) {
+ dispenser = new NaiveIdentifierDispenser();
+ }
+ return dispenser;
+ }
+
+ public static void setDispenser(VisualIdentifierDispenser dispenser) {
+ Provider.dispenser = dispenser;
+ }
+
+ }
+}
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto
index 0f2ae2f..282379c 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2009 Borland Software Corporation
+ * Copyright (c) 2009 Borland Software Corporation & others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,28 +8,18 @@
*
* Contributors:
* Artem Tikhomirov (Borland) - initial API and implementation
+ * Guillaume Hillairet (Montages A.G.)
*/
import Map2GenMappings;
-
+import gmf.VisualIdentifierDispenser;
+
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefinition');
-modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
library Identity;
-- *************************************************************************************
--- Visual ID
--- *************************************************************************************
-
-property topNodeID: Integer = 2000;
-property childNodeID: Integer = 3000;
-property linkNodeID: Integer = 4000;
-property nodeLabelID: Integer = 5000;
-property linkLabelID: Integer = 6000;
-property compartmentID: Integer = 7000;
-
--- *************************************************************************************
-- Visual Identity
-- *************************************************************************************
@@ -42,8 +32,9 @@ helper GMFMAP::Mapping::visualIdentity() {
self.diagram.resolveone(GenDiagram).visualID := 1000;
self.nodes->collect(e |
- if e.resolveone(GenTopLevelNode).visualID = 0 then {
- e.resolveone(GenTopLevelNode).visualID := topNodeID();
+ if e.resolveone(GenTopLevelNode).visualID <= 0 then {
+ var genNode := e.resolveone(GenTopLevelNode);
+ genNode.visualID := genNode.getVisualID();
e.child.children->collect(visualIdentity());
e.child.labelMappings->collect(visualIdentity(e));
} endif
@@ -59,17 +50,18 @@ helper GMFMAP::Mapping::visualIdentity() {
helper GMFMAP::ChildReference::visualIdentity() {
var node := self.findProcessableChildReference();
if not node.oclIsUndefined() then
- if node.map structure(node.child).visualID = 0 then {
- if not node.referencedChild.oclIsUndefined() then
- node.map structure(node.child).visualID := childNodeID()
- else {
- node.map structure(node.child).visualID := childNodeID();
+ if node.map structure(node.child).visualID <= 0 then {
+ if not node.referencedChild.oclIsUndefined() then {
+ var genNode := node.map structure(node.child);
+ genNode.visualID := genNode.getVisualID();
+ } else {
+ var genNode := node.map structure(node.child);
+ genNode.visualID := genNode.getVisualID();
node.child.children->collect(e |
if e.needVisualID() then e.visualIdentity() endif
);
} endif;
node.map structure(node.child).labels->collect(e | visualIdentity(e));
- -- node.child.labelMappings->collect(visualIdentity(node));
} endif
endif
}
@@ -78,63 +70,40 @@ query ChildReference::needVisualID(): Boolean {
var node := self.findProcessableChildReference();
return
if node.oclIsUndefined() then false else
- node.map structure(node.child).visualID = 0
+ node.map structure(node.child).visualID <= 0
endif
}
helper visualIdentity(inout genNode: GMFGEN::GenNodeLabel) {
- if genNode.visualID = 0 then
- genNode.visualID := nodeLabelID()
- endif;
+ if genNode.visualID <= 0 then {
+ genNode.visualID := genNode.getVisualID();
+ } endif;
}
helper GMFMAP::LabelMapping::visualIdentity(node: GMFMAP::NodeReference) {
- if self.map createNodeLabel(node).visualID = 0 then
- self.map createNodeLabel(node).visualID := nodeLabelID()
- endif;
+ if self.map createNodeLabel(node).visualID <= 0 then {
+ var genNode := self.map createNodeLabel(node);
+ genNode.visualID := genNode.getVisualID();
+ } endif;
}
helper visualIdentity(inout label: GenLinkLabel) {
- if label.visualID = 0 then
- label.visualID := linkLabelID()
+ if label.visualID <= 0 then
+ label.visualID := label.getVisualID()
endif;
}
helper GMFMAP::LinkMapping::visualIdentity() {
- if self.map structure().visualID = 0 then {
- self.map structure().visualID := linkNodeID();
+ if self.map structure().visualID <= 0 then {
+ var genLink := self.map structure();
+ genLink.visualID := genLink.getVisualID();
self.map structure().labels->collect(e | visualIdentity(e))
} endif;
}
helper GMFMAP::CompartmentMapping::visualIdentity(_mapping: NodeMapping, node: NodeReference) {
- if self.map structure(_mapping, node).visualID = 0 then
- self.map structure(_mapping, node).visualID := compartmentID()
- endif
-}
-
-helper topNodeID(): Integer {
- var nodeID :=
- topNodeID := this.topNodeID + 1;
- return this.topNodeID;
-}
-helper childNodeID(): Integer {
- childNodeID := childNodeID + 1;
- return childNodeID;
-}
-helper nodeLabelID(): Integer {
- nodeLabelID := nodeLabelID + 1;
- return nodeLabelID;
-}
-helper linkNodeID(): Integer {
- linkNodeID := linkNodeID + 1;
- return linkNodeID;
-}
-helper compartmentID(): Integer {
- compartmentID := compartmentID + 1;
- return compartmentID;
-}
-helper linkLabelID(): Integer {
- linkLabelID := linkLabelID + 1;
- return linkLabelID;
+ if self.map structure(_mapping, node).visualID <= 0 then {
+ var genNode := self.map structure(_mapping, node);
+ genNode.visualID := genNode.getVisualID();
+ } endif
}
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto
index f92f7dc..04660b9 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto
@@ -43,6 +43,7 @@ main() {
mapRoot := mapModel.rootObjects()![GMFMAP::Mapping];
genModel := domainGenModel.rootObjects()![GENMODEL::GenModel];
childReferences := mapRoot.getChildReferences();
+ Viewmaps::setMapMode(useMapMode);
var genEditor := mapRoot.map structure();
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto
index 909de88..a438bbf 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto
@@ -10,7 +10,7 @@
* Artem Tikhomirov (Borland) - initial API and implementation
* Guillaume Hillairet (Montages A.G.)
*/
- import Map2GenUtil;
+import Map2GenUtil;
library Map2GenMappings;
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto
index 05ab8db..f58b2bd 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto
@@ -21,8 +21,6 @@ modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
library Viewmaps;
-property templateRoots : Sequence(String) = Sequence {'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/'};
-
helper viewmaps(in mapRoot : GMFMAP::Mapping, inout genDiagram : GMFGEN::GenDiagram) {
genDiagram.viewmap := mapRoot.diagram.diagramCanvas.map viewmap();
@@ -56,6 +54,7 @@ helper viewmaps(in mapRoot : GMFMAP::Mapping, inout genDiagram : GMFGEN::GenDiag
link.labels->forEach(label) {
var labelMapping := label.invresolveone(LabelMapping);
label.viewmap := labelMapping.diagramLabel.viewmap();
+ label.viewmap.attributes += labelMapping.diagramLabel.labelOffSetAttributes(link.labels->indexOf(label));
}
};
@@ -97,12 +96,6 @@ helper GMFGRAPH::Node::viewmap(): GMFGEN::Viewmap {
rs.layoutType := self.getLayoutType();
rs.attributes += if self.hasResizeConstraints() then self.map resizeConstraints() endif;
rs.attributes += if self.hasDefaultSize() then self.map defaultSize() endif;
-
--- } else {
--- rv := object GMFGEN::ModeledViewmap {
--- figureModel := self.oclAsType(EObject);
--- }
--- } endif;
return rs;
}
@@ -197,27 +190,29 @@ helper GMFGRAPH::DiagramLabel::viewmap(): GMFGEN::Viewmap {
rs := object GMFGEN::FigureViewmap {
figureQualifiedClassName := "org.eclipse.draw2d.Label"
}
- endif;
-
- if self.accessor.oclIsUndefined() then
- rs := self.figure.viewmap()
else
- -- for GenLinkLabel, need to specify alignment based on AlignmentFacet
- -- besides, need to create LabelOffsetAttributes and optionally populate it from LabelOffsetFacet
- rs := self.figure.viewmap(self.accessor)
+ if self.accessor.oclIsUndefined() then
+ rs := self.figure.viewmap()
+ else
+ -- for GenLinkLabel, need to specify alignment based on AlignmentFacet
+ -- besides, need to create LabelOffsetAttributes and optionally populate it from LabelOffsetFacet
+ rs := self.figure.viewmap(self.accessor)
+ endif
endif;
- rs.attributes += object LabelOffsetAttributes {
+ return rs;
+}
+
+helper DiagramLabel::labelOffSetAttributes(position: Integer): LabelOffsetAttributes {
+ return object LabelOffsetAttributes {
var offsetFacet := self.findOffsetFacet();
if not offsetFacet.oclIsUndefined() then {
x := offsetFacet.x;
y := offsetFacet.y;
} else {
- y := (self.findIndex() + 1) * 20;
+ y := (position + 1) * 20;
} endif;
};
-
- return rs;
}
-- =================================================================================================
@@ -229,11 +224,11 @@ helper GMFGRAPH::FigureDescriptor::viewmap() : GMFGEN::Viewmap {
if self.actualFigure.isBareInstance() then {
rs := object GMFGEN::FigureViewmap {
- figureQualifiedClassName := self.actualFigure.xpand('Runtime::fqn', templateRoots);
+ figureQualifiedClassName := self.actualFigure.xpand('Runtime::fqn', templates());
}
} else {
rs := object GMFGEN::InnerClassViewmap {
- classBody := self.xpand('top::Descriptor::Inner', templateRoots);
+ classBody := self.xpand('top::Descriptor::Inner', templates());
className := self.name.firstToUpper(); -- FIXME InnerClassViewmapProducer has validJavaIdentifier(capName())
};
} endif;
@@ -256,18 +251,13 @@ helper GMFGRAPH::Figure::createStyleAttributes() : GMFGEN::StyleAttributes {
return attributes;
}
-helper GMFGRAPH::FigureDescriptor::viewmap(childAccess : GMFGRAPH::ChildAccess) : GMFGEN::Viewmap {
- return
--- if useInTransformationCodeGen then
- object GMFGEN::ParentAssignedViewmap {
- getterName := childAccess.accessor;
- figureQualifiedClassName := childAccess.figure.xpand('Runtime::fqn', templateRoots);
- attributes := childAccess.figure.createStyleAttributes();
- }
--- else object GMFGEN::ModeledViewmap {
--- figureModel := self.oclAsType(EObject);
--- } endif;
-}
+helper GMFGRAPH::FigureDescriptor::viewmap(childAccess : GMFGRAPH::ChildAccess) : GMFGEN::Viewmap =
+ object GMFGEN::ParentAssignedViewmap {
+ getterName := childAccess.accessor;
+ figureQualifiedClassName := childAccess.figure.xpand('Runtime::fqn', templates());
+ attributes := childAccess.figure.createStyleAttributes();
+ };
+
query GMFGRAPH::Figure::isBareInstance() : Boolean { return false; }
query GMFGRAPH::RealFigure::isBareInstance() : Boolean {
if self.children->notEmpty() then return false endif;
@@ -319,4 +309,18 @@ query DiagramElement::findIndex(): Integer {
} endif;
return 0;
-} \ No newline at end of file
+}
+
+-- =================================================================================================
+-- Templates
+-- =================================================================================================
+property templateRoots : Sequence(String) = Sequence {'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/'};
+property mapModeTemplateRoots : String = 'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/rt_mm/';
+property useMapMode : Boolean = false;
+
+helper setMapMode(mapMode: Boolean) {
+ this.useMapMode := mapMode;
+ return;
+}
+query templates(): Sequence(String) =
+ if useMapMode then this.templateRoots->prepend(this.mapModeTemplateRoots) else this.templateRoots endif;
diff --git a/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/XpandFacadeAccess.java b/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/XpandFacadeAccess.java
index 9e119c7..ddb3b05 100644
--- a/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/XpandFacadeAccess.java
+++ b/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/XpandFacadeAccess.java
@@ -14,14 +14,17 @@ package org.eclipse.gmf.internal.codegen.util;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.gmf.internal.xpand.BufferOutput;
import org.eclipse.gmf.internal.xpand.XpandFacade;
import org.eclipse.gmf.internal.xpand.model.Scope;
+import org.eclipse.gmf.internal.xpand.model.Variable;
import org.eclipse.gmf.internal.xpand.util.BundleResourceManager;
import org.eclipse.m2m.qvt.oml.blackbox.java.Operation;
import org.eclipse.m2m.qvt.oml.blackbox.java.Operation.Kind;
@@ -29,12 +32,17 @@ import org.eclipse.m2m.qvt.oml.blackbox.java.Operation.Kind;
/**
* @author artem
*/
+@SuppressWarnings("restriction")
public class XpandFacadeAccess {
+ private static final String VAR_MM_ACCESS = "mapModeAccessor";
+ private static final String VAR_RT_TOKEN = "runtimeToken";
+
@Operation(contextual = true, kind = Kind.QUERY)
public String xpand(Object self, String templateName, List<String> templateRoots) {
StringBuilder result = new StringBuilder();
ArrayList<URL> urls = new ArrayList<URL>(templateRoots.size());
+
for (String s : templateRoots) {
try {
urls.add(new URL(s));
@@ -43,9 +51,15 @@ public class XpandFacadeAccess {
l.log(new Status(Status.ERROR, l.getBundle().getSymbolicName(), ex.getClass().getSimpleName(), ex));
}
}
+
+ final Collection<Variable> globals = new ArrayList<Variable>();
+
+ globals.add( new Variable(VAR_MM_ACCESS, EcorePackage.eINSTANCE.getEString(), ""));
+ globals.add(new Variable(VAR_RT_TOKEN, EcorePackage.eINSTANCE.getEString(), "full"));
+
BundleResourceManager rm = new BundleResourceManager(urls.toArray(new URL[urls.size()]));
try {
- new XpandFacade(new Scope(rm, null, new BufferOutput(result))).evaluate(templateName, self, null);
+ new XpandFacade(new Scope(rm, globals, new BufferOutput(result))).evaluate(templateName, self, null);
} catch (Exception ex) {
return ex.toString();
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
index 47971a8..7feae22 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/AllTests.java
@@ -80,6 +80,7 @@ import org.eclipse.gmf.tests.tr.PaletteTransformationTest;
import org.eclipse.gmf.tests.tr.PluginXMLTextMergerTest;
import org.eclipse.gmf.tests.tr.QvtGenModelTransformerBasicRTTest;
import org.eclipse.gmf.tests.tr.QvtGenModelTransformerSimpleTest;
+import org.eclipse.gmf.tests.tr.QvtGenModelTransformerVisualIDWithTraceTest;
import org.eclipse.gmf.tests.tr.QvtLabelMappingTransformTest;
import org.eclipse.gmf.tests.tr.QvtPaletteTransformationTest;
import org.eclipse.gmf.tests.tr.QvtTransformComparisonAudtisTest;
@@ -210,6 +211,7 @@ public class AllTests {
suite.addTestSuite(QvtTransformComparisonCompartmentRefNodeTest.class);
suite.addTestSuite(QvtTransformComparisonFullTest.class);
suite.addTestSuite(QvtTransformModeledViewmapTest.class);
+ suite.addTestSuite(QvtGenModelTransformerVisualIDWithTraceTest.class);
suite.addTestSuite(EcoreGenModelMatcherTest.class);
suite.addTestSuite(ModelLoadHelperTest.class);
@@ -307,6 +309,7 @@ public class AllTests {
c.register(QvtTransformComparisonCompartmentRefNodeTest.class, SessionSetup.class);
c.register(QvtTransformComparisonFullTest.class, SessionSetup.class);
c.register(QvtTransformModeledViewmapTest.class, SessionSetup.class);
+ c.register(QvtGenModelTransformerVisualIDWithTraceTest.class, SessionSetup.class);
// Default configuration, TestAllDerivedFeatures also runs for LinksSessionSetup
c.register(TestAllDerivedFeatures.class, SessionSetup.class);
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerBasicRTTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerBasicRTTest.java
index 25fc30d..33d76ca 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerBasicRTTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerBasicRTTest.java
@@ -1,21 +1,21 @@
-/*
- * Copyright (c) 2005, 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:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.tests.tr;
-
-import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
-
-public class QvtGenModelTransformerBasicRTTest extends QvtGenModelTransformerTest {
-
- public QvtGenModelTransformerBasicRTTest(String name) {
- super(name, new BasicDiagramRunTimeModelHelper());
- }
-}
+/*
+ * Copyright (c) 2005, 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.tr;
+
+import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
+
+public class QvtGenModelTransformerBasicRTTest extends QvtGenModelTransformerTest {
+
+ public QvtGenModelTransformerBasicRTTest(String name) {
+ super(name, new BasicDiagramRunTimeModelHelper());
+ }
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerSimpleTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerSimpleTest.java
index 65f4350..9e428aa 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerSimpleTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerSimpleTest.java
@@ -1,170 +1,170 @@
-/*
- * Copyright (c) 2006, 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:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.tests.tr;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.gmf.codegen.gmfgen.GenChildNode;
-import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
-import org.eclipse.gmf.codegen.gmfgen.GenNode;
-import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
-import org.eclipse.gmf.mappings.Mapping;
-import org.eclipse.gmf.tests.Utils;
-import org.eclipse.gmf.tests.setup.DiaDefSource;
-import org.eclipse.gmf.tests.setup.MapDefSource;
-import org.eclipse.gmf.tests.setup.MapDefWithReuseSetup;
-import org.eclipse.m2m.qvt.oml.BasicModelExtent;
-import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
-import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
-import org.eclipse.m2m.qvt.oml.ModelExtent;
-import org.eclipse.m2m.qvt.oml.TransformationExecutor;
-
-public class QvtGenModelTransformerSimpleTest extends AbstractMappingTransformerTest {
- private GenEditorGenerator transformationResult;
-
- public QvtGenModelTransformerSimpleTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- transformationResult = executeQVT();
- assertNotNull(transformationResult);
- }
-
- protected GenEditorGenerator executeQVT() throws IOException {
- GenModel genModel = Utils.createGenModel(getCanvasMapping().getDomainModel());
- Mapping mapping = getMapping();
-
- ResourceSet resourceSet = genModel.eResource().getResourceSet();
-
- TransformationExecutor executor = new TransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto"));
- ExecutionContextImpl context = new ExecutionContextImpl();
- context.setConfigProperty("rcp", false);
- context.setConfigProperty("useMapMode", false);
- context.setConfigProperty("useFullRunTime", false);
- context.setConfigProperty("useInTransformationCodeGen", true);
-
- EList<EObject> mapObjects = new BasicEList<EObject>();
- mapObjects.add(mapping);
- ModelExtent inMap = new BasicModelExtent(mapObjects);
- EList<EObject> genObjects = new BasicEList<EObject>();
- genObjects.add(genModel);
- ModelExtent inGen = new BasicModelExtent(genObjects);
- Resource res = resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel"));
- res.load(null);
- ModelExtent inNotation = new BasicModelExtent(res.getContents());
-
- ModelExtent output = new BasicModelExtent();
-
- ExecutionDiagnostic result = executor.execute(context, inMap, inGen, inNotation, output);
- if(result.getSeverity() == Diagnostic.OK) {
-
- List<EObject> outObjects = output.getContents();
- assertEquals(1, outObjects.size());
- assertTrue(outObjects.get(0) instanceof GenEditorGenerator);
-
- return (GenEditorGenerator) outObjects.get(0);
- }
-
- return null;
- }
-
- protected MapDefSource initMapModel(DiaDefSource graphDef) {
- return new MapDefWithReuseSetup().init(graphDef);
- }
-
- public void testNoReuseForTopLevelReference() {
- GenNode nodeA = getGenNodeA();
-
- final GenChildNode childA = nodeA.getChildNodes().get(0);
- // dumb check, although makes me believe DGMT set attributes
- // of the node that is actually a duplicate of top-level node
- assertEquals(nodeA.getDomainMetaClass(), childA.getDomainMetaClass());
- assertEquals(nodeA.getDiagramRunTimeClass(), childA.getDiagramRunTimeClass());
- assertTrue(childA.getChildNodes().contains(childA));
- }
-
- public void testReuseForChildReference() {
- GenNode nodeB = getGenNodeB();
-
- // B1 is child of Btop
- final GenChildNode bFirstLevelChild = nodeB.getChildNodes().get(0);
- final GenChildNode bSecondLevelChild = bFirstLevelChild.getChildNodes().get(0);
- assertFalse("B2 can't be the same as Btop", bFirstLevelChild == nodeB);
-// assertTrue("Actually, B2 should be the same as B1", bFirstLevelChild == bSecondLevelChild);
- assertTrue("B1 is child of B2 (and, of course, itself)", bSecondLevelChild.getChildNodes().contains(bFirstLevelChild));
- }
-
- public void testNoChildReferenceReuseWithDistinctContainments() {
- GenNode nodeB = getGenNodeB();
-
- final GenChildNode cFirstLevelChild = nodeB.getChildNodes().get(1); // note '1'
- final GenChildNode cSecondLevelChild = cFirstLevelChild.getChildNodes().get(0);
- assertFalse("C2 should not reuse C1 because of different containment", cSecondLevelChild.getChildNodes().contains(cFirstLevelChild));
- assertTrue("C2 IS a child of itself", cSecondLevelChild.getChildNodes().contains(cSecondLevelChild));
-
- }
-
- public void testNoChildReferenceReuseWithDistinctChildrenFeature() {
- GenNode nodeB = getGenNodeB();
-
- // this one has containment only
- final GenChildNode c1FirstLevelChild = nodeB.getChildNodes().get(1); // note '1'
- assertSame(c1FirstLevelChild.getModelFacet().getContainmentMetaFeature(), c1FirstLevelChild.getModelFacet().getChildMetaFeature());
-
- // this one has same containment, but different childrenMetaFeature
- final GenChildNode c2FirstLevelChild = nodeB.getChildNodes().get(2); // note '2'
- assertNotSame(c2FirstLevelChild.getModelFacet().getContainmentMetaFeature(), c2FirstLevelChild.getModelFacet().getChildMetaFeature());
- assertSame(c1FirstLevelChild.getModelFacet().getContainmentMetaFeature(), c2FirstLevelChild.getModelFacet().getContainmentMetaFeature());
-
- assertFalse("Just [in]sanity check", c1FirstLevelChild == c2FirstLevelChild);
- final GenChildNode c2SecondLevelChild = c2FirstLevelChild.getChildNodes().get(0);
- assertFalse("Although we referenced c1 mapping, childrenFeature was different, hence distinct child", c2FirstLevelChild.getChildNodes().contains(c1FirstLevelChild));
- assertTrue("... with its own cycle to itself", c2SecondLevelChild.getChildNodes().contains(c2SecondLevelChild));
- }
-
- private GenNode getGenNodeA() {
- GenNode rv = findTopNode(getNodeDomainElement(0));
- assertNotNull(rv);
- return rv;
- }
-
- private GenNode getGenNodeB() {
- GenNode rv = findTopNode(getNodeDomainElement(1));
- assertNotNull(rv);
- return rv;
- }
-
- private EClass getNodeDomainElement(int idx) {
- return (getMapping().getNodes().get(idx)).getOwnedChild().getDomainMetaElement();
- }
-
- private GenNode findTopNode(EClass eClass) {
- for (GenTopLevelNode next : transformationResult.getDiagram().getTopLevelNodes()) {
- if (next.getDomainMetaClass().getEcoreClass() == eClass) {
- return next;
- }
- }
- return null;
- }
-}
+/*
+ * Copyright (c) 2006, 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.tr;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.gmf.codegen.gmfgen.GenChildNode;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.gmf.codegen.gmfgen.GenNode;
+import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
+import org.eclipse.gmf.mappings.Mapping;
+import org.eclipse.gmf.tests.Utils;
+import org.eclipse.gmf.tests.setup.DiaDefSource;
+import org.eclipse.gmf.tests.setup.MapDefSource;
+import org.eclipse.gmf.tests.setup.MapDefWithReuseSetup;
+import org.eclipse.m2m.qvt.oml.BasicModelExtent;
+import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
+import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
+import org.eclipse.m2m.qvt.oml.ModelExtent;
+import org.eclipse.m2m.qvt.oml.TransformationExecutor;
+
+public class QvtGenModelTransformerSimpleTest extends AbstractMappingTransformerTest {
+ private GenEditorGenerator transformationResult;
+
+ public QvtGenModelTransformerSimpleTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ transformationResult = executeQVT();
+ assertNotNull(transformationResult);
+ }
+
+ protected GenEditorGenerator executeQVT() throws IOException {
+ GenModel genModel = Utils.createGenModel(getCanvasMapping().getDomainModel());
+ Mapping mapping = getMapping();
+
+ ResourceSet resourceSet = genModel.eResource().getResourceSet();
+
+ TransformationExecutor executor = new TransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto"));
+ ExecutionContextImpl context = new ExecutionContextImpl();
+ context.setConfigProperty("rcp", false);
+ context.setConfigProperty("useMapMode", false);
+ context.setConfigProperty("useFullRunTime", false);
+ context.setConfigProperty("useInTransformationCodeGen", true);
+
+ EList<EObject> mapObjects = new BasicEList<EObject>();
+ mapObjects.add(mapping);
+ ModelExtent inMap = new BasicModelExtent(mapObjects);
+ EList<EObject> genObjects = new BasicEList<EObject>();
+ genObjects.add(genModel);
+ ModelExtent inGen = new BasicModelExtent(genObjects);
+ Resource res = resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel"));
+ res.load(null);
+ ModelExtent inNotation = new BasicModelExtent(res.getContents());
+
+ ModelExtent output = new BasicModelExtent();
+
+ ExecutionDiagnostic result = executor.execute(context, inMap, inGen, inNotation, output);
+ if(result.getSeverity() == Diagnostic.OK) {
+
+ List<EObject> outObjects = output.getContents();
+ assertEquals(1, outObjects.size());
+ assertTrue(outObjects.get(0) instanceof GenEditorGenerator);
+
+ return (GenEditorGenerator) outObjects.get(0);
+ }
+
+ return null;
+ }
+
+ protected MapDefSource initMapModel(DiaDefSource graphDef) {
+ return new MapDefWithReuseSetup().init(graphDef);
+ }
+
+ public void testNoReuseForTopLevelReference() {
+ GenNode nodeA = getGenNodeA();
+
+ final GenChildNode childA = nodeA.getChildNodes().get(0);
+ // dumb check, although makes me believe DGMT set attributes
+ // of the node that is actually a duplicate of top-level node
+ assertEquals(nodeA.getDomainMetaClass(), childA.getDomainMetaClass());
+ assertEquals(nodeA.getDiagramRunTimeClass(), childA.getDiagramRunTimeClass());
+ assertTrue(childA.getChildNodes().contains(childA));
+ }
+
+ public void testReuseForChildReference() {
+ GenNode nodeB = getGenNodeB();
+
+ // B1 is child of Btop
+ final GenChildNode bFirstLevelChild = nodeB.getChildNodes().get(0);
+ final GenChildNode bSecondLevelChild = bFirstLevelChild.getChildNodes().get(0);
+ assertFalse("B2 can't be the same as Btop", bFirstLevelChild == nodeB);
+// assertTrue("Actually, B2 should be the same as B1", bFirstLevelChild == bSecondLevelChild);
+ assertTrue("B1 is child of B2 (and, of course, itself)", bSecondLevelChild.getChildNodes().contains(bFirstLevelChild));
+ }
+
+ public void testNoChildReferenceReuseWithDistinctContainments() {
+ GenNode nodeB = getGenNodeB();
+
+ final GenChildNode cFirstLevelChild = nodeB.getChildNodes().get(1); // note '1'
+ final GenChildNode cSecondLevelChild = cFirstLevelChild.getChildNodes().get(0);
+ assertFalse("C2 should not reuse C1 because of different containment", cSecondLevelChild.getChildNodes().contains(cFirstLevelChild));
+ assertTrue("C2 IS a child of itself", cSecondLevelChild.getChildNodes().contains(cSecondLevelChild));
+
+ }
+
+ public void testNoChildReferenceReuseWithDistinctChildrenFeature() {
+ GenNode nodeB = getGenNodeB();
+
+ // this one has containment only
+ final GenChildNode c1FirstLevelChild = nodeB.getChildNodes().get(1); // note '1'
+ assertSame(c1FirstLevelChild.getModelFacet().getContainmentMetaFeature(), c1FirstLevelChild.getModelFacet().getChildMetaFeature());
+
+ // this one has same containment, but different childrenMetaFeature
+ final GenChildNode c2FirstLevelChild = nodeB.getChildNodes().get(2); // note '2'
+ assertNotSame(c2FirstLevelChild.getModelFacet().getContainmentMetaFeature(), c2FirstLevelChild.getModelFacet().getChildMetaFeature());
+ assertSame(c1FirstLevelChild.getModelFacet().getContainmentMetaFeature(), c2FirstLevelChild.getModelFacet().getContainmentMetaFeature());
+
+ assertFalse("Just [in]sanity check", c1FirstLevelChild == c2FirstLevelChild);
+ final GenChildNode c2SecondLevelChild = c2FirstLevelChild.getChildNodes().get(0);
+ assertFalse("Although we referenced c1 mapping, childrenFeature was different, hence distinct child", c2FirstLevelChild.getChildNodes().contains(c1FirstLevelChild));
+ assertTrue("... with its own cycle to itself", c2SecondLevelChild.getChildNodes().contains(c2SecondLevelChild));
+ }
+
+ private GenNode getGenNodeA() {
+ GenNode rv = findTopNode(getNodeDomainElement(0));
+ assertNotNull(rv);
+ return rv;
+ }
+
+ private GenNode getGenNodeB() {
+ GenNode rv = findTopNode(getNodeDomainElement(1));
+ assertNotNull(rv);
+ return rv;
+ }
+
+ private EClass getNodeDomainElement(int idx) {
+ return (getMapping().getNodes().get(idx)).getOwnedChild().getDomainMetaElement();
+ }
+
+ private GenNode findTopNode(EClass eClass) {
+ for (GenTopLevelNode next : transformationResult.getDiagram().getTopLevelNodes()) {
+ if (next.getDomainMetaClass().getEcoreClass() == eClass) {
+ return next;
+ }
+ }
+ return null;
+ }
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerTest.java
index 665607f..1a4231c 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerTest.java
@@ -1,194 +1,195 @@
-/*
- * Copyright (c) 2005, 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:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.tests.tr;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.gmf.codegen.gmfgen.GenCommonBase;
-import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
-import org.eclipse.gmf.codegen.gmfgen.GenLink;
-import org.eclipse.gmf.codegen.gmfgen.GenNode;
-import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
-import org.eclipse.gmf.codegen.gmfgen.Palette;
-import org.eclipse.gmf.codegen.gmfgen.ToolEntry;
-import org.eclipse.gmf.codegen.gmfgen.ToolGroup;
-import org.eclipse.gmf.codegen.gmfgen.ToolGroupItem;
-import org.eclipse.gmf.internal.bridge.genmodel.DiagramRunTimeModelHelper;
-import org.eclipse.gmf.mappings.GMFMapPackage;
-import org.eclipse.gmf.mappings.LinkMapping;
-import org.eclipse.gmf.mappings.Mapping;
-import org.eclipse.gmf.mappings.NodeMapping;
-import org.eclipse.gmf.mappings.TopNodeReference;
-import org.eclipse.gmf.tests.Utils;
-import org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor;
-import org.eclipse.m2m.internal.qvt.oml.trace.Trace;
-import org.eclipse.m2m.internal.qvt.oml.trace.TraceRecord;
-import org.eclipse.m2m.qvt.oml.BasicModelExtent;
-import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
-import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
-import org.eclipse.m2m.qvt.oml.ModelExtent;
-
-@SuppressWarnings("restriction")
-public abstract class QvtGenModelTransformerTest extends AbstractMappingTransformerTest {
-
- protected GenEditorGenerator myTransformationResult;
-// private final DiagramRunTimeModelHelper myDiagramModelHelper;
- protected Resource traceResource;
-
- protected QvtGenModelTransformerTest(String name, DiagramRunTimeModelHelper rtHelper) {
- super(name);
- assert rtHelper != null;
-// myDiagramModelHelper = rtHelper;
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- myTransformationResult = executeQVT();
- }
-
- protected GenEditorGenerator executeQVT() throws IOException {
- GenModel genModel = Utils.createGenModel(getCanvasMapping().getDomainModel());
- Mapping mapping = getMapping();
-
- ResourceSet resourceSet = genModel.eResource().getResourceSet();
- traceResource = resourceSet.createResource(URI.createURI("test.qvtotrace"));
- InternalTransformationExecutor executor = //new TransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto"));
- new InternalTransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto")) {
- @Override
- protected void handleExecutionTraces(Trace traces) {
- traceResource.getContents().add(traces);
- super.handleExecutionTraces(traces);
- }
- };
- ExecutionContextImpl context = new ExecutionContextImpl();
- context.setConfigProperty("rcp", false);
- context.setConfigProperty("useMapMode", false);
- context.setConfigProperty("useFullRunTime", false);
- context.setConfigProperty("useInTransformationCodeGen", true);
-
- EList<EObject> mapObjects = new BasicEList<EObject>();
- mapObjects.add(mapping);
- ModelExtent inMap = new BasicModelExtent(mapObjects);
- EList<EObject> genObjects = new BasicEList<EObject>();
- genObjects.add(genModel);
- ModelExtent inGen = new BasicModelExtent(genObjects);
- Resource res = resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel"));
- res.load(null);
- ModelExtent inNotation = new BasicModelExtent(res.getContents());
-
- ModelExtent output = new BasicModelExtent();
-
- ExecutionDiagnostic result = executor.execute(context, inMap, inGen, inNotation, output);
-
- if(result.getSeverity() == Diagnostic.OK) {
-
- List<EObject> outObjects = output.getContents();
- assertTrue(outObjects.get(0) instanceof GenEditorGenerator);
-
- return (GenEditorGenerator) outObjects.get(0);
- }
-
- return null;
- }
-
- protected GenNode[] find(NodeMapping nodeMap) {
- assert nodeMap != null;
- GenNode genNode = findTopNode(nodeMap);
- return genNode != null ? new GenNode[] {genNode} : new GenNode[]{};//findChildNodes(nodeMap);
- }
-
- protected GenTopLevelNode findTopNode(NodeMapping nodeMap) {
- assert nodeMap != null;
- Trace trace = (Trace) traceResource.getContents().get(0);
- for (TraceRecord record: trace.getTraceRecords()) {
- if (record.getContext().getContext().getType().equals(GMFMapPackage.eINSTANCE.getTopNodeReference().getName())) {
- if (record.getContext().getContext().getValue().getModelElement().equals(nodeMap.eContainer())) {
- return (GenTopLevelNode) record.getResult().getResult().get(0).getValue().getModelElement();
- }
- }
- }
- return null;
- }
-
- private GenLink find(LinkMapping linkMapping) {
- assert linkMapping != null;
- Trace trace = (Trace) traceResource.getContents().get(0);
- for (TraceRecord record: trace.getTraceRecords()) {
- if (record.getContext().getContext().getType().equals(GMFMapPackage.eINSTANCE.getLinkMapping().getName())) {
- if (record.getContext().getContext().getValue().getModelElement().equals(linkMapping)) {
- return (GenLink) record.getResult().getResult().get(0).getValue().getModelElement();
- }
- }
- }
- return null;
- }
-
- public void testGenModelTransform() {
- assertNotNull("GenEditorGenerator is expected as result of mapping transformation", myTransformationResult);
- assertNotNull("GenDiagram is expected to be set...", myTransformationResult.getDiagram());
- assertNotNull("... as well as GenPlugin is expected to be set", myTransformationResult.getPlugin());
- assertNotNull("Diagram filename extension not set", myTransformationResult.getDiagramFileExtension());
- // FIXME add more
-
- GenNode[] genNodes = find(getNodeMapping());
- assertEquals("Result model contains no GenNode for nodeMapping", 1, genNodes.length);
- // FIXME add more
-
- GenLink genLinks = find(getLinkMapping());
- assertNotNull("Result model contains no GenLink for linkMapping", genLinks);
- // FIXME add more
- }
-
- public void testCreatedPalette() {
- final Palette palette = myTransformationResult.getDiagram().getPalette();
- for (TopNodeReference topNode : getMapping().getNodes()) {
- final NodeMapping nodeMapping = topNode.getChild();
- GenTopLevelNode genNode = findTopNode(nodeMapping);
- assertNotNull(genNode);
- assertEquals(nodeMapping.getTool() != null ? 1 : 0, countUses(genNode, palette));
- }
- for (LinkMapping linkMapping : getMapping().getLinks()) {
- GenLink genLink = find(linkMapping);
- assertNotNull(genLink);
- assertEquals(linkMapping.getTool() != null ? 1 : 0, countUses(genLink, palette));
- }
- // TODO add grooping test
- }
-
- private static int countUses(GenCommonBase genElement, Palette palette) {
- int uses = 0;
- for (ToolGroup nextGroup : palette.getGroups()) {
- for (ToolGroupItem item : nextGroup.getEntries()) {
- if (false == item instanceof ToolEntry) {
- continue;
- }
- for (GenCommonBase cb : ((ToolEntry) item).getElements()) {
- if (cb == genElement) {
- uses++;
- // although it's hardly there's more that one GenCommonBase in EMF EList for ToolEntry#elements, doesn't hurt
- // *not to* break here
- }
- }
- }
- }
- return uses;
- }
-}
+/*
+ * Copyright (c) 2005, 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.tr;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.gmf.codegen.gmfgen.GenCommonBase;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.gmf.codegen.gmfgen.GenLink;
+import org.eclipse.gmf.codegen.gmfgen.GenNode;
+import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
+import org.eclipse.gmf.codegen.gmfgen.Palette;
+import org.eclipse.gmf.codegen.gmfgen.ToolEntry;
+import org.eclipse.gmf.codegen.gmfgen.ToolGroup;
+import org.eclipse.gmf.codegen.gmfgen.ToolGroupItem;
+import org.eclipse.gmf.internal.bridge.genmodel.DiagramRunTimeModelHelper;
+import org.eclipse.gmf.mappings.GMFMapPackage;
+import org.eclipse.gmf.mappings.LinkMapping;
+import org.eclipse.gmf.mappings.Mapping;
+import org.eclipse.gmf.mappings.NodeMapping;
+import org.eclipse.gmf.mappings.TopNodeReference;
+import org.eclipse.gmf.tests.Utils;
+import org.eclipse.m2m.internal.qvt.oml.InternalTransformationExecutor;
+import org.eclipse.m2m.internal.qvt.oml.trace.Trace;
+import org.eclipse.m2m.internal.qvt.oml.trace.TraceRecord;
+import org.eclipse.m2m.qvt.oml.BasicModelExtent;
+import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
+import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
+import org.eclipse.m2m.qvt.oml.ModelExtent;
+
+@SuppressWarnings("restriction")
+public abstract class QvtGenModelTransformerTest extends AbstractMappingTransformerTest {
+
+ protected GenEditorGenerator myTransformationResult;
+// private final DiagramRunTimeModelHelper myDiagramModelHelper;
+ protected Resource traceResource;
+
+ protected QvtGenModelTransformerTest(String name, DiagramRunTimeModelHelper rtHelper) {
+ super(name);
+ assert rtHelper != null;
+// myDiagramModelHelper = rtHelper;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ myTransformationResult = executeQVT();
+ }
+
+ protected GenEditorGenerator executeQVT() throws IOException {
+ GenModel genModel = Utils.createGenModel(getCanvasMapping().getDomainModel());
+ Mapping mapping = getMapping();
+
+ ResourceSet resourceSet = genModel.eResource().getResourceSet();
+ traceResource = resourceSet.createResource(URI.createURI("test.qvtotrace"));
+ InternalTransformationExecutor executor = //new TransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto"));
+ new InternalTransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto")) {
+ @Override
+ protected void handleExecutionTraces(Trace traces) {
+ traceResource.getContents().add(traces);
+ super.handleExecutionTraces(traces);
+ }
+ };
+ ExecutionContextImpl context = new ExecutionContextImpl();
+ context.setConfigProperty("rcp", false);
+ context.setConfigProperty("useMapMode", false);
+ context.setConfigProperty("useFullRunTime", false);
+ context.setConfigProperty("useInTransformationCodeGen", true);
+
+ EList<EObject> mapObjects = new BasicEList<EObject>();
+ mapObjects.add(mapping);
+ ModelExtent inMap = new BasicModelExtent(mapObjects);
+ EList<EObject> genObjects = new BasicEList<EObject>();
+ genObjects.add(genModel);
+ ModelExtent inGen = new BasicModelExtent(genObjects);
+ Resource res = resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel"));
+ res.load(null);
+ ModelExtent inNotation = new BasicModelExtent(res.getContents());
+
+ ModelExtent output = new BasicModelExtent();
+
+ ExecutionDiagnostic result = executor.execute(context, inMap, inGen, inNotation, output);
+
+ if(result.getSeverity() == Diagnostic.OK) {
+
+ List<EObject> outObjects = output.getContents();
+ assertTrue(outObjects.get(0) instanceof GenEditorGenerator);
+
+ return (GenEditorGenerator) outObjects.get(0);
+ }
+
+ return null;
+ }
+
+ protected GenNode[] find(NodeMapping nodeMap) {
+ assert nodeMap != null;
+ GenNode genNode = findTopNode(nodeMap);
+ return genNode != null ? new GenNode[] {genNode} : new GenNode[]{};//findChildNodes(nodeMap);
+ }
+
+ protected GenTopLevelNode findTopNode(NodeMapping nodeMap) {
+ assert nodeMap != null;
+ Trace trace = (Trace) traceResource.getContents().get(0);
+ for (TraceRecord record: trace.getTraceRecords()) {
+ if (record.getContext().getContext().getType().equals(GMFMapPackage.eINSTANCE.getTopNodeReference().getName())) {
+ if (record.getContext().getContext().getValue().getModelElement().equals(nodeMap.eContainer())) {
+ return (GenTopLevelNode) record.getResult().getResult().get(0).getValue().getModelElement();
+ }
+ }
+ }
+ return null;
+ }
+
+ private GenLink find(LinkMapping linkMapping) {
+ assert linkMapping != null;
+ Trace trace = (Trace) traceResource.getContents().get(0);
+ for (TraceRecord record: trace.getTraceRecords()) {
+ if (record.getContext().getContext().getType().equals(GMFMapPackage.eINSTANCE.getLinkMapping().getName())) {
+ if (record.getContext().getContext().getValue().getModelElement().equals(linkMapping)) {
+ return (GenLink) record.getResult().getResult().get(0).getValue().getModelElement();
+ }
+ }
+ }
+ return null;
+ }
+
+ public void testGenModelTransform() {
+ assertNotNull("GenEditorGenerator is expected as result of mapping transformation", myTransformationResult);
+ assertNotNull("GenDiagram is expected to be set...", myTransformationResult.getDiagram());
+ assertNotNull("... as well as GenPlugin is expected to be set", myTransformationResult.getPlugin());
+ assertNotNull("Diagram filename extension not set", myTransformationResult.getDiagramFileExtension());
+ // FIXME add more
+
+ GenNode[] genNodes = find(getNodeMapping());
+ assertEquals("Result model contains no GenNode for nodeMapping", 1, genNodes.length);
+ // FIXME add more
+
+ GenLink genLinks = find(getLinkMapping());
+ assertNotNull("Result model contains no GenLink for linkMapping", genLinks);
+ // FIXME add more
+ }
+
+ public void testCreatedPalette() {
+ final Palette palette = myTransformationResult.getDiagram().getPalette();
+ for (TopNodeReference topNode : getMapping().getNodes()) {
+ final NodeMapping nodeMapping = topNode.getChild();
+ GenTopLevelNode genNode = findTopNode(nodeMapping);
+ assertNotNull(genNode);
+ assertEquals(nodeMapping.getTool() != null ? 1 : 0, countUses(genNode, palette));
+ }
+ for (LinkMapping linkMapping : getMapping().getLinks()) {
+ GenLink genLink = find(linkMapping);
+ assertNotNull(genLink);
+ assertEquals(linkMapping.getTool() != null ? 1 : 0, countUses(genLink, palette));
+ }
+ // TODO add grooping test
+ }
+
+ private static int countUses(GenCommonBase genElement, Palette palette) {
+ int uses = 0;
+ for (ToolGroup nextGroup : palette.getGroups()) {
+ for (ToolGroupItem item : nextGroup.getEntries()) {
+ if (false == item instanceof ToolEntry) {
+ continue;
+ }
+ for (GenCommonBase cb : ((ToolEntry) item).getElements()) {
+ if (cb == genElement) {
+ uses++;
+ // although it's hardly there's more that one GenCommonBase in EMF EList for ToolEntry#elements, doesn't hurt
+ // *not to* break here
+ }
+ }
+ }
+ }
+ return uses;
+ }
+}
+
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerVisualIDWithTraceTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerVisualIDWithTraceTest.java
new file mode 100644
index 0000000..103dcc3
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtGenModelTransformerVisualIDWithTraceTest.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+* Copyright (c) 2011, 2012 Montages A.G.
+* 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:
+* Guillaume Hillairet (Montages A.G.) : initial implementation
+*******************************************************************************/
+package org.eclipse.gmf.tests.tr;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
+import org.eclipse.gmf.mappings.CanvasMapping;
+import org.eclipse.gmf.mappings.GMFMapFactory;
+import org.eclipse.gmf.mappings.Mapping;
+import org.eclipse.gmf.mappings.NodeMapping;
+import org.eclipse.gmf.mappings.TopNodeReference;
+
+public class QvtGenModelTransformerVisualIDWithTraceTest extends QvtTransformCompareTestSupport {
+
+ public QvtGenModelTransformerVisualIDWithTraceTest(String name) {
+ super( name,
+ testFolder+"/test.ecore",
+ testFolder+"/test.genmodel",
+ testFolder+"/test.gmftool",
+ testFolder+"/test.gmfgraph",
+ testFolder+"/test.gmfmap");
+ }
+
+ @Override
+ protected Mapping loadMapping() {
+ Mapping mapping = GMFMapFactory.eINSTANCE.createMapping();
+ CanvasMapping cmap = GMFMapFactory.eINSTANCE.createCanvasMapping();
+ cmap.setDiagramCanvas(getCanvas());
+ mapping.setDiagram(cmap);
+
+ EPackage ePackage = getGenModel().getGenPackages().get(0).getEcorePackage();
+ EClass container = (EClass) ePackage.getEClassifier("UltimateContainer");
+ EReference containment = (EReference) container.getEStructuralFeature("all");
+ EClass srcA = (EClass) ePackage.getEClassifier("NodeSrcA");
+ cmap.setDomainMetaElement(container);
+ cmap.setDomainModel(ePackage);
+
+ TopNodeReference top1 = GMFMapFactory.eINSTANCE.createTopNodeReference();
+ top1.setContainmentFeature(containment);
+
+ NodeMapping nmap = GMFMapFactory.eINSTANCE.createNodeMapping();
+ nmap.setDomainMetaElement(srcA);
+ nmap.setDiagramNode(getCanvas().getNodes().get(0));
+ top1.setOwnedChild(nmap);
+
+ mapping.getNodes().add(top1);
+
+ return mapping;
+ }
+
+ protected TopNodeReference createTopNode(String name) {
+ TopNodeReference existing = getMapping().getNodes().get(0);
+ EPackage ePackage = existing.getOwnedChild().getDomainMetaElement().getEPackage();
+ EClass eClass = (EClass) ePackage.getEClassifier(name);
+
+ TopNodeReference node = GMFMapFactory.eINSTANCE.createTopNodeReference();
+ node.setContainmentFeature(existing.getContainmentFeature());
+
+ NodeMapping nmap = GMFMapFactory.eINSTANCE.createNodeMapping();
+ nmap.setDomainMetaElement(eClass);
+ nmap.setDiagramNode(existing.getChild().getDiagramNode());
+ node.setOwnedChild(nmap);
+
+ return node;
+ }
+
+ public void testVisualIDWithNoTrace() {
+ Transformation java = getJavaTransformation(false);
+ Transformation qvt = getQvtTransformation(false);
+
+ GenEditorGenerator expected = java.execute();
+ GenEditorGenerator actual = qvt.execute();
+
+ EList<GenTopLevelNode> expNodes = expected.getDiagram().getTopLevelNodes();
+ EList<GenTopLevelNode> actNodes = actual.getDiagram().getTopLevelNodes();
+
+ assertEquals(1, expNodes.size());
+ assertEquals(expNodes.size(), actNodes.size());
+
+ assertEquals(2001, expNodes.get(0).getVisualID());
+
+ for (int i=0;i<expNodes.size();i++){
+ GenTopLevelNode expNode = expNodes.get(i);
+ GenTopLevelNode actNode = actNodes.get(i);
+
+ assertEquals(expNode.getVisualID(), actNode.getVisualID());
+ }
+
+ java.saveGenEditor("java");
+ java.getDispencer().saveState();
+
+ qvt.getDispencer().saveState();
+ qvt.saveGenEditor("qvt");
+
+ TopNodeReference node = createTopNode("NodeTargetB");
+ getMapping().getNodes().add(node);
+
+ expected = java.execute();
+ actual = qvt.execute();
+
+ expNodes = expected.getDiagram().getTopLevelNodes();
+ actNodes = actual.getDiagram().getTopLevelNodes();
+
+ assertEquals(2, expNodes.size());
+ assertEquals(expNodes.size(), actNodes.size());
+
+ assertEquals(2001, expNodes.get(0).getVisualID());
+ assertEquals(2002, expNodes.get(1).getVisualID());
+
+ for (int i=0;i<expNodes.size();i++){
+ GenTopLevelNode expNode = expNodes.get(i);
+ GenTopLevelNode actNode = actNodes.get(i);
+
+ assertEquals(expNode.getVisualID(), actNode.getVisualID());
+ }
+
+ node = createTopNode("NodeTargetC");
+ getMapping().getNodes().add(0, node);
+
+ java.saveGenEditor("java");
+ java.getDispencer().saveState();
+
+ qvt.saveGenEditor("qvt");
+ qvt.getDispencer().saveState();
+
+ expected = java.execute();
+ actual = qvt.execute();
+
+ expNodes = expected.getDiagram().getTopLevelNodes();
+ actNodes = actual.getDiagram().getTopLevelNodes();
+
+ assertEquals(3, expNodes.size());
+ assertEquals(expNodes.size(), actNodes.size());
+
+ assertEquals(2003, expNodes.get(0).getVisualID());
+ assertEquals(2001, expNodes.get(1).getVisualID());
+ assertEquals(2002, expNodes.get(2).getVisualID());
+
+ for (int i=0;i<expNodes.size();i++){
+ GenTopLevelNode expNode = expNodes.get(i);
+ GenTopLevelNode actNode = actNodes.get(i);
+
+ assertEquals(expNode.getVisualID(), actNode.getVisualID());
+ }
+
+ java.saveGenEditor("java");
+ java.getDispencer().saveState();
+
+ qvt.saveGenEditor("qvt");
+ qvt.getDispencer().saveState();
+ }
+
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtLabelMappingTransformTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtLabelMappingTransformTest.java
index 66f4355..0cd7bd2 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtLabelMappingTransformTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtLabelMappingTransformTest.java
@@ -1,268 +1,268 @@
-/*
- * Copyright (c) 2006, 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:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.tests.tr;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.Diagnostic;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.gmf.codegen.gmfgen.GenChildLabelNode;
-import org.eclipse.gmf.codegen.gmfgen.GenChildNode;
-import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
-import org.eclipse.gmf.codegen.gmfgen.GenNode;
-import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
-import org.eclipse.gmf.mappings.CanvasMapping;
-import org.eclipse.gmf.mappings.ChildReference;
-import org.eclipse.gmf.mappings.FeatureLabelMapping;
-import org.eclipse.gmf.mappings.GMFMapFactory;
-import org.eclipse.gmf.mappings.LinkMapping;
-import org.eclipse.gmf.mappings.Mapping;
-import org.eclipse.gmf.mappings.NodeMapping;
-import org.eclipse.gmf.mappings.TopNodeReference;
-import org.eclipse.gmf.tests.Utils;
-import org.eclipse.gmf.tests.setup.DiaDefSource;
-import org.eclipse.gmf.tests.setup.MapDefSource;
-import org.eclipse.gmf.tests.setup.MapDefWithReuseSetup;
-import org.eclipse.m2m.qvt.oml.BasicModelExtent;
-import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
-import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
-import org.eclipse.m2m.qvt.oml.ModelExtent;
-import org.eclipse.m2m.qvt.oml.TransformationExecutor;
-
-/**
- * Check transformation of LabelMappings - to get either GenChildNode with GenNodeLabel or GenChildLabelNode
- * @author artem
- */
-public class QvtLabelMappingTransformTest extends AbstractMappingTransformerTest {
- private GenEditorGenerator transformationResult;
-
- public QvtLabelMappingTransformTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- transformationResult = executeQVT();
- assertNotNull(transformationResult);
- }
-
- protected GenEditorGenerator executeQVT() throws IOException {
- GenModel genModel = Utils.createGenModel(getCanvasMapping().getDomainModel());
- Mapping mapping = getMapping();
-
- ResourceSet resourceSet = genModel.eResource().getResourceSet();
-
- TransformationExecutor executor = new TransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto"));
- ExecutionContextImpl context = new ExecutionContextImpl();
- context.setConfigProperty("rcp", false);
- context.setConfigProperty("useMapMode", false);
- context.setConfigProperty("useFullRunTime", false);
- context.setConfigProperty("useInTransformationCodeGen", true);
-
- EList<EObject> mapObjects = new BasicEList<EObject>();
- mapObjects.add(mapping);
- ModelExtent inMap = new BasicModelExtent(mapObjects);
- EList<EObject> genObjects = new BasicEList<EObject>();
- genObjects.add(genModel);
- ModelExtent inGen = new BasicModelExtent(genObjects);
- Resource res = resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel"));
- res.load(null);
- ModelExtent inNotation = new BasicModelExtent(res.getContents());
-
- ModelExtent output = new BasicModelExtent();
-
- ExecutionDiagnostic result = executor.execute(context, inMap, inGen, inNotation, output);
- if(result.getSeverity() == Diagnostic.OK) {
-
- List<EObject> outObjects = output.getContents();
- assertEquals(1, outObjects.size());
- assertTrue(outObjects.get(0) instanceof GenEditorGenerator);
-
- return (GenEditorGenerator) outObjects.get(0);
- }
-
- return null;
- }
-
- protected MapDefSource initMapModel(final DiaDefSource graphDef) {
- return new MapDefSource() {
- private Mapping mapping;
- private NodeMapping nodeA;
- private NodeMapping nodeB;
-
- {
- final EPackage domainPack = EcoreFactory.eINSTANCE.createEPackage();
- domainPack.setName("DomainPack");
- final EClass domainA = EcoreFactory.eINSTANCE.createEClass();
- domainA.setName("DomainA");
- final EClass domainB = EcoreFactory.eINSTANCE.createEClass();
- domainB.setName("DomainB");
- domainPack.getEClassifiers().add(domainA);
- domainPack.getEClassifiers().add(domainB);
-
- EAttribute nameA = EcoreFactory.eINSTANCE.createEAttribute();
- nameA.setName("nameA");
- domainA.getEStructuralFeatures().add(nameA);
-
- EAttribute nameB = EcoreFactory.eINSTANCE.createEAttribute();
- nameB.setName("nameB");
- domainB.getEStructuralFeatures().add(nameB);
-
- final EReference aOwnsA = newContainment("aOwnsA", domainA);
- domainA.getEStructuralFeatures().add(aOwnsA);
- final EReference bOwnsB = newContainment("bOwnsB", domainB);
- domainB.getEStructuralFeatures().add(bOwnsB);
-
- mapping = GMFMapFactory.eINSTANCE.createMapping();
- CanvasMapping cme = GMFMapFactory.eINSTANCE.createCanvasMapping();
- cme.setDiagramCanvas(graphDef.getCanvasDef());
- cme.setDomainModel(domainPack);
- mapping.setDiagram(cme);
-
- // Node with label and subnodes (with labels as well. actually, reuses itself for subnode)
- nodeA = GMFMapFactory.eINSTANCE.createNodeMapping();
- nodeA.setDiagramNode(graphDef.getNodeDef());
- nodeA.setDomainMetaElement(domainA);
- FeatureLabelMapping lm = GMFMapFactory.eINSTANCE.createFeatureLabelMapping();
- lm.setDiagramLabel(graphDef.getLabelDef());
- lm.getFeatures().add(nameA);
- nodeA.getLabelMappings().add(lm);
- ChildReference childRef = GMFMapFactory.eINSTANCE.createChildReference();
- childRef.setContainmentFeature(aOwnsA);
- childRef.setReferencedChild(nodeA);
- nodeA.getChildren().add(childRef);
-
- // node with children that are pure labels
- nodeB = GMFMapFactory.eINSTANCE.createNodeMapping();
- nodeB.setDiagramNode(graphDef.getNodeDef());
- nodeB.setDomainMetaElement(domainB);
-
- lm = GMFMapFactory.eINSTANCE.createFeatureLabelMapping();
- lm.setDiagramLabel(graphDef.getLabelDef());
- lm.getFeatures().add(nameB);
-
- NodeMapping childNodeB = GMFMapFactory.eINSTANCE.createNodeMapping();
- childNodeB.setDiagramNode(lm.getDiagramLabel()); // SIC! we use diagram label for node to 'shortcut' label-only children
- childNodeB.setDomainMetaElement(domainB);
- childNodeB.getLabelMappings().add(lm);
- childRef = GMFMapFactory.eINSTANCE.createChildReference();
- childRef.setContainmentFeature(bOwnsB);
- childRef.setOwnedChild(childNodeB);
- nodeB.getChildren().add(childRef);
-
- TopNodeReference tnr = GMFMapFactory.eINSTANCE.createTopNodeReference();
- tnr.setOwnedChild(nodeA);
- tnr.setContainmentFeature(aOwnsA);
- mapping.getNodes().add(tnr);
-
- tnr = GMFMapFactory.eINSTANCE.createTopNodeReference();
- tnr.setOwnedChild(nodeB);
- tnr.setContainmentFeature(bOwnsB);
- mapping.getNodes().add(tnr);
- }
-
- public LinkMapping getClassLink() {
- return null;
- }
-
- public Mapping getMapping() {
- return mapping;
- }
-
- public NodeMapping getNodeA() {
- return nodeA;
- }
-
- public NodeMapping getNodeB() {
- return nodeB;
- }
-
- public LinkMapping getReferenceLink() {
- return null;
- }
- };
- }
-
- /**
- * there should be GenChildNode with GenNodelLabel
- */
- public void testNodeAndLabelPairOutcome() {
- GenNode nodeA = getGenNodeA();
-
- assertFalse(nodeA.getLabels().isEmpty());
- GenChildNode childA = nodeA.getChildNodes().get(0);
- assertFalse(childA instanceof GenChildLabelNode);
- assertFalse(childA.getLabels().isEmpty());
-
- }
-
- public void testSoleLabelNodeOutcome() {
- GenNode nodeB = getGenNodeB();
- assertTrue(nodeB.getLabels().isEmpty()); // sanity
- GenChildNode childB = nodeB.getChildNodes().get(0);
- assertTrue (childB instanceof GenChildLabelNode);
- assertTrue(childB.getLabels().isEmpty());
- }
-
- /**
- * FIXME copy-of {@link MapDefWithReuseSetup#newContainment(String, EClass)}
- */
- private static EReference newContainment(String name, final EClass domainClass) {
- final EReference ref = EcoreFactory.eINSTANCE.createEReference();
- ref.setName(name);
- ref.setContainment(true);
- ref.setUpperBound(-1);
- ref.setEType(domainClass);
- return ref;
- }
-
- ////////////////
- // FIXME copy-of GenModelTransformerSimpleTest
- //
-
- private GenNode getGenNodeA() {
- GenNode rv = findTopNode(getNodeDomainElement(0));
- assertNotNull(rv);
- return rv;
- }
-
- private GenNode getGenNodeB() {
- GenNode rv = findTopNode(getNodeDomainElement(1));
- assertNotNull(rv);
- return rv;
- }
-
- private EClass getNodeDomainElement(int idx) {
- return (getMapping().getNodes().get(idx)).getOwnedChild().getDomainMetaElement();
- }
-
- private GenNode findTopNode(EClass eClass) {
- for (GenTopLevelNode next : transformationResult.getDiagram().getTopLevelNodes()) {
- if (next.getDomainMetaClass().getEcoreClass() == eClass) {
- return next;
- }
- }
- return null;
- }
-}
+/*
+ * Copyright (c) 2006, 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.tr;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.gmf.codegen.gmfgen.GenChildLabelNode;
+import org.eclipse.gmf.codegen.gmfgen.GenChildNode;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.gmf.codegen.gmfgen.GenNode;
+import org.eclipse.gmf.codegen.gmfgen.GenTopLevelNode;
+import org.eclipse.gmf.mappings.CanvasMapping;
+import org.eclipse.gmf.mappings.ChildReference;
+import org.eclipse.gmf.mappings.FeatureLabelMapping;
+import org.eclipse.gmf.mappings.GMFMapFactory;
+import org.eclipse.gmf.mappings.LinkMapping;
+import org.eclipse.gmf.mappings.Mapping;
+import org.eclipse.gmf.mappings.NodeMapping;
+import org.eclipse.gmf.mappings.TopNodeReference;
+import org.eclipse.gmf.tests.Utils;
+import org.eclipse.gmf.tests.setup.DiaDefSource;
+import org.eclipse.gmf.tests.setup.MapDefSource;
+import org.eclipse.gmf.tests.setup.MapDefWithReuseSetup;
+import org.eclipse.m2m.qvt.oml.BasicModelExtent;
+import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
+import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
+import org.eclipse.m2m.qvt.oml.ModelExtent;
+import org.eclipse.m2m.qvt.oml.TransformationExecutor;
+
+/**
+ * Check transformation of LabelMappings - to get either GenChildNode with GenNodeLabel or GenChildLabelNode
+ * @author artem
+ */
+public class QvtLabelMappingTransformTest extends AbstractMappingTransformerTest {
+ private GenEditorGenerator transformationResult;
+
+ public QvtLabelMappingTransformTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ transformationResult = executeQVT();
+ assertNotNull(transformationResult);
+ }
+
+ protected GenEditorGenerator executeQVT() throws IOException {
+ GenModel genModel = Utils.createGenModel(getCanvasMapping().getDomainModel());
+ Mapping mapping = getMapping();
+
+ ResourceSet resourceSet = genModel.eResource().getResourceSet();
+
+ TransformationExecutor executor = new TransformationExecutor(URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto"));
+ ExecutionContextImpl context = new ExecutionContextImpl();
+ context.setConfigProperty("rcp", false);
+ context.setConfigProperty("useMapMode", false);
+ context.setConfigProperty("useFullRunTime", false);
+ context.setConfigProperty("useInTransformationCodeGen", true);
+
+ EList<EObject> mapObjects = new BasicEList<EObject>();
+ mapObjects.add(mapping);
+ ModelExtent inMap = new BasicModelExtent(mapObjects);
+ EList<EObject> genObjects = new BasicEList<EObject>();
+ genObjects.add(genModel);
+ ModelExtent inGen = new BasicModelExtent(genObjects);
+ Resource res = resourceSet.createResource(URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel"));
+ res.load(null);
+ ModelExtent inNotation = new BasicModelExtent(res.getContents());
+
+ ModelExtent output = new BasicModelExtent();
+
+ ExecutionDiagnostic result = executor.execute(context, inMap, inGen, inNotation, output);
+ if(result.getSeverity() == Diagnostic.OK) {
+
+ List<EObject> outObjects = output.getContents();
+ assertEquals(1, outObjects.size());
+ assertTrue(outObjects.get(0) instanceof GenEditorGenerator);
+
+ return (GenEditorGenerator) outObjects.get(0);
+ }
+
+ return null;
+ }
+
+ protected MapDefSource initMapModel(final DiaDefSource graphDef) {
+ return new MapDefSource() {
+ private Mapping mapping;
+ private NodeMapping nodeA;
+ private NodeMapping nodeB;
+
+ {
+ final EPackage domainPack = EcoreFactory.eINSTANCE.createEPackage();
+ domainPack.setName("DomainPack");
+ final EClass domainA = EcoreFactory.eINSTANCE.createEClass();
+ domainA.setName("DomainA");
+ final EClass domainB = EcoreFactory.eINSTANCE.createEClass();
+ domainB.setName("DomainB");
+ domainPack.getEClassifiers().add(domainA);
+ domainPack.getEClassifiers().add(domainB);
+
+ EAttribute nameA = EcoreFactory.eINSTANCE.createEAttribute();
+ nameA.setName("nameA");
+ domainA.getEStructuralFeatures().add(nameA);
+
+ EAttribute nameB = EcoreFactory.eINSTANCE.createEAttribute();
+ nameB.setName("nameB");
+ domainB.getEStructuralFeatures().add(nameB);
+
+ final EReference aOwnsA = newContainment("aOwnsA", domainA);
+ domainA.getEStructuralFeatures().add(aOwnsA);
+ final EReference bOwnsB = newContainment("bOwnsB", domainB);
+ domainB.getEStructuralFeatures().add(bOwnsB);
+
+ mapping = GMFMapFactory.eINSTANCE.createMapping();
+ CanvasMapping cme = GMFMapFactory.eINSTANCE.createCanvasMapping();
+ cme.setDiagramCanvas(graphDef.getCanvasDef());
+ cme.setDomainModel(domainPack);
+ mapping.setDiagram(cme);
+
+ // Node with label and subnodes (with labels as well. actually, reuses itself for subnode)
+ nodeA = GMFMapFactory.eINSTANCE.createNodeMapping();
+ nodeA.setDiagramNode(graphDef.getNodeDef());
+ nodeA.setDomainMetaElement(domainA);
+ FeatureLabelMapping lm = GMFMapFactory.eINSTANCE.createFeatureLabelMapping();
+ lm.setDiagramLabel(graphDef.getLabelDef());
+ lm.getFeatures().add(nameA);
+ nodeA.getLabelMappings().add(lm);
+ ChildReference childRef = GMFMapFactory.eINSTANCE.createChildReference();
+ childRef.setContainmentFeature(aOwnsA);
+ childRef.setReferencedChild(nodeA);
+ nodeA.getChildren().add(childRef);
+
+ // node with children that are pure labels
+ nodeB = GMFMapFactory.eINSTANCE.createNodeMapping();
+ nodeB.setDiagramNode(graphDef.getNodeDef());
+ nodeB.setDomainMetaElement(domainB);
+
+ lm = GMFMapFactory.eINSTANCE.createFeatureLabelMapping();
+ lm.setDiagramLabel(graphDef.getLabelDef());
+ lm.getFeatures().add(nameB);
+
+ NodeMapping childNodeB = GMFMapFactory.eINSTANCE.createNodeMapping();
+ childNodeB.setDiagramNode(lm.getDiagramLabel()); // SIC! we use diagram label for node to 'shortcut' label-only children
+ childNodeB.setDomainMetaElement(domainB);
+ childNodeB.getLabelMappings().add(lm);
+ childRef = GMFMapFactory.eINSTANCE.createChildReference();
+ childRef.setContainmentFeature(bOwnsB);
+ childRef.setOwnedChild(childNodeB);
+ nodeB.getChildren().add(childRef);
+
+ TopNodeReference tnr = GMFMapFactory.eINSTANCE.createTopNodeReference();
+ tnr.setOwnedChild(nodeA);
+ tnr.setContainmentFeature(aOwnsA);
+ mapping.getNodes().add(tnr);
+
+ tnr = GMFMapFactory.eINSTANCE.createTopNodeReference();
+ tnr.setOwnedChild(nodeB);
+ tnr.setContainmentFeature(bOwnsB);
+ mapping.getNodes().add(tnr);
+ }
+
+ public LinkMapping getClassLink() {
+ return null;
+ }
+
+ public Mapping getMapping() {
+ return mapping;
+ }
+
+ public NodeMapping getNodeA() {
+ return nodeA;
+ }
+
+ public NodeMapping getNodeB() {
+ return nodeB;
+ }
+
+ public LinkMapping getReferenceLink() {
+ return null;
+ }
+ };
+ }
+
+ /**
+ * there should be GenChildNode with GenNodelLabel
+ */
+ public void testNodeAndLabelPairOutcome() {
+ GenNode nodeA = getGenNodeA();
+
+ assertFalse(nodeA.getLabels().isEmpty());
+ GenChildNode childA = nodeA.getChildNodes().get(0);
+ assertFalse(childA instanceof GenChildLabelNode);
+ assertFalse(childA.getLabels().isEmpty());
+
+ }
+
+ public void testSoleLabelNodeOutcome() {
+ GenNode nodeB = getGenNodeB();
+ assertTrue(nodeB.getLabels().isEmpty()); // sanity
+ GenChildNode childB = nodeB.getChildNodes().get(0);
+ assertTrue (childB instanceof GenChildLabelNode);
+ assertTrue(childB.getLabels().isEmpty());
+ }
+
+ /**
+ * FIXME copy-of {@link MapDefWithReuseSetup#newContainment(String, EClass)}
+ */
+ private static EReference newContainment(String name, final EClass domainClass) {
+ final EReference ref = EcoreFactory.eINSTANCE.createEReference();
+ ref.setName(name);
+ ref.setContainment(true);
+ ref.setUpperBound(-1);
+ ref.setEType(domainClass);
+ return ref;
+ }
+
+ ////////////////
+ // FIXME copy-of GenModelTransformerSimpleTest
+ //
+
+ private GenNode getGenNodeA() {
+ GenNode rv = findTopNode(getNodeDomainElement(0));
+ assertNotNull(rv);
+ return rv;
+ }
+
+ private GenNode getGenNodeB() {
+ GenNode rv = findTopNode(getNodeDomainElement(1));
+ assertNotNull(rv);
+ return rv;
+ }
+
+ private EClass getNodeDomainElement(int idx) {
+ return (getMapping().getNodes().get(idx)).getOwnedChild().getDomainMetaElement();
+ }
+
+ private GenNode findTopNode(EClass eClass) {
+ for (GenTopLevelNode next : transformationResult.getDiagram().getTopLevelNodes()) {
+ if (next.getDomainMetaClass().getEcoreClass() == eClass) {
+ return next;
+ }
+ }
+ return null;
+ }
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtPaletteTransformationTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtPaletteTransformationTest.java
index 5ae9017..b336a68 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtPaletteTransformationTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtPaletteTransformationTest.java
@@ -1,245 +1,246 @@
-/*
- * Copyright (c) 2006, 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:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-package org.eclipse.gmf.tests.tr;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.codegen.gmfgen.Palette;
-import org.eclipse.gmf.codegen.gmfgen.Separator;
-import org.eclipse.gmf.codegen.gmfgen.ToolEntry;
-import org.eclipse.gmf.codegen.gmfgen.ToolGroup;
-import org.eclipse.gmf.codegen.gmfgen.ToolGroupItem;
-import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
-import org.eclipse.gmf.tests.setup.DiaDefSource;
-import org.eclipse.gmf.tests.setup.MapDefSource;
-import org.eclipse.gmf.tests.setup.MapSetup;
-import org.eclipse.gmf.tests.setup.ToolDefSetup;
-import org.eclipse.gmf.tooldef.AbstractTool;
-import org.eclipse.gmf.tooldef.CreationTool;
-import org.eclipse.gmf.tooldef.GMFToolFactory;
-import org.eclipse.gmf.tooldef.GenericTool;
-
-/**
- * TODO test ToolEntry.properties to appear in the code
- * TODO test collape/active attibutes of tooldef.ToolGroup
- * @author artem
- */
-public class QvtPaletteTransformationTest extends QvtGenModelTransformerTest {
-
- private static final int TOOLS_FOR_CHECK = 5;
- private static final int SEP_2_POS = 4;
- private static final int SEP_1_POS = 2;
-
- private AbstractTool myTool2Reuse;
- /*
- * Besides, we add it as a top-level tool, to check in #testTopLevelToolDefMovedToDefaultGroup
- * And, it's a tool that is not referenced from any mappingEntry
- */
- private GenericTool myToolWithClass;
- private CreationTool myToolFromWrongPalette;
- private org.eclipse.gmf.tooldef.ToolGroup myGroupWithWrongTool;
- private org.eclipse.gmf.tooldef.ToolGroup myGroupWithOrderAndSeparators;
- private org.eclipse.gmf.tooldef.ToolGroup myToolStackGroup;
-
-
- public QvtPaletteTransformationTest(String name) {
- super(name, new BasicDiagramRunTimeModelHelper());
- }
-
- protected MapDefSource initMapModel(DiaDefSource graphDef) {
- final ToolDefSetup toolDefSetup = new ToolDefSetup();
- final MapSetup init = new MapSetup().init(graphDef, getSetup().getDomainModel(), toolDefSetup);
- // use same tool twice
- myTool2Reuse = GMFToolFactory.eINSTANCE.createCreationTool();
- myTool2Reuse.setTitle("NodeTool");
- toolDefSetup.getPalette().getTools().add(myTool2Reuse);
- init.getNodeA().setTool(myTool2Reuse);
- init.getNodeB().setTool(myTool2Reuse);
- myToolWithClass = GMFToolFactory.eINSTANCE.createGenericTool();
- myToolWithClass.setTitle("ToolWithClass");
- myToolWithClass.setToolClass(Object.class.getName());
- // and explicitly add it as a top-level tool
- init.getMapping().getDiagram().getPalette().getTools().add(myToolWithClass);
- myToolFromWrongPalette = GMFToolFactory.eINSTANCE.createCreationTool();
- myToolFromWrongPalette.setTitle("ToolFromWrongPalette");
- myGroupWithWrongTool = GMFToolFactory.eINSTANCE.createToolGroup();
- myGroupWithWrongTool.setTitle("GroupWithWrongTool");
- myGroupWithWrongTool.getTools().add(myToolFromWrongPalette);
- init.getClassLink().setTool(myToolFromWrongPalette);
- myGroupWithOrderAndSeparators = GMFToolFactory.eINSTANCE.createToolGroup();
- myGroupWithOrderAndSeparators.setTitle("GroupWithOrderAndSeparators");
- myGroupWithOrderAndSeparators.getTools().addAll(createToolsForOrderCheck(TOOLS_FOR_CHECK));
- myGroupWithOrderAndSeparators.getTools().add(SEP_1_POS, GMFToolFactory.eINSTANCE.createPaletteSeparator());
- myGroupWithOrderAndSeparators.getTools().add(SEP_2_POS, GMFToolFactory.eINSTANCE.createPaletteSeparator());
- toolDefSetup.getPalette().getTools().add(myGroupWithOrderAndSeparators);
-
- myToolStackGroup = GMFToolFactory.eINSTANCE.createToolGroup();
- myToolStackGroup.setTitle("StackGroup");
- myToolStackGroup.setStack(true);
- myToolStackGroup.getTools().addAll(createToolsForOrderCheck(2));
- toolDefSetup.getPalette().getTools().add(myToolStackGroup);
-
- return init;
- }
-
- private static List<AbstractTool> createToolsForOrderCheck(final int numOfTools) {
- assert numOfTools > 0;
- ArrayList<AbstractTool> rv = new ArrayList<AbstractTool>(numOfTools);
- for (int i = 0; i < numOfTools; i++) {
- // testOrderPreserved relies on fact there are GenericTools
- GenericTool t = GMFToolFactory.eINSTANCE.createGenericTool();
- t.setTitle("ToolOrder" + i);
- t.setToolClass(Object.class.getName());
- rv.add(t);
- }
- return rv;
- }
-
- public void testToolEntryReuse() {
- ToolEntry te = findToolEntry(myTool2Reuse);
- assertNotNull(te);
- assertEquals(2, te.getGenNodes().size());
- assertEquals(2, te.getElements().size());
- assertEquals(0, te.getGenLinks().size());
- assertEquals("Node[A|B] should share same ToolEntry", 1, countToolEntriesWithName(myTool2Reuse.getTitle()));
- }
-
- public void testUseNonReferencedTool() {
- ToolEntry te = findToolEntry(myToolWithClass);
- assertNotNull("Present", te);
- assertEquals("... and only once", 1, countToolEntriesWithName(myToolWithClass.getTitle()));
- assertEquals(0, te.getGenNodes().size());
- assertEquals(0, te.getElements().size());
- assertEquals(0, te.getGenLinks().size());
- }
-
- public void testUseToolWithClass() {
- ToolEntry te = findToolEntry(myToolWithClass);
- assertNotNull("Present", te);
- assertNotNull(te.getQualifiedToolName());
- assertEquals(myToolWithClass.getToolClass(), te.getQualifiedToolName());
- }
-
- public void testTopLevelToolDefMovedToDefaultGroup() {
- ToolEntry te = findToolEntry(myToolWithClass);
- assertNotNull("Present", te);
- assertFalse("not in palette...", te.eContainer() instanceof Palette);
- assertTrue("... rather in some group ...", te.eContainer() instanceof ToolGroup);
- ToolGroup group = (ToolGroup) te.eContainer();
- assertTrue("... which in turn is child of palette", group.eContainer() instanceof Palette);
- }
-
-// public void testReferenceToolFromWrongPalette() {
-// ToolEntry te = findToolEntry(myToolFromWrongPalette);
-// assertNotNull("Present", te);
-// assertEquals("... and only once", 1, countToolEntriesWithName(myToolFromWrongPalette.getTitle()));
-// assertTrue("There's some group for mis-referenced tools...", te.eContainer() instanceof ToolGroup);
-// ToolGroup group = (ToolGroup) te.eContainer();
-// assert myGroupWithWrongTool.getTools().contains(myToolFromWrongPalette) : "just make sure we didn't forget to add one to another";
-// assertNotSame("But it's not the transformation of the original owner", myGroupWithWrongTool.getTitle(), group.getTitle());
-// }
-
- public void testOrderPreserved() {
- ToolGroup transformed = findTransformedGroup(myGroupWithOrderAndSeparators);
- assertNotNull(transformed);
- Iterator<ToolGroupItem> itTransformed = transformed.getEntries().iterator();
- int toolsCompared = 0;
- for (Iterator<AbstractTool> itOriginal = myGroupWithOrderAndSeparators.getTools().iterator(); itOriginal.hasNext();) {
- GenericTool next = null;
- do {
- Object o = itOriginal.next();
- if (o instanceof GenericTool) {
- next = (GenericTool) o;
- }
- } while (next == null && itOriginal.hasNext());
- if (next == null && !itOriginal.hasNext()) {
- break;
- }
- while (itTransformed.hasNext()) {
- Object o = itTransformed.next();
- if (o instanceof ToolEntry) {
- assertEquals(next.getTitle(), ((ToolEntry) o).getTitle());
- toolsCompared++;
- break;
- }
- }
- }
- assertEquals(TOOLS_FOR_CHECK, toolsCompared);
- }
-
- public void testSeparators() {
- ToolGroup transformed = findTransformedGroup(myGroupWithOrderAndSeparators);
- assertNotNull(transformed);
- ToolGroupItem item = transformed.getEntries().get(SEP_1_POS);
- assertTrue(item instanceof Separator);
- item = transformed.getEntries().get(SEP_2_POS);
- assertTrue(item instanceof Separator);
- }
-
- public void testStackGroup(){
- ToolGroup explicitlyStack = findTransformedGroup(myToolStackGroup);
- assertNotNull(explicitlyStack);
- assertTrue(explicitlyStack.isStack());
-
- ToolGroup byDefaultNotStack = findTransformedGroup(myGroupWithOrderAndSeparators);
- assertNotNull(byDefaultNotStack);
- assertFalse(byDefaultNotStack.isStack());
- }
-
- private ToolGroup findTransformedGroup(org.eclipse.gmf.tooldef.ToolGroup toolGroup) {
- ToolGroup transformed = null;
- for (ToolGroup next : getResultPalette().getGroups()) {
- if (toolGroup.getTitle().equals(next.getTitle())) {
- transformed = next;
- break;
- }
- }
- return transformed;
- }
-
- private ToolEntry findToolEntry(AbstractTool tool) {
- Palette palette = getResultPalette();
- for (Iterator<EObject> it = palette.eAllContents(); it.hasNext();) {
- EObject next = it.next();
- if (next instanceof ToolEntry) {
- ToolEntry toolEntry = (ToolEntry) next;
- if (tool.getTitle().equals(toolEntry.getTitle())) {
- return toolEntry;
- }
- }
- }
- return null;
- }
-
- private Palette getResultPalette() {
- Palette palette = myTransformationResult.getDiagram().getPalette();
- return palette;
- }
-
- private int countToolEntriesWithName(String name) {
- int count = 0;
- Palette palette = getResultPalette();
- for (Iterator<EObject> it = palette.eAllContents(); it.hasNext();) {
- EObject next = it.next();
- if (next instanceof ToolEntry) {
- ToolEntry toolEntry = (ToolEntry) next;
- if (name.equals(toolEntry.getTitle())) {
- count++;
- }
- }
- }
- return count;
- }
-}
+/*
+ * Copyright (c) 2006, 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.tr;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.codegen.gmfgen.Palette;
+import org.eclipse.gmf.codegen.gmfgen.Separator;
+import org.eclipse.gmf.codegen.gmfgen.ToolEntry;
+import org.eclipse.gmf.codegen.gmfgen.ToolGroup;
+import org.eclipse.gmf.codegen.gmfgen.ToolGroupItem;
+import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
+import org.eclipse.gmf.tests.setup.DiaDefSource;
+import org.eclipse.gmf.tests.setup.MapDefSource;
+import org.eclipse.gmf.tests.setup.MapSetup;
+import org.eclipse.gmf.tests.setup.ToolDefSetup;
+import org.eclipse.gmf.tooldef.AbstractTool;
+import org.eclipse.gmf.tooldef.CreationTool;
+import org.eclipse.gmf.tooldef.GMFToolFactory;
+import org.eclipse.gmf.tooldef.GenericTool;
+
+/**
+ * TODO test ToolEntry.properties to appear in the code
+ * TODO test collape/active attibutes of tooldef.ToolGroup
+ * @author artem
+ */
+public class QvtPaletteTransformationTest extends QvtGenModelTransformerTest {
+
+ private static final int TOOLS_FOR_CHECK = 5;
+ private static final int SEP_2_POS = 4;
+ private static final int SEP_1_POS = 2;
+
+ private AbstractTool myTool2Reuse;
+ /*
+ * Besides, we add it as a top-level tool, to check in #testTopLevelToolDefMovedToDefaultGroup
+ * And, it's a tool that is not referenced from any mappingEntry
+ */
+ private GenericTool myToolWithClass;
+ private CreationTool myToolFromWrongPalette;
+ private org.eclipse.gmf.tooldef.ToolGroup myGroupWithWrongTool;
+ private org.eclipse.gmf.tooldef.ToolGroup myGroupWithOrderAndSeparators;
+ private org.eclipse.gmf.tooldef.ToolGroup myToolStackGroup;
+
+
+ public QvtPaletteTransformationTest(String name) {
+ super(name, new BasicDiagramRunTimeModelHelper());
+ }
+
+ protected MapDefSource initMapModel(DiaDefSource graphDef) {
+ final ToolDefSetup toolDefSetup = new ToolDefSetup();
+ final MapSetup init = new MapSetup().init(graphDef, getSetup().getDomainModel(), toolDefSetup);
+ // use same tool twice
+ myTool2Reuse = GMFToolFactory.eINSTANCE.createCreationTool();
+ myTool2Reuse.setTitle("NodeTool");
+ toolDefSetup.getPalette().getTools().add(myTool2Reuse);
+ init.getNodeA().setTool(myTool2Reuse);
+ init.getNodeB().setTool(myTool2Reuse);
+ myToolWithClass = GMFToolFactory.eINSTANCE.createGenericTool();
+ myToolWithClass.setTitle("ToolWithClass");
+ myToolWithClass.setToolClass(Object.class.getName());
+ // and explicitly add it as a top-level tool
+ init.getMapping().getDiagram().getPalette().getTools().add(myToolWithClass);
+ myToolFromWrongPalette = GMFToolFactory.eINSTANCE.createCreationTool();
+ myToolFromWrongPalette.setTitle("ToolFromWrongPalette");
+ myGroupWithWrongTool = GMFToolFactory.eINSTANCE.createToolGroup();
+ myGroupWithWrongTool.setTitle("GroupWithWrongTool");
+ myGroupWithWrongTool.getTools().add(myToolFromWrongPalette);
+ init.getClassLink().setTool(myToolFromWrongPalette);
+ myGroupWithOrderAndSeparators = GMFToolFactory.eINSTANCE.createToolGroup();
+ myGroupWithOrderAndSeparators.setTitle("GroupWithOrderAndSeparators");
+ myGroupWithOrderAndSeparators.getTools().addAll(createToolsForOrderCheck(TOOLS_FOR_CHECK));
+ myGroupWithOrderAndSeparators.getTools().add(SEP_1_POS, GMFToolFactory.eINSTANCE.createPaletteSeparator());
+ myGroupWithOrderAndSeparators.getTools().add(SEP_2_POS, GMFToolFactory.eINSTANCE.createPaletteSeparator());
+ toolDefSetup.getPalette().getTools().add(myGroupWithOrderAndSeparators);
+
+ myToolStackGroup = GMFToolFactory.eINSTANCE.createToolGroup();
+ myToolStackGroup.setTitle("StackGroup");
+ myToolStackGroup.setStack(true);
+ myToolStackGroup.getTools().addAll(createToolsForOrderCheck(2));
+ toolDefSetup.getPalette().getTools().add(myToolStackGroup);
+
+ return init;
+ }
+
+ private static List<AbstractTool> createToolsForOrderCheck(final int numOfTools) {
+ assert numOfTools > 0;
+ ArrayList<AbstractTool> rv = new ArrayList<AbstractTool>(numOfTools);
+ for (int i = 0; i < numOfTools; i++) {
+ // testOrderPreserved relies on fact there are GenericTools
+ GenericTool t = GMFToolFactory.eINSTANCE.createGenericTool();
+ t.setTitle("ToolOrder" + i);
+ t.setToolClass(Object.class.getName());
+ rv.add(t);
+ }
+ return rv;
+ }
+
+ public void testToolEntryReuse() {
+ ToolEntry te = findToolEntry(myTool2Reuse);
+ assertNotNull(te);
+ assertEquals(2, te.getGenNodes().size());
+ assertEquals(2, te.getElements().size());
+ assertEquals(0, te.getGenLinks().size());
+ assertEquals("Node[A|B] should share same ToolEntry", 1, countToolEntriesWithName(myTool2Reuse.getTitle()));
+ }
+
+ public void testUseNonReferencedTool() {
+ ToolEntry te = findToolEntry(myToolWithClass);
+ assertNotNull("Present", te);
+ assertEquals("... and only once", 1, countToolEntriesWithName(myToolWithClass.getTitle()));
+ assertEquals(0, te.getGenNodes().size());
+ assertEquals(0, te.getElements().size());
+ assertEquals(0, te.getGenLinks().size());
+ }
+
+ public void testUseToolWithClass() {
+ ToolEntry te = findToolEntry(myToolWithClass);
+ assertNotNull("Present", te);
+ assertNotNull(te.getQualifiedToolName());
+ assertEquals(myToolWithClass.getToolClass(), te.getQualifiedToolName());
+ }
+
+ public void testTopLevelToolDefMovedToDefaultGroup() {
+ ToolEntry te = findToolEntry(myToolWithClass);
+ assertNotNull("Present", te);
+ assertFalse("not in palette...", te.eContainer() instanceof Palette);
+ assertTrue("... rather in some group ...", te.eContainer() instanceof ToolGroup);
+ ToolGroup group = (ToolGroup) te.eContainer();
+ assertTrue("... which in turn is child of palette", group.eContainer() instanceof Palette);
+ }
+
+// public void testReferenceToolFromWrongPalette() {
+// ToolEntry te = findToolEntry(myToolFromWrongPalette);
+// assertNotNull("Present", te);
+// assertEquals("... and only once", 1, countToolEntriesWithName(myToolFromWrongPalette.getTitle()));
+// assertTrue("There's some group for mis-referenced tools...", te.eContainer() instanceof ToolGroup);
+// ToolGroup group = (ToolGroup) te.eContainer();
+// assert myGroupWithWrongTool.getTools().contains(myToolFromWrongPalette) : "just make sure we didn't forget to add one to another";
+// assertNotSame("But it's not the transformation of the original owner", myGroupWithWrongTool.getTitle(), group.getTitle());
+// }
+
+ public void testOrderPreserved() {
+ ToolGroup transformed = findTransformedGroup(myGroupWithOrderAndSeparators);
+ assertNotNull(transformed);
+ Iterator<ToolGroupItem> itTransformed = transformed.getEntries().iterator();
+ int toolsCompared = 0;
+ for (Iterator<AbstractTool> itOriginal = myGroupWithOrderAndSeparators.getTools().iterator(); itOriginal.hasNext();) {
+ GenericTool next = null;
+ do {
+ Object o = itOriginal.next();
+ if (o instanceof GenericTool) {
+ next = (GenericTool) o;
+ }
+ } while (next == null && itOriginal.hasNext());
+ if (next == null && !itOriginal.hasNext()) {
+ break;
+ }
+ while (itTransformed.hasNext()) {
+ Object o = itTransformed.next();
+ if (o instanceof ToolEntry) {
+ assertEquals(next.getTitle(), ((ToolEntry) o).getTitle());
+ toolsCompared++;
+ break;
+ }
+ }
+ }
+ assertEquals(TOOLS_FOR_CHECK, toolsCompared);
+ }
+
+ public void testSeparators() {
+ ToolGroup transformed = findTransformedGroup(myGroupWithOrderAndSeparators);
+ assertNotNull(transformed);
+ ToolGroupItem item = transformed.getEntries().get(SEP_1_POS);
+ assertTrue(item instanceof Separator);
+ item = transformed.getEntries().get(SEP_2_POS);
+ assertTrue(item instanceof Separator);
+ }
+
+ public void testStackGroup(){
+ ToolGroup explicitlyStack = findTransformedGroup(myToolStackGroup);
+ assertNotNull(explicitlyStack);
+ assertTrue(explicitlyStack.isStack());
+
+ ToolGroup byDefaultNotStack = findTransformedGroup(myGroupWithOrderAndSeparators);
+ assertNotNull(byDefaultNotStack);
+ assertFalse(byDefaultNotStack.isStack());
+ }
+
+ private ToolGroup findTransformedGroup(org.eclipse.gmf.tooldef.ToolGroup toolGroup) {
+ ToolGroup transformed = null;
+ for (ToolGroup next : getResultPalette().getGroups()) {
+ if (toolGroup.getTitle().equals(next.getTitle())) {
+ transformed = next;
+ break;
+ }
+ }
+ return transformed;
+ }
+
+ private ToolEntry findToolEntry(AbstractTool tool) {
+ Palette palette = getResultPalette();
+ for (Iterator<EObject> it = palette.eAllContents(); it.hasNext();) {
+ EObject next = it.next();
+ if (next instanceof ToolEntry) {
+ ToolEntry toolEntry = (ToolEntry) next;
+ if (tool.getTitle().equals(toolEntry.getTitle())) {
+ return toolEntry;
+ }
+ }
+ }
+ return null;
+ }
+
+ private Palette getResultPalette() {
+ Palette palette = myTransformationResult.getDiagram().getPalette();
+ return palette;
+ }
+
+ private int countToolEntriesWithName(String name) {
+ int count = 0;
+ Palette palette = getResultPalette();
+ for (Iterator<EObject> it = palette.eAllContents(); it.hasNext();) {
+ EObject next = it.next();
+ if (next instanceof ToolEntry) {
+ ToolEntry toolEntry = (ToolEntry) next;
+ if (name.equals(toolEntry.getTitle())) {
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+}
+
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareAbstractTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareAbstractTest.java
index 0fa62bf..4a4f752 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareAbstractTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareAbstractTest.java
@@ -64,8 +64,12 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
public void setUp() throws Exception {
super.setUp();
- expectedGenerator = executeBaseTransformation();
- actualGenerator = executeQvtTransformation();
+ Transformation java = getJavaTransformation(false);
+ expectedGenerator = java.execute();
+ java.saveGenEditor("java");
+ Transformation qvt = getQvtTransformation(false);
+ actualGenerator = qvt.execute();
+ qvt.saveGenEditor("qvt");
}
public void testGenAuditRoot() {
@@ -85,11 +89,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenTopLevelNode() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
-
- GenDiagram expectedDiagram = expectedGenEditor.getDiagram();
- GenDiagram actualDiagram = actualGenEditor.getDiagram();
+ GenDiagram expectedDiagram = expectedGenerator.getDiagram();
+ GenDiagram actualDiagram = actualGenerator.getDiagram();
assertNotNull(expectedDiagram);
assertNotNull(actualDiagram);
@@ -113,8 +114,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenChildNode() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenDiagram expectedDiagram = expectedGenEditor.getDiagram();
GenDiagram actualDiagram = actualGenEditor.getDiagram();
@@ -149,8 +150,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenLink() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenDiagram expectedDiagram = expectedGenEditor.getDiagram();
GenDiagram actualDiagram = actualGenEditor.getDiagram();
@@ -175,8 +176,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenNavigator() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenNavigator baseNavigator = expectedGenEditor.getNavigator();
GenNavigator qvtNavigator = actualGenEditor.getNavigator();
@@ -185,8 +186,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenNavigatorChildReferences() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenNavigator expected = expectedGenEditor.getNavigator();
GenNavigator actual = actualGenEditor.getNavigator();
@@ -220,8 +221,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenPlugin() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenPlugin basePlugin = expectedGenEditor.getPlugin();
GenPlugin qvtPlugin = actualGenEditor.getPlugin();
@@ -231,8 +232,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenPropertySheet() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenPropertySheet basePropSheet = expectedGenEditor.getPropertySheet();
GenPropertySheet qvtPropSheet = actualGenEditor.getPropertySheet();
@@ -247,8 +248,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenPropertySheetTabs() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenPropertySheet expected = expectedGenEditor.getPropertySheet();
GenPropertySheet actual = actualGenEditor.getPropertySheet();
@@ -269,8 +270,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenDiagramPalette() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
Palette expected = expectedGenEditor.getDiagram().getPalette();
Palette actual = actualGenEditor.getDiagram().getPalette();
@@ -279,8 +280,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenDiagramPaletteToolGroup() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
Palette basePalette = expectedGenEditor.getDiagram().getPalette();
Palette qvtPalette = actualGenEditor.getDiagram().getPalette();
@@ -315,8 +316,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenDiagramUpdater() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenDiagramUpdater baseUpdater = expectedGenEditor.getDiagramUpdater();
GenDiagramUpdater qvtUpdater = actualGenEditor.getDiagramUpdater();
@@ -326,8 +327,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenEditorView() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenEditorView baseEditor = expectedGenEditor.getEditor();
GenEditorView qvtEditor = actualGenEditor.getEditor();
@@ -343,8 +344,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testLabelGenParsers() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenParsers baseParser = expectedGenEditor.getLabelParsers();
GenParsers qvtParser = actualGenEditor.getLabelParsers();
@@ -364,8 +365,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenContextMenu() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
EList<GenContextMenu> baseContexts = expectedGenEditor.getContextMenus();
EList<GenContextMenu> qvtContexts = actualGenEditor.getContextMenus();
@@ -381,8 +382,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenDiagramAttributes() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenDiagram baseDiagram = expectedGenEditor.getDiagram();
GenDiagram qvtDiagram = actualGenEditor.getDiagram();
@@ -391,8 +392,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenExpressionProviderContainer() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
GenExpressionProviderContainer baseExpr = expectedGenEditor.getExpressionProviders();
GenExpressionProviderContainer qvtExpr = actualGenEditor.getExpressionProviders();
@@ -418,8 +419,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenCompartments() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
EList<GenCompartment> expected = expectedGenEditor.getDiagram().getCompartments();
EList<GenCompartment> actual = actualGenEditor.getDiagram().getCompartments();
@@ -432,8 +433,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenDiagramBehaviour() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
EList<Behaviour> expected = expectedGenEditor.getDiagram().getBehaviour();
EList<Behaviour> actual = actualGenEditor.getDiagram().getBehaviour();
@@ -446,8 +447,8 @@ public abstract class QvtTransformCompareAbstractTest extends QvtTransformCompar
}
public void testGenDiagramAssistantNodes() {
- GenEditorGenerator expectedGenEditor = executeBaseTransformation();
- GenEditorGenerator actualGenEditor = executeQvtTransformation();
+ GenEditorGenerator expectedGenEditor = expectedGenerator;
+ GenEditorGenerator actualGenEditor = actualGenerator;
EList<GenNode> expected = expectedGenEditor.getDiagram().getAssistantNodes();
EList<GenNode> actual = actualGenEditor.getDiagram().getAssistantNodes();
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareTestSupport.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareTestSupport.java
index f2a5da1..9c136d1 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareTestSupport.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformCompareTestSupport.java
@@ -1,18 +1,16 @@
/*******************************************************************************
-* Copyright (c) 2011, 2012 Montages A.G.
-* 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:
-* Guillaume Hillairet (Montages A.G.) : initial implementation
-*******************************************************************************/
+ * Copyright (c) 2011, 2012 Montages A.G.
+ * 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:
+ * Guillaume Hillairet (Montages A.G.) : initial implementation
+ *******************************************************************************/
package org.eclipse.gmf.tests.tr;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -20,8 +18,10 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -40,14 +40,29 @@ import org.eclipse.gmf.codegen.gmfgen.GenNavigatorChildReference;
import org.eclipse.gmf.codegen.gmfgen.GenParserImplementation;
import org.eclipse.gmf.codegen.gmfgen.LabelModelFacet;
import org.eclipse.gmf.codegen.gmfgen.ValueExpression;
+import org.eclipse.gmf.gmfgraph.Canvas;
+import org.eclipse.gmf.graphdef.codegen.MapModeCodeGenStrategy;
+import org.eclipse.gmf.internal.bridge.StatefulVisualIdentifierDispencer;
+import org.eclipse.gmf.internal.bridge.genmodel.BasicDiagramRunTimeModelHelper;
+import org.eclipse.gmf.internal.bridge.genmodel.DiagramGenModelTransformer;
+import org.eclipse.gmf.internal.bridge.genmodel.DiagramRunTimeModelHelper;
+import org.eclipse.gmf.internal.bridge.genmodel.GenModelProducer;
+import org.eclipse.gmf.internal.bridge.genmodel.InnerClassViewmapProducer;
+import org.eclipse.gmf.internal.bridge.genmodel.ModeledViewmapProducer;
+import org.eclipse.gmf.internal.bridge.genmodel.QVTDiagramGenModelTransformer;
+import org.eclipse.gmf.internal.bridge.genmodel.ViewmapProducer;
import org.eclipse.gmf.internal.bridge.transform.GenModelDetector;
import org.eclipse.gmf.internal.bridge.transform.TransformToGenModelOperation;
+import org.eclipse.gmf.internal.bridge.transform.VisualIdentifierDispenserProvider;
import org.eclipse.gmf.internal.common.URIUtil;
import org.eclipse.gmf.mappings.Mapping;
import org.eclipse.gmf.tests.ConfiguredTestCase;
+import org.eclipse.m2m.qvt.oml.BasicModelExtent;
+import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
+import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase {
-
+
protected static String FOLDER_MODELS = "models"; //$NON-NLS-1$
protected static String FILE_BASE = "test"; //$NON-NLS-1$
protected static String FILE_EXT_ECORE = "ecore"; //$NON-NLS-1$
@@ -55,16 +70,24 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
protected static String FILE_EXT_GMFGRAPH = "gmfgraph"; //$NON-NLS-1$
protected static String FILE_EXT_GMFMAP = "gmfmap"; //$NON-NLS-1$
protected static String FILE_EXT_GMFTOOL = "gmftool"; //$NON-NLS-1$
-
+
protected IProject myProject;
-
+
protected static String testFolder = "platform:/plugin/org.eclipse.gmf.tests/models/tests"; //$NON-NLS-1$
+
+ protected String emf_model_uri;
+ protected String gen_model_uri;
+ protected String tool_model_uri;
+ protected String graph_model_uri;
+ protected String map_model_uri;
+
+ protected final ResourceSet resourceSet = new ResourceSetImpl();
+ protected Mapping mapping;
+ private GenModel genModel;
- private String emf_model_uri;
- private String gen_model_uri;
- private String tool_model_uri;
- private String graph_model_uri;
- private String map_model_uri;
+ protected URI traceURI;
+ protected VisualIdentifierDispenserProvider provider;
+ private Canvas canvas;
public QvtTransformCompareTestSupport(String name, String ecoreFile, String genFile, String toolFile, String graphFile, String mapFile) {
super(name);
@@ -74,11 +97,19 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
graph_model_uri = graphFile;
map_model_uri = mapFile;
}
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
myProject = createProject();
+ this.traceURI = URI.createURI(myProject.getFile("test.trace").getFullPath().toString());
+ prepareResources();
+ this.genModel = loadGenModel();
+ this.canvas = loadCanvas();
+ this.mapping = loadMapping();
+
+ provider = new VisualIdentifierDispenserProvider(traceURI);
+ provider.acquire();
}
@Override
@@ -88,110 +119,174 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
super.tearDown();
}
- protected void prepareResources() throws IOException {
- ResourceSet rs = new ResourceSetImpl();
- Resource emf = rs.createResource(URI.createURI(emf_model_uri));
- emf.load(null);
- Resource tool = rs.createResource(URI.createURI(tool_model_uri));
- tool.load(null);
- Resource graph = rs.createResource(URI.createURI(graph_model_uri));
- graph.load(null);
- Resource map = rs.createResource(URI.createURI(map_model_uri));
- map.load(null);
- }
-
- protected GenEditorGenerator executeBaseTransformation() {
+ protected Mapping loadMapping() {
+ Resource map = resourceSet.createResource(URI.createURI(map_model_uri));
try {
- prepareResources();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
-
- TransformToGenModelOperation operation = new TransformToGenModelOperation(new ResourceSetImpl());
- loadMappingModel(URI.createURI(map_model_uri), operation);
- operation.getGenModelDetector().detect();
-
- try {
- operation.loadGenModel(URI.createURI(gen_model_uri), null);
- } catch (CoreException e) {
+ map.load(null);
+ } catch (IOException e) {
e.printStackTrace();
}
- operation.setGenURI(createURI(FILE_EXT_GMFGEN));
-
- IStatus status = operation.executeTransformation(null);
- assertTrue(status.getMessage(), status.isOK());
-
- GenEditorGenerator genEditor = (GenEditorGenerator) operation.getResourceSet().getResource(
- operation.getGenURI(), true).getContents().get(0);
-
- assertNotNull(genEditor);
- genEditor.eResource().setURI(genEditor.eResource().getURI().trimFileExtension().appendFileExtension("java.gmfgen"));
+
+ assertEquals(1, map.getContents().size());
+ EObject root = map.getContents().get(0);
+ assertTrue(root instanceof Mapping);
+
+ return (Mapping) root;
+ }
+
+ protected Mapping getMapping() {
+ return mapping;
+ }
+
+ protected Canvas loadCanvas() {
+ Resource graph = resourceSet.createResource(URI.createURI(graph_model_uri));
try {
- genEditor.eResource().save(null);
+ graph.load(null);
} catch (IOException e) {
e.printStackTrace();
}
-
- return genEditor;
+ assertEquals(1, graph.getContents().size());
+ EObject root = graph.getContents().get(0);
+ assertTrue(root instanceof Canvas);
+
+ return (Canvas) root;
}
- protected GenEditorGenerator executeQvtTransformation() {
- return executeQvtTransformation(false, true);
+ protected Canvas getCanvas() {
+ return canvas;
}
- protected GenEditorGenerator executeQvtTransformation(boolean rcp, boolean useCodeGen) {
+ protected GenModel loadGenModel() {
+ Resource gen = resourceSet.createResource(URI.createURI(this.gen_model_uri));
try {
- prepareResources();
- } catch (IOException e1) {
- e1.printStackTrace();
+ gen.load(null);
+ } catch (IOException e) {
+ e.printStackTrace();
}
-
- TransformToGenModelOperation operation = new TransformToGenModelOperation(new ResourceSetImpl());
- loadMappingModel(URI.createURI(map_model_uri), operation);
- operation.getGenModelDetector().detect();
- try {
- operation.loadGenModel(URI.createURI(gen_model_uri), null);
- } catch (CoreException e1) {
- e1.printStackTrace();
- }
-
- String pathName = getProject().getName() +
- IPath.SEPARATOR + FOLDER_MODELS +
- IPath.SEPARATOR + "test.gmfgen"; //$NON-NLS-1$
-
- URI uri = URI.createPlatformResourceURI(pathName, true);
-
- operation.setGenURI(uri);
- operation.getOptions().setUseMapMode(true);
- operation.getOptions().setUseRuntimeFigures(false);
- operation.getOptions().setGenerateRCP(rcp);
- operation.getOptions().setInTransformationCodeGen(useCodeGen);
-
- try {
- operation.getOptions().setTransformation(new URL(
- URI.createURI("platform:/plugin/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto").toString()));
- } catch (MalformedURLException e) {
- e.printStackTrace();
+ assertEquals(1, gen.getContents().size());
+ EObject root = gen.getContents().get(0);
+ assertTrue(root instanceof GenModel);
+
+ return (GenModel) root;
+ }
+
+ protected GenModel getGenModel() {
+ return this.genModel;
+ }
+
+ protected void prepareResources() throws IOException {
+ Resource emf = resourceSet.createResource(URI.createURI(emf_model_uri));
+ emf.load(null);
+ Resource tool = resourceSet.createResource(URI.createURI(tool_model_uri));
+ tool.load(null);
+ Resource graph = resourceSet.createResource(URI.createURI(graph_model_uri));
+ graph.load(null);
+ Resource map = resourceSet.createResource(URI.createURI(map_model_uri));
+ map.load(null);
+ }
+
+ protected abstract class Transformation {
+ protected GenEditorGenerator editor;
+ protected StatefulVisualIdentifierDispencer dispenser;
+ public GenEditorGenerator getEditor() {
+ return editor;
}
-
- IStatus status = operation.executeTransformation(null);
- assertTrue(status.getMessage(), status.isOK());
-
- GenEditorGenerator genEditor = (GenEditorGenerator) operation.getResourceSet().getResource(
- operation.getGenURI(), true).getContents().get(0);
-
- assertNotNull(genEditor);
- genEditor.eResource().setURI(genEditor.eResource().getURI().trimFileExtension().appendFileExtension("qvt.gmfgen"));
- try {
- genEditor.eResource().save(null);
- } catch (IOException e) {
- e.printStackTrace();
+ public abstract GenEditorGenerator execute();
+ public StatefulVisualIdentifierDispencer getDispencer() {return dispenser;}
+ public void saveGenEditor(String type) {
+ GenEditorGenerator editor = getEditor();
+ Resource resource = resourceSet.createResource(traceURI.trimFileExtension().appendFileExtension(type+".gmfgen"));
+ resource.getContents().add(editor);
+ try {
+ resource.save(null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
-
- return genEditor;
}
+ protected Transformation getJavaTransformation(final boolean useModeledViewmap) {
+ return new Transformation() {
+ @Override
+ public GenEditorGenerator execute() {
+ VisualIdentifierDispenserProvider provider = new VisualIdentifierDispenserProvider(
+ traceURI.trimFileExtension().appendFileExtension("java.gmfgen"));
+ provider.acquire();
+ dispenser = (StatefulVisualIdentifierDispencer) provider.get();
+ GenModelProducer producer = getJavaGenModelProducer(useModeledViewmap, getGenModel(), provider);
+ try {
+ editor = producer.process(getMapping(), null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return editor;
+ }
+ };
+ }
+
+ protected Transformation getQvtTransformation(final boolean useModeledViewmap) {
+ return new Transformation() {
+ @Override
+ public GenEditorGenerator execute() {
+ VisualIdentifierDispenserProvider provider = new VisualIdentifierDispenserProvider(
+ traceURI.trimFileExtension().appendFileExtension("qvt.gmfgen"));
+ provider.acquire();
+ dispenser = (StatefulVisualIdentifierDispencer) provider.get();
+ GenModelProducer producer = getQvtGenModelProducer(useModeledViewmap, getGenModel(), provider);
+ try {
+ editor = producer.process(getMapping(), null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return editor;
+ }
+ };
+ }
+
+ protected GenModelProducer getJavaGenModelProducer(boolean useModeledViewmap, final GenModel genModel, VisualIdentifierDispenserProvider idDespenser) {
+ MapModeCodeGenStrategy mmStrategy = MapModeCodeGenStrategy.DYNAMIC;
+ ViewmapProducer viewmapProducer = useModeledViewmap ? new ModeledViewmapProducer() : new InnerClassViewmapProducer("full", mmStrategy, null);
+
+ final DiagramRunTimeModelHelper drtModelHelper = new BasicDiagramRunTimeModelHelper();
+ DiagramGenModelTransformer.Parameters opts = new DiagramGenModelTransformer.Parameters(
+ drtModelHelper, viewmapProducer, idDespenser.get(), false);
+ final DiagramGenModelTransformer t = new DiagramGenModelTransformer(opts);
+
+ t.setEMFGenModel(genModel);
+
+ return new GenModelProducer() {
+
+ public GenEditorGenerator process(Mapping mapping, IProgressMonitor progress) {
+ t.transform(mapping);
+ return t.getResult();
+ }
+ };
+ }
+
+ protected GenModelProducer getQvtGenModelProducer(boolean useModeledViewmap, final GenModel genModel, VisualIdentifierDispenserProvider idDespenser) {
+ final ExecutionContextImpl context = new ExecutionContextImpl();
+ context.setConfigProperty("rcp", false);
+ context.setConfigProperty("useMapMode", false);
+ context.setConfigProperty("useFullRunTime", false);
+ context.setConfigProperty("useInTransformationCodeGen", !useModeledViewmap);
+
+ final QVTDiagramGenModelTransformer transformer = new QVTDiagramGenModelTransformer(resourceSet, idDespenser.get());
+
+ return new GenModelProducer() {
+ public GenEditorGenerator process(Mapping mapping, IProgressMonitor progress) throws CoreException {
+ final BasicModelExtent output = new BasicModelExtent();
+ final ExecutionDiagnostic result = transformer.transform(mapping, genModel, output, context);
+
+ if(result.getSeverity() == Diagnostic.OK) {
+ List<EObject> outObjects = output.getContents();
+ return outObjects.get(0) instanceof GenEditorGenerator ? (GenEditorGenerator) outObjects.get(0) : null;
+ }
+ return null;
+ }
+ };
+ }
+
protected void deleteProject() throws CoreException {
if (getProject() != null) {
if (getProject().isOpen()) {
@@ -244,7 +339,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
assertNotNull("GenModelDetector should be initialized", gmd);
genmodelURI = gmd.createDefault(getProject().getName(), URIUtil.getFile(mapURI));
assertNotNull("GenModel URI should be created", genmodelURI);
-
+
IFile file = URIUtil.getFile(mapURI);
assertNotNull("GenModel file should be created", file);
assertTrue("GenModel file should exists", file.exists());
@@ -264,10 +359,10 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
graph.load(null);
Resource map = rs.createResource(URI.createURI(baseURI+".gmfmap"));
map.load(null);
-
+
return URI.createURI(baseURI+".gmfmap");
}
-
+
protected URI createURI(String extension) {
String pathName = getProject().getName() +
IPath.SEPARATOR + FOLDER_MODELS +
@@ -275,7 +370,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
URI uri = URI.createPlatformResourceURI(pathName, true);
return uri;
}
-
+
protected GenChildNode getChildNodeByVisualID(int visualID, EList<GenChildNode> child) {
for (GenChildNode node: child) {
if (visualID == node.getVisualID()) {
@@ -284,32 +379,32 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return null;
}
-
+
protected void checkObjectAttributes(EObject expected, EObject actual) {
if (expected == null) {
assertNull(actual);
return;
}
-
+
assertNotNull(actual);
-
+
for (EAttribute attr: expected.eClass().getEAllAttributes()) {
if (expected.eIsSet(attr)) {
-
+
assertTrue("attribute "+expected.eClass().getName()+"."+attr.getName()+" should be set", actual.eIsSet(attr));
-
+
if (attr.isMany()) {
List<?> exp = (List<?>) expected.eGet(attr);
List<?> act = (List<?>) actual.eGet(attr);
assertEquals(exp.size(), act.size());
-
+
for (int i=0; i<exp.size(); i++) {
assertTrue(act.contains(exp.get(i)));
}
} else {
assertEquals(expected.eClass().getName()+" attribute: "+attr.getName(), expected.eGet(attr), actual.eGet(attr));
}
-
+
} else {
assertFalse("attribute "+attr.getName()+" should not be set", actual.eIsSet(attr));
}
@@ -321,9 +416,9 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
assertNull(actual);
return;
}
-
+
assertNotNull(actual);
-
+
for (EReference ref: expected.eClass().getEAllReferences()) {
if (ref.isMany()) {
@SuppressWarnings("unchecked")
@@ -332,7 +427,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
EList<EObject> actualObjects = (EList<EObject>) actual.eGet(ref);
assertEquals(expected.eClass().getName()+" number of elements in: " + ref.getName(), expectedObjects.size(), actualObjects.size());
-
+
for (int i=0;i<expectedObjects.size();i++) {
if (ref.isContainment()) {
checkObjectAttributes(expectedObjects.get(i), actualObjects.get(i));
@@ -342,7 +437,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
} else {
EObject exp = (EObject) expected.eGet(ref);
EObject act = (EObject) actual.eGet(ref);
-
+
if (ref.isContainment()) {
checkObjectAttributes(exp, act);
checkContainedObjects(exp, act);
@@ -350,7 +445,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
}
}
-
+
protected GenExpressionProviderBase findGenExpressionProviderBase(GenExpressionProviderBase exp, EList<GenExpressionProviderBase> actuals) {
for (GenExpressionProviderBase actual: actuals) {
if (checkValueExpressions(exp.getExpressions(), actual.getExpressions()))
@@ -358,7 +453,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return null;
}
-
+
protected ValueExpression findValueExpression(ValueExpression expected, EList<ValueExpression> actuals) {
for (ValueExpression actual: actuals) {
if (actual.getBody().equals(expected.getBody()) && actual.getBodyString().equals(expected.getBodyString())) {
@@ -367,7 +462,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return null;
}
-
+
protected boolean checkValueExpressions(EList<ValueExpression> expected, EList<ValueExpression> actual) {
if (expected.size() == actual.size()) {
boolean find = true;
@@ -380,12 +475,12 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return false;
}
-
+
protected GenNavigatorChildReference findSameChildReference(GenNavigatorChildReference expected, EList<GenNavigatorChildReference> actuals, EList<GenNavigatorChildReference> found) {
for (GenNavigatorChildReference actual: actuals) {
-
+
if (expected.getChild().getVisualID() == actual.getChild().getVisualID()) {
-
+
if (expected.getParent() == null) {
assertNull(actual.getParent());
if (!found.contains(actual))
@@ -401,7 +496,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return null;
}
-
+
protected GenAuditContext findActualCtx(GenAuditContext expected, EList<GenAuditContext> actuals) {
for (GenAuditContext actual: actuals) {
if (actual.getId().equals(expected.getId())) {
@@ -410,7 +505,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return null;
}
-
+
protected GenParserImplementation findParserImpl(GenParserImplementation expectImpl, EList<GenParserImplementation> actuals) {
for (GenParserImplementation actual: actuals) {
if (actual.eClass().equals(expectImpl.eClass())) {
@@ -427,7 +522,7 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
private boolean findLabelModelFacet(LabelModelFacet facet, EList<LabelModelFacet> uses) {
GenCommonBase expected = (GenCommonBase)facet.eContainer();
-
+
if (uses.isEmpty()) return false;
for (LabelModelFacet f: uses) {
if (f.eContainer() instanceof GenCommonBase) {
@@ -437,5 +532,5 @@ public abstract class QvtTransformCompareTestSupport extends ConfiguredTestCase
}
return false;
}
-
+
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformModeledViewmapTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformModeledViewmapTest.java
index f5bbf61..ec2be4c 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformModeledViewmapTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/QvtTransformModeledViewmapTest.java
@@ -38,7 +38,7 @@ public class QvtTransformModeledViewmapTest extends QvtTransformCompareTestSuppo
public void setUp() throws Exception {
super.setUp();
- actualGenerator = executeQvtTransformation(false, false);
+ actualGenerator = getQvtTransformation(true).execute();
}
public void testTopNodeModeledViewmap() {
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/TransformToGenModelOperationTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/TransformToGenModelOperationTest.java
index 380556d..25c9ee7 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/TransformToGenModelOperationTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/tr/TransformToGenModelOperationTest.java
@@ -154,27 +154,7 @@ public class TransformToGenModelOperationTest extends ConfiguredTestCase {
IStatus status = myOperation.executeTransformation(null);
assertTrue(status.isOK());
}
-
- public void testMainTransformationWithQVTO() throws Exception {
- URI mapURI = prepareResources();
- loadMappingModel(mapURI);
- // GenModelDetector#detect() should be invoked prior to #createDefaultGenModel()
- myOperation.getGenModelDetector().detect();
- myOperation.loadGenModel(createDefaultGenModel(mapURI), null);
- myOperation.setGenURI(createURI(FILE_EXT_GMFGEN));
- //
- myOperation.getOptions().setUseMapMode(false);
- myOperation.getOptions().setUseRuntimeFigures(false);
- myOperation.getOptions().setGenerateRCP(true);
- myOperation.getOptions().setTransformation(new URL(URI.createURI("platform:/plugin/org.eclipse.gmf.tests/transforms/Map2Gen.qvto").toString()));
- //
- IStatus status = myOperation.executeTransformation(null);
- assertTrue(status.getMessage(), status.isOK());
- GenEditorGenerator result = (GenEditorGenerator) myOperation.getResourceSet().getResource(myOperation.getGenURI(), true).getContents().get(0);
- assertEquals("FROM QVTO TRANSFORMATION", result.getCopyrightText());
- assertEquals("truefalsefalse", result.getModelID());
- }
-
+
public void testPreReconcileHookOption() throws Exception {
URI mapURI = prepareResources();
loadMappingModel(mapURI);