Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2007-02-01 13:39:01 +0000
committeratikhomirov2007-02-01 13:39:01 +0000
commit8b4f736516f11246a9ce2c76a5ae4171b80037be (patch)
treeec30a63fbb39b3229af73b46bf1dc86ea1da8825 /plugins/org.eclipse.gmf.graphdef.codegen
parent5835f958fdf1a2ce55e002f1f44797dc3b44cd5c (diff)
downloadorg.eclipse.gmf-tooling-8b4f736516f11246a9ce2c76a5ae4171b80037be.tar.gz
org.eclipse.gmf-tooling-8b4f736516f11246a9ce2c76a5ae4171b80037be.tar.xz
org.eclipse.gmf-tooling-8b4f736516f11246a9ce2c76a5ae4171b80037be.zip
use common XpandTextEmitter
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.java8
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneEmitters.java76
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java9
-rw-r--r--plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/Activator.java25
4 files changed, 45 insertions, 73 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 dc5650870..b9ec7e6ee 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 Borland Software Corporation
+ * Copyright (c) 2006, 2007 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
@@ -24,8 +24,10 @@ import org.eclipse.gmf.gmfgraph.util.FigureQualifiedNameSwitch;
import org.eclipse.gmf.internal.common.codegen.TextEmitter;
import org.eclipse.gmf.internal.graphdef.codegen.Activator;
import org.eclipse.gmf.internal.xpand.BufferOutput;
+import org.eclipse.gmf.internal.xpand.ResourceManager;
import org.eclipse.gmf.internal.xpand.XpandFacade;
import org.eclipse.gmf.internal.xpand.expression.Variable;
+import org.eclipse.gmf.internal.xpand.util.ContextFactory;
public class FigureGenerator implements TextEmitter {
private final XpandFacade xpandFacade;
@@ -75,7 +77,9 @@ public class FigureGenerator implements TextEmitter {
slots.put("additionalMethods", additionalMethods);
slots.put("staticFields", additionalFields);
BufferOutput bufferOutput = new BufferOutput(result, slots);
- xpandFacade = Activator.createTemplateEngine(mapModeStrategy, bufferOutput, globals);
+
+ ResourceManager resourceManager = Activator.createResourceEngine(mapModeStrategy);
+ xpandFacade = new XpandFacade(ContextFactory.createXpandContext(resourceManager, bufferOutput, globals, getClass().getClassLoader()));
}
public String go(Figure figure, ImportAssistant importAssistant) {
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneEmitters.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneEmitters.java
index 54d4eaad2..d1946f83a 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneEmitters.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneEmitters.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006 Borland Software Corporation
+ * Copyright (c) 2006, 2007 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
@@ -12,110 +12,78 @@
*/
package org.eclipse.gmf.graphdef.codegen;
-import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gmf.common.UnexpectedBehaviourException;
import org.eclipse.gmf.graphdef.codegen.StandaloneGenerator.Config;
import org.eclipse.gmf.internal.common.codegen.TextEmitter;
+import org.eclipse.gmf.internal.common.codegen.XpandTextEmitter;
import org.eclipse.gmf.internal.graphdef.codegen.Activator;
-import org.eclipse.gmf.internal.xpand.BufferOutput;
-import org.eclipse.gmf.internal.xpand.XpandFacade;
-import org.eclipse.gmf.internal.xpand.expression.Variable;
+import org.eclipse.gmf.internal.xpand.ResourceManager;
class StandaloneEmitters {
- private final MapModeCodeGenStrategy myMapModeStrategy;
+ private final ResourceManager myResourceManager;
StandaloneEmitters(MapModeCodeGenStrategy mapModeStrategy) {
- myMapModeStrategy = mapModeStrategy;
+ assert mapModeStrategy != null;
+ myResourceManager = Activator.createResourceEngine(mapModeStrategy);
}
public TextEmitter getBuildPropertiesEmitter() throws UnexpectedBehaviourException {
- return new XpandTextEmitter(myMapModeStrategy) {
- public String generate(IProgressMonitor monitor, Object[] arguments) throws InterruptedException, InvocationTargetException, UnexpectedBehaviourException {
- StringBuilder result = new StringBuilder();
- createEngine(result).evaluate("plugin::BuildProperties::Init", new Object(), null);
- return result.toString();
- }
- };
+ return new XpandTextEmitter(myResourceManager, "plugin::BuildProperties::Init", getClass().getClassLoader());
}
public TextEmitter getPluginPropertiesEmitter() throws UnexpectedBehaviourException {
- return new XpandTextEmitter(myMapModeStrategy) {
- public String generate(IProgressMonitor monitor, Object[] arguments) throws InterruptedException, InvocationTargetException, UnexpectedBehaviourException {
+ return new XpandTextEmitter(myResourceManager, "plugin::PluginProperties::Init", getClass().getClassLoader()) {
+ @Override
+ protected Object[] extractArguments(Object[] arguments) {
assert arguments != null && arguments.length > 0 && arguments[0] instanceof Config;
Config config = (Config) arguments[0];
- StringBuilder result = new StringBuilder();
- Object[] params = new Object[] {
+ return new Object[] {
config.getPluginFriendlyName(),
config.getPluginProviderName()
};
- createEngine(result).evaluate("plugin::PluginProperties::Init", new Object(), params);
- return result.toString();
}
};
}
public TextEmitter getManifestMFEmitter() throws UnexpectedBehaviourException {
- return new XpandTextEmitter(myMapModeStrategy) {
- public String generate(IProgressMonitor monitor, Object[] arguments) throws InterruptedException, InvocationTargetException, UnexpectedBehaviourException {
- assert arguments != null && arguments.length > 0 && arguments[0] instanceof Object[];
- Object[] actualArgs = (Object[]) arguments[0];
- assert actualArgs.length > 1 && actualArgs[0] instanceof Config && actualArgs[1] instanceof String[];
- Config config = (Config) actualArgs[0];
+ return new XpandTextEmitter(myResourceManager, "plugin::Manifest::Init", getClass().getClassLoader()) {
+ @Override
+ protected Object[] extractArguments(Object[] arguments) {
+ assert arguments != null && arguments.length > 1 && arguments[0] instanceof Config && arguments[1] instanceof String[];
+ Config config = (Config) arguments[0];
List<String> requiredBundles = new LinkedList<String>();
if (config.needsMapMode()) {
requiredBundles.add("org.eclipse.gmf.runtime.draw2d.ui");
}
- requiredBundles.addAll(Arrays.asList((String[]) actualArgs[1]));
+ requiredBundles.addAll(Arrays.asList((String[]) arguments[1]));
List<String> exportedPackages = (config.getMainPackageName() == null || config.getMainPackageName().trim().length() == 0) ? Collections.singletonList(config.getPluginActivatorPackageName()) : Arrays.asList(config.getPluginActivatorPackageName(), config.getMainPackageName());
- StringBuilder result = new StringBuilder();
- Object[] params = new Object[] {
+ return new Object[] {
config.getPluginID(),
config.getPluginActivatorPackageName() + '.' + config.getPluginActivatorClassName(),
exportedPackages,
requiredBundles,
};
- createEngine(result).evaluate("plugin::Manifest::Init", new Object(), params);
- return result.toString();
}
};
}
public TextEmitter getPluginActivatorEmitter() throws UnexpectedBehaviourException {
- return new XpandTextEmitter(myMapModeStrategy) {
- public String generate(IProgressMonitor monitor, Object[] arguments) throws InterruptedException, InvocationTargetException, UnexpectedBehaviourException {
- // we do not use ImportAssistant argument
+ return new XpandTextEmitter(myResourceManager, "plugin::Activator::Init", getClass().getClassLoader()) {
+ @Override
+ protected Object[] extractArguments(Object[] arguments) {
assert arguments != null && arguments.length > 0 && arguments[0] instanceof Object[];
Config config = (Config) ((Object[]) arguments[0])[0];
- StringBuilder result = new StringBuilder();
- Object[] params = new Object[] {
+ return new Object[] {
config.getPluginActivatorPackageName(),
config.getPluginActivatorClassName(),
config.getPluginID(),
};
- createEngine(result).evaluate("plugin::Activator::Init", new Object(), params);
- return result.toString();
}
};
}
-
- private static abstract class XpandTextEmitter implements TextEmitter {
- protected final MapModeCodeGenStrategy myMapModeStrategy;
-
- protected XpandTextEmitter(MapModeCodeGenStrategy mapModeStrategy) {
- myMapModeStrategy = mapModeStrategy;
- }
-
- protected XpandFacade createEngine(StringBuilder result) {
- final Map<String, StringBuilder> slots = Collections.emptyMap();
- final List<Variable> globals = Collections.emptyList();
- return Activator.createTemplateEngine(myMapModeStrategy, new BufferOutput(result, slots), globals);
- }
- }
}
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java
index 8d85bea67..b8082907b 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/graphdef/codegen/StandaloneGenerator.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006 Borland Software Corporation
+ * Copyright (c) 2006, 2007 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
@@ -175,11 +175,10 @@ public class StandaloneGenerator extends GeneratorBase {
doGenerateJavaClass(myAuxiliaryGenerators.getPluginActivatorEmitter(), myArgs.getPluginActivatorPackageName(), myArgs.getPluginActivatorClassName(), new Object[] {args});
}
- // FIXME do not wrap array of arguments into another array (new Object[] { new Object[] {)
protected void generatePluginStructure() throws UnexpectedBehaviourException, InterruptedException {
- doGenerateFile(myAuxiliaryGenerators.getBuildPropertiesEmitter(), new Path("build.properties"), new Object[] { myArgs });
- doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), new Object[] { new Object[] { myArgs, myProcessor.getRequiredBundles(myFigureNameSwitch) } });
- doGenerateFile(myAuxiliaryGenerators.getPluginPropertiesEmitter(), new Path("plugin.properties"), new Object[] { myArgs });
+ doGenerateFile(myAuxiliaryGenerators.getBuildPropertiesEmitter(), new Path("build.properties"), myArgs);
+ doGenerateFile(myAuxiliaryGenerators.getManifestMFEmitter(), new Path("META-INF/MANIFEST.MF"), myArgs, myProcessor.getRequiredBundles(myFigureNameSwitch));
+ doGenerateFile(myAuxiliaryGenerators.getPluginPropertiesEmitter(), new Path("plugin.properties"), myArgs);
}
private void generateTopLevelFigures() throws InterruptedException {
diff --git a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/Activator.java b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/Activator.java
index 8946c9e52..dbea73765 100644
--- a/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/Activator.java
+++ b/plugins/org.eclipse.gmf.graphdef.codegen/src/org/eclipse/gmf/internal/graphdef/codegen/Activator.java
@@ -1,20 +1,24 @@
+/*
+ * Copyright (c) 2006, 2007 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.internal.graphdef.codegen;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collection;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.gmf.graphdef.codegen.MapModeCodeGenStrategy;
import org.eclipse.gmf.internal.xpand.ResourceManager;
-import org.eclipse.gmf.internal.xpand.XpandFacade;
-import org.eclipse.gmf.internal.xpand.expression.Variable;
-import org.eclipse.gmf.internal.xpand.model.Output;
-import org.eclipse.gmf.internal.xpand.model.XpandExecutionContext;
-import org.eclipse.gmf.internal.xpand.model.XpandExecutionContextImpl;
import org.eclipse.gmf.internal.xpand.util.BundleResourceManager;
-import org.eclipse.gmf.internal.xpand.util.ContextFactory;
import org.osgi.framework.BundleContext;
public class Activator extends Plugin {
@@ -30,7 +34,7 @@ public class Activator extends Plugin {
super.stop(context);
}
- public static XpandFacade createTemplateEngine(MapModeCodeGenStrategy strategy, Output output, Collection<Variable> globals) {
+ public static ResourceManager createResourceEngine(MapModeCodeGenStrategy strategy) {
try {
URL baseURL = instance.getBundle().getEntry("/templates/");
ArrayList<URL> urls = new ArrayList<URL>(3);
@@ -38,10 +42,7 @@ public class Activator extends Plugin {
urls.add(new URL(baseURL, strategy.getToken() + '/'));
}
urls.add(baseURL);
- ResourceManager resourceManager = new BundleResourceManager(urls.toArray(new URL[urls.size()]));
- final XpandExecutionContext xpandContext = ContextFactory.createXpandContext(resourceManager, output, globals);
- ((XpandExecutionContextImpl) xpandContext).setContextClassLoader(instance.getClass().getClassLoader());
- return new XpandFacade(xpandContext);
+ return new BundleResourceManager(urls.toArray(new URL[urls.size()]));
} catch (MalformedURLException ex) {
throw new Error();
}

Back to the top