فهرست منبع

Share project "org.yakindu.sct.generator.core" into "https://svn.codespot.com/a/eclipselabs.org/yakindu"

Andreas Mülder 14 سال پیش
والد
کامیت
c52b7aed0e

+ 7 - 0
plugins/org.yakindu.sct.generator.core/.classpath

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 28 - 0
plugins/org.yakindu.sct.generator.core/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.generator.core</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 8 - 0
plugins/org.yakindu.sct.generator.core/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,8 @@
+#Wed Nov 09 14:23:22 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

+ 22 - 0
plugins/org.yakindu.sct.generator.core/META-INF/MANIFEST.MF

@@ -0,0 +1,22 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Generator Core Plugin
+Bundle-SymbolicName: org.yakindu.sct.generator.core;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.yakindu.sct.generator.core.GeneratorActivator
+Bundle-Vendor: YAKINDU
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.yakindu.sct.model.sgen;bundle-version="1.0.0";visibility:=reexport,
+ org.yakindu.sct.model.sexec;bundle-version="1.0.0";visibility:=reexport,
+ org.eclipse.xpand;bundle-version="1.1.0",
+ org.eclipse.core.resources;bundle-version="3.7.100",
+ org.eclipse.xtend;bundle-version="1.1.0",
+ org.eclipse.xtend.typesystem.emf;bundle-version="1.0.1",
+ org.yakindu.sct.model.stext;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: org.yakindu.sct.generator.core,
+ org.yakindu.sct.generator.core.extensions,
+ org.yakindu.sct.generator.core.features,
+ org.yakindu.sct.generator.core.impl

+ 5 - 0
plugins/org.yakindu.sct.generator.core/build.properties

@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml

+ 7 - 0
plugins/org.yakindu.sct.generator.core/library/FeatureTypeLibrary.xmi

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="ASCII"?>
+<sgen:FeatureTypeLibrary xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sgen="http://www.yakindu.org/sct/statechart/SGen" xsi:schemaLocation="http://www.yakindu.org/sct/statechart/SGen ../../org.yakindu.sct.model.sgen/model/emf/sgen.ecore">
+  <types name="OutletFeature">
+    <parameters name="targetProject"/>
+    <parameters name="targetFolder"/>
+  </types>
+</sgen:FeatureTypeLibrary>

+ 12 - 0
plugins/org.yakindu.sct.generator.core/plugin.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension-point id="org.yakindu.sct.generator.core" name="SCT Generator" schema="schema/generator.exsd"/>
+ <extension
+         point="org.yakindu.sct.generator.genmodel.featuretypes">
+      <FeatureLibrary
+            generatorId="ALL"
+            uri="platform:/plugin/org.yakindu.sct.generator.core/library/FeatureTypeLibrary.xmi">
+      </FeatureLibrary>
+   </extension>
+</plugin>

+ 133 - 0
plugins/org.yakindu.sct.generator.core/schema/generator.exsd

@@ -0,0 +1,133 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.yakindu.sct.generator.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.yakindu.sct.generator.core" id="org.yakindu.sct.generator.core.generator" name="Generator"/>
+      </appinfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence>
+            <element ref="SCTGenerator"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="SCTGenerator">
+      <complexType>
+         <attribute name="class" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="java" basedOn=":org.yakindu.sct.generator.base.ISCTGenerator"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+         <attribute name="icon" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute kind="resource"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="description" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>

+ 50 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/GeneratorActivator.java

@@ -0,0 +1,50 @@
+package org.yakindu.sct.generator.core;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class GeneratorActivator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.yakindu.sct.generator.core"; //$NON-NLS-1$
+
+	// The shared instance
+	private static GeneratorActivator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public GeneratorActivator() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static GeneratorActivator getDefault() {
+		return plugin;
+	}
+
+}

+ 29 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/ISCTGenerator.java

@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.core;
+
+import org.yakindu.sct.model.sgen.GeneratorEntry;
+import org.yakindu.sct.model.sgen.GeneratorModel;
+
+/**
+ * Basic interface for all CodeGenerators
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public interface ISCTGenerator {
+	/**
+	 * 
+	 * @param entry
+	 *            The {@link GeneratorEntry} from the {@link GeneratorModel}
+	 */
+	public void generate(GeneratorEntry entry);
+}

+ 105 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/extensions/GeneratorExtensions.java

@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.core.extensions;
+
+import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Lists.newArrayList;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.graphics.Image;
+import org.yakindu.sct.generator.core.ISCTGenerator;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * @author holger willebrandt - Initial contribution and API
+ */
+public class GeneratorExtensions {
+
+	private static final String EXTENSION_POINT_ID = "org.yakindu.sct.generator.core";
+	private static final String ATTRIBUTE_CLASS = "class";
+	private static final String ATTRIBUTE_ID = "id";
+	private static final String ATTRIBUTE_NAME = "name";
+	@SuppressWarnings("unused")
+	private static final String ATTRIBUTE_ICON = "icon";
+
+	private static Iterable<GeneratorDescriptor> generatorDescriptors;
+
+	public static class GeneratorDescriptor {
+		private final IConfigurationElement configElement;
+
+		GeneratorDescriptor(IConfigurationElement configElement) {
+			this.configElement = configElement;
+		}
+
+		public ISCTGenerator createGenerator() {
+			try {
+				return (ISCTGenerator) configElement
+						.createExecutableExtension(ATTRIBUTE_CLASS);
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+			return null;
+		}
+
+		public String getId() {
+			return configElement.getAttribute(ATTRIBUTE_ID);
+		}
+
+		public String getName() {
+			return configElement.getAttribute(ATTRIBUTE_NAME);
+		}
+
+		public Image getImage() {
+			return null;
+			// TODO
+			// String iconPath = configElement.getAttribute(ATTRIBUTE_ICON);
+			// ImageDescriptor descriptor = ImageDescriptor.createFromFile(
+			// getClass(), iconPath);
+			// return descriptor.createImage();
+		}
+	}
+
+	public static Iterable<GeneratorDescriptor> getGeneratorDescriptors() {
+		IConfigurationElement[] configurationElements = Platform
+				.getExtensionRegistry().getConfigurationElementsFor(
+						EXTENSION_POINT_ID);
+		if (generatorDescriptors == null) {
+			generatorDescriptors = transform(
+					newArrayList(configurationElements),
+					new CreateGeneratorDescriptor());
+		}
+		return generatorDescriptors;
+	}
+
+	public static GeneratorDescriptor getGeneratorDescriptorForId(
+			final String generatorId) {
+		return Iterables.find(getGeneratorDescriptors(),
+				new Predicate<GeneratorDescriptor>() {
+					public boolean apply(GeneratorDescriptor input) {
+						return input.getId().equals(generatorId);
+					}
+				});
+	}
+
+	private static final class CreateGeneratorDescriptor implements
+			Function<IConfigurationElement, GeneratorDescriptor> {
+
+		public GeneratorDescriptor apply(IConfigurationElement from) {
+			return new GeneratorDescriptor(from);
+		}
+	}
+
+}

+ 25 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/features/ICoreFeatureConstants.java

@@ -0,0 +1,25 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.core.features;
+
+/**
+ * Core Feature Constants defined by this plugin
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public interface ICoreFeatureConstants {
+
+	public static final String OUTLET_FEATURE = "OutletFeature";
+	public static final String OUTLET_FEATURE_TARGET_PROJECT = "targetProject";
+	public static final String OUTLET_FEATURE_TARGET_FOLDER = "targetFolder";
+
+}

+ 50 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java

@@ -0,0 +1,50 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.core.impl;
+
+import org.eclipse.core.runtime.Assert;
+import org.yakindu.sct.generator.core.ISCTGenerator;
+import org.yakindu.sct.model.sexec.ExecutionFlow;
+import org.yakindu.sct.model.sexec.transformation.ModelSequencer;
+import org.yakindu.sct.model.sexec.transformation.SequencerModule;
+import org.yakindu.sct.model.sgen.GeneratorEntry;
+import org.yakindu.sct.model.sgraph.Statechart;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+/**
+ * abstract base class for all code generators that want to generate code based
+ * on the {@link ExecutionFlow}
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public abstract class AbstractSExecModelGenerator implements ISCTGenerator {
+
+	protected abstract void generate(ExecutionFlow flow, GeneratorEntry entry);
+
+	public final void generate(GeneratorEntry entry) {
+		generate(createExecutionFlow(entry.getStatechart()), entry);
+	}
+
+	/**
+	 * Transforms the {@link Statechart} model to a {@link ExecutionFlow} model
+	 */
+	protected ExecutionFlow createExecutionFlow(Statechart statechart) {
+		Injector injector = Guice.createInjector(new SequencerModule());
+		ModelSequencer sequencer = injector.getInstance(ModelSequencer.class);
+		ExecutionFlow flow = sequencer.transform(statechart);
+		Assert.isNotNull(flow, "Error creation ExecutionFlow");
+		return flow;
+	}
+
+}

+ 120 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractXpandBasedCodeGenerator.java

@@ -0,0 +1,120 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     committers of YAKINDU - initial API and implementation
+ */
+package org.yakindu.sct.generator.core.impl;
+
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT;
+
+import java.io.File;
+import java.util.Collections;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.xpand2.XpandExecutionContext;
+import org.eclipse.xpand2.XpandExecutionContextImpl;
+import org.eclipse.xpand2.XpandFacade;
+import org.eclipse.xpand2.output.Outlet;
+import org.eclipse.xpand2.output.Output;
+import org.eclipse.xpand2.output.OutputImpl;
+import org.eclipse.xtend.expression.Variable;
+import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
+import org.yakindu.sct.model.sexec.ExecutionFlow;
+import org.yakindu.sct.model.sexec.SexecPackage;
+import org.yakindu.sct.model.sgen.FeatureConfiguration;
+import org.yakindu.sct.model.sgen.FeatureParameterValue;
+import org.yakindu.sct.model.sgen.GeneratorEntry;
+import org.yakindu.sct.model.sgraph.SGraphPackage;
+import org.yakindu.sct.model.stext.stext.StextPackage;
+
+/**
+ * abstract base class for all code generators using Xpand as the template
+ * language.
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public abstract class AbstractXpandBasedCodeGenerator extends
+		AbstractSExecModelGenerator {
+
+	public abstract String getTemplatePath();
+
+	/**
+	 * Invokes XPands template engine to generate resources
+	 */
+	@Override
+	protected final void generate(ExecutionFlow flow, GeneratorEntry entry) {
+		Output output = createOutput(entry);
+		XpandExecutionContext context = createXpandContext(output);
+		XpandFacade facade = XpandFacade.create(context);
+		facade.evaluate(getTemplatePath(), flow);
+		// refresh the project to get external updates:
+		IProject project = getTargetProject(entry);
+		try {
+			project.refreshLocal(IResource.DEPTH_INFINITE,
+					new NullProgressMonitor());
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+	}
+
+	private IProject getTargetProject(GeneratorEntry entry) {
+		FeatureConfiguration outletConfig = getOutletFeatureConfiguration(entry);
+		String projectName = outletConfig.getParameterValue(
+				OUTLET_FEATURE_TARGET_PROJECT).getValue();
+		IProject project = ResourcesPlugin.getWorkspace().getRoot()
+				.getProject(projectName);
+		return project;
+	}
+
+	protected XpandExecutionContext createXpandContext(Output output) {
+		XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(
+				output, null, Collections.<String, Variable> emptyMap(), null,
+				null);
+		EmfRegistryMetaModel metamodel = new EmfRegistryMetaModel() {
+			@Override
+			protected EPackage[] allPackages() {
+				return new EPackage[] { SGraphPackage.eINSTANCE,
+						StextPackage.eINSTANCE, EcorePackage.eINSTANCE,
+						SexecPackage.eINSTANCE };
+			}
+		};
+		execCtx.registerMetaModel(metamodel);
+		return execCtx;
+	}
+
+	protected Output createOutput(GeneratorEntry entry) {
+		FeatureConfiguration outletConfig = getOutletFeatureConfiguration(entry);
+		FeatureParameterValue targetFolder = outletConfig
+				.getParameterValue(OUTLET_FEATURE_TARGET_FOLDER);
+
+		String absoluteTargetFolder = getTargetProject(entry).getLocation()
+				.toOSString() + File.separator + targetFolder.getValue();
+		Output output = new OutputImpl();
+		Outlet outlet = new Outlet(absoluteTargetFolder);
+		outlet.setOverwrite(true);
+		output.addOutlet(outlet);
+		System.out.println("Generating to " + absoluteTargetFolder);
+		return output;
+	}
+
+	protected FeatureConfiguration getOutletFeatureConfiguration(
+			GeneratorEntry entry) {
+		FeatureConfiguration outletConfig = entry
+				.getFeatureConfiguration(OUTLET_FEATURE);
+		return outletConfig;
+	}
+}