Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbblajer2009-01-14 14:13:02 +0000
committerbblajer2009-01-14 14:13:02 +0000
commit75c7fa1a125de7ab72d524957e16418b491e0c48 (patch)
treea4286085de7f5631758c294fae33859ceefa71ce /plugins/org.eclipse.gmf.graphdef.codegen
parent0ce60b56ca6d5dcc506cc6602b5e39de2263389c (diff)
downloadorg.eclipse.gmf-tooling-75c7fa1a125de7ab72d524957e16418b491e0c48.tar.gz
org.eclipse.gmf-tooling-75c7fa1a125de7ab72d524957e16418b491e0c48.tar.xz
org.eclipse.gmf-tooling-75c7fa1a125de7ab72d524957e16418b491e0c48.zip
Migrate graphdef templates to the new mechanism of stream access.
Diffstat (limited to 'plugins/org.eclipse.gmf.graphdef.codegen')
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java45
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/templates.migrated/Util.qvto3
2 files changed, 17 insertions, 31 deletions
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
index 2df3e3fd0..5fc00acda 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/FigureGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006, 2007 Borland Software Corporation
+ * Copyright (c) 2006, 2009 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
@@ -14,8 +14,6 @@ package org.eclipse.gmf.graphdef.codegen;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EcorePackage;
@@ -33,19 +31,16 @@ import org.eclipse.gmf.internal.xpand.util.ContextFactory;
public class FigureGenerator implements TextEmitter {
private static final String VAR_MM_ACCESS = "mapModeAccessor";
- private static final String VAR_OUTPUT_FIELDS = "outputStaticFields";
private static final String VAR_RT_TOKEN = "runtimeToken";
- private static final String SLOT_FIELDS = "staticFields";
+ private final ResourceManager resourceManager;
- private final XpandFacade xpandFacade;
+ private final StringBuilder result = new StringBuilder();
- private final StringBuilder result;
+ private final ArrayList<Variable> globals = new ArrayList<Variable>();
private final boolean myIsInnerClassCode;
- private StringBuilder additionalFields;
-
private String packageStatement;
@@ -70,26 +65,13 @@ public class FigureGenerator implements TextEmitter {
throw new IllegalArgumentException("Can't use map mode accessor with identity map mode");
}
}
- final ArrayList<Variable> globals = new ArrayList<Variable>();
if (mapModeStrategy == MapModeCodeGenStrategy.DYNAMIC) {
globals.add(new Variable(VAR_MM_ACCESS, EcorePackage.eINSTANCE.getEString(), mapModeAccessor == null ? "" : mapModeAccessor));
}
if (runtimeToken != null) {
globals.add(new Variable(VAR_RT_TOKEN, EcorePackage.eINSTANCE.getEString(), runtimeToken));
}
- additionalFields = new StringBuilder();
- globals.add(new Variable(VAR_OUTPUT_FIELDS, EcorePackage.eINSTANCE.getEString(), "") {
- public Object getValue() {
- return additionalFields.toString();
- }
- });
- result = new StringBuilder(200);
- Map<String, StringBuilder> slots = new HashMap<String, StringBuilder>();
- slots.put(SLOT_FIELDS, additionalFields);
- BufferOutput bufferOutput = new BufferOutput(result, slots);
-
- ResourceManager resourceManager = Activator.createResourceEngine(mapModeStrategy, dynamicTemplates);
- xpandFacade = new XpandFacade(ContextFactory.createXpandContext(resourceManager, bufferOutput, globals, getClass().getClassLoader()));
+ resourceManager = Activator.createResourceEngine(mapModeStrategy, dynamicTemplates);
}
public String getPackageName() {
@@ -97,9 +79,7 @@ public class FigureGenerator implements TextEmitter {
}
public String fqnSwitch(Figure figure) {
- result.setLength(0);
- additionalFields.setLength(0);
- xpandFacade.evaluate("Runtime::fqn", figure, null);
+ xpandFacade().evaluate("Runtime::fqn", figure, null);
return result.toString();
}
@@ -108,16 +88,21 @@ public class FigureGenerator implements TextEmitter {
* @param figure
*/
public String go(FigureDescriptor figure) {
- result.setLength(0);
- additionalFields.setLength(0);
if (myIsInnerClassCode) {
- xpandFacade.evaluate("top::Descriptor::Inner", figure, null);
+ xpandFacade().evaluate("top::Descriptor::Inner", figure, null);
} else {
- xpandFacade.evaluate("top::Descriptor::Top", figure, new Object[] { packageStatement });
+ xpandFacade().evaluate("top::Descriptor::Top", figure, new Object[] { packageStatement });
}
return result.toString();
}
+ private XpandFacade xpandFacade() {
+ result.setLength(0);
+ BufferOutput bufferOutput = new BufferOutput(result);
+
+ return new XpandFacade(ContextFactory.createXpandContext(resourceManager, bufferOutput, globals));
+ }
+
public String generate(IProgressMonitor monitor, Object[] arguments) throws InterruptedException, InvocationTargetException, UnexpectedBehaviourException {
if (arguments == null || arguments.length != 1 || false == arguments[0] instanceof FigureDescriptor) {
throw new UnexpectedBehaviourException("(FigureDescriptor) expected as arguments, not " + arguments);
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/templates.migrated/Util.qvto b/plugins/org.eclipse.gmf.graphdef.codegen/templates.migrated/Util.qvto
index eee24c2d8..1cdd73c7c 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/templates.migrated/Util.qvto
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/templates.migrated/Util.qvto
@@ -1,4 +1,5 @@
import xpt.GlobalVarOperations;
+import xpt.StreamOperations;
import xpt.StringOperations;
modeltype graphicalDefinition uses "http://www.eclipse.org/gmf/2006/GraphicalDefinition";
@@ -34,7 +35,7 @@ helper requiredBundles(referencedBundles : Sequence(String)) : Sequence(String)
}
helper additionalStaticFields() : String {
-return xpandGetStringGlobalVar('outputStaticFields')
+return if xpandGetStreamNames()->includes('staticFields') then xpandGetStreamContents('staticFields') else '' endif
}
helper hasTargetDecoration(figure : graphicalDefinition::PolylineConnection) : Boolean {

Back to the top