summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-04 10:09:57 (EDT)
committer Ed Merks2011-08-04 10:09:57 (EDT)
commit8ea97ec14abfcb90c3a38876b51d036ea6a43108 (patch)
treec2171be481443bee5c6db0ac435c9b9fec85a01d
parent4409d8fac35855a6f2978b9608d7f18a354fe940 (diff)
downloadorg.eclipse.emf-8ea97ec14abfcb90c3a38876b51d036ea6a43108.zip
org.eclipse.emf-8ea97ec14abfcb90c3a38876b51d036ea6a43108.tar.gz
org.eclipse.emf-8ea97ec14abfcb90c3a38876b51d036ea6a43108.tar.bz2
first bits for the generator
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/util/AbstractModelSanityTest.java2
-rwxr-xr-xorg.eclipse.emf.ecore.xcore.ui/plugin.xml9
-rw-r--r--org.eclipse.emf.ecore.xcore.ui/plugin.xml_gen7
-rw-r--r--org.eclipse.emf.ecore.xcore.ui/src-gen/org/eclipse/emf/ecore/xcore/ui/AbstractXcoreUiModule.java10
-rw-r--r--org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.emf.ecore.xcore/src-gen/org/eclipse/emf/ecore/xcore/AbstractXcoreRuntimeModule.java5
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/GenerateXcore.mwe25
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend53
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend27
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java79
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java31
11 files changed, 230 insertions, 2 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/util/AbstractModelSanityTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/util/AbstractModelSanityTest.java
index b3c10c2..26955f9 100644
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/util/AbstractModelSanityTest.java
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/util/AbstractModelSanityTest.java
@@ -10,7 +10,7 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.mwe.utils.StandaloneSetup;
import org.eclipse.xtext.diagnostics.ExceptionDiagnostic;
-import org.eclipse.xtext.junit.serializer.SerializerTester;
+import org.eclipse.xtext.junit4.serializer.SerializerTester;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.util.CancelIndicator;
diff --git a/org.eclipse.emf.ecore.xcore.ui/plugin.xml b/org.eclipse.emf.ecore.xcore.ui/plugin.xml
index 1de9b5e..7d6bf0c 100755
--- a/org.eclipse.emf.ecore.xcore.ui/plugin.xml
+++ b/org.eclipse.emf.ecore.xcore.ui/plugin.xml
@@ -199,6 +199,15 @@
</markerResolutionGenerator>
</extension>
+ <extension
+ point="org.eclipse.xtext.builder.participant">
+ <participant
+ class="org.eclipse.emf.ecore.xcore.ui.XcoreExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant">
+ </participant>
+ </extension>
+
+ <-- MANUAL ADDITIONS -->
+
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
diff --git a/org.eclipse.emf.ecore.xcore.ui/plugin.xml_gen b/org.eclipse.emf.ecore.xcore.ui/plugin.xml_gen
index fc68609..5a2b3be 100644
--- a/org.eclipse.emf.ecore.xcore.ui/plugin.xml_gen
+++ b/org.eclipse.emf.ecore.xcore.ui/plugin.xml_gen
@@ -199,5 +199,12 @@
</markerResolutionGenerator>
</extension>
+ <extension
+ point="org.eclipse.xtext.builder.participant">
+ <participant
+ class="org.eclipse.emf.ecore.xcore.ui.XcoreExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant">
+ </participant>
+ </extension>
+
</plugin>
diff --git a/org.eclipse.emf.ecore.xcore.ui/src-gen/org/eclipse/emf/ecore/xcore/ui/AbstractXcoreUiModule.java b/org.eclipse.emf.ecore.xcore.ui/src-gen/org/eclipse/emf/ecore/xcore/ui/AbstractXcoreUiModule.java
index 28ecdd6..ee918ed 100644
--- a/org.eclipse.emf.ecore.xcore.ui/src-gen/org/eclipse/emf/ecore/xcore/ui/AbstractXcoreUiModule.java
+++ b/org.eclipse.emf.ecore.xcore.ui/src-gen/org/eclipse/emf/ecore/xcore/ui/AbstractXcoreUiModule.java
@@ -113,6 +113,16 @@ public abstract class AbstractXcoreUiModule extends DefaultUiModule {
return org.eclipse.emf.ecore.xcore.ui.quickfix.XcoreQuickfixProvider.class;
}
+ // contributed by org.eclipse.xtext.generator.generator.GeneratorFragment
+ public Class<? extends org.eclipse.xtext.builder.IXtextBuilderParticipant> bindIXtextBuilderParticipant() {
+ return org.eclipse.xtext.builder.JavaProjectBasedBuilderParticipant.class;
+ }
+
+ // contributed by org.eclipse.xtext.generator.generator.GeneratorFragment
+ public org.eclipse.core.resources.IWorkspaceRoot bindIWorkspaceRootToInstance() {
+ return org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot();
+ }
+
// contributed by org.eclipse.xtext.generator.types.TypesGeneratorFragment
public java.lang.ClassLoader bindClassLoaderToInstance() {
return getClass().getClassLoader();
diff --git a/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF b/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF
index 3844c81..4945819 100644
--- a/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF
+++ b/org.eclipse.emf.ecore.xcore/META-INF/MANIFEST.MF
@@ -19,7 +19,9 @@ Require-Bundle: org.eclipse.xtext;bundle-version="2.0.0";visibility:=reexport,
org.eclipse.xtext.common.types,
org.eclipse.xtext.xtend2.lib
Import-Package: org.apache.log4j,
- org.apache.commons.logging
+ org.apache.commons.logging,
+ org.eclipse.xtext.xbase.lib,
+ org.eclipse.xtext.xtend2.lib
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.emf.ecore.xcore,
org.eclipse.emf.ecore.xcore.formatting,
diff --git a/org.eclipse.emf.ecore.xcore/src-gen/org/eclipse/emf/ecore/xcore/AbstractXcoreRuntimeModule.java b/org.eclipse.emf.ecore.xcore/src-gen/org/eclipse/emf/ecore/xcore/AbstractXcoreRuntimeModule.java
index b46cf2c..8c6e46e 100644
--- a/org.eclipse.emf.ecore.xcore/src-gen/org/eclipse/emf/ecore/xcore/AbstractXcoreRuntimeModule.java
+++ b/org.eclipse.emf.ecore.xcore/src-gen/org/eclipse/emf/ecore/xcore/AbstractXcoreRuntimeModule.java
@@ -124,6 +124,11 @@ public abstract class AbstractXcoreRuntimeModule extends DefaultRuntimeModule {
binder.bind(org.eclipse.xtext.resource.IResourceDescriptions.class).annotatedWith(com.google.inject.name.Names.named(org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE)).to(org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions.class);
}
+ // contributed by org.eclipse.xtext.generator.generator.GeneratorFragment
+ public Class<? extends org.eclipse.xtext.generator.IGenerator> bindIGenerator() {
+ return org.eclipse.emf.ecore.xcore.generator.XcoreGenerator.class;
+ }
+
// contributed by org.eclipse.xtext.generator.types.TypesGeneratorFragment
public java.lang.ClassLoader bindClassLoaderToInstance() {
return getClass().getClassLoader();
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/GenerateXcore.mwe2 b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/GenerateXcore.mwe2
index d9ce5e3..4c401f3 100644
--- a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/GenerateXcore.mwe2
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/GenerateXcore.mwe2
@@ -122,6 +122,11 @@ Workflow {
// quickfix API
fragment = quickfix.QuickfixProviderFragment {}
+ fragment = generator.GeneratorFragment {
+ generateJavaMain = false
+ generateMwe = false
+ }
+
// Xbase support
fragment = types.TypesGeneratorFragment {}
fragment = xbase.XbaseGeneratorFragment {
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend
new file mode 100644
index 0000000..7ccfbdd
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.xtend
@@ -0,0 +1,53 @@
+/*
+ * generated by Xtext
+ */
+package org.eclipse.emf.ecore.xcore.generator
+
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.xtext.generator.IGenerator
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.emf.ecore.xcore.XPackage
+import com.google.inject.Inject
+import org.eclipse.emf.ecore.xcore.util.MappingFacade
+import org.eclipse.emf.ecore.xcore.XOperation
+import static extension org.eclipse.xtext.xtend2.lib.EObjectExtensions.*
+import org.eclipse.xtext.xbase.compiler.XbaseCompiler
+import org.eclipse.xtext.xbase.compiler.IAppendable
+import org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable
+import org.eclipse.emf.ecore.EcoreFactory
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel
+
+class XcoreGenerator implements IGenerator {
+
+ @Inject
+ extension MappingFacade mappings
+
+ @Inject
+ XbaseCompiler compiler
+
+ override void doGenerate(Resource resource, IFileSystemAccess fsa) {
+ val pack = resource.contents.head as XPackage
+ // install operation bodies
+ for (op : pack.allContentsIterable.filter(typeof(XOperation))) {
+ val eOperation = op.EOperation
+ val appendable = new StringBuilderBasedAppendable()
+ val expectedType = op.jvmOperation.returnType
+ compiler.compile(op.body, appendable, expectedType)
+ eOperation.EAnnotations.add(createGenModelAnnotation("body", appendable.toString))
+ }
+
+ generateGenModel(resource.contents.get(2) as GenModel)
+ }
+
+ def generateGenModel(GenModel genModel) {
+ genModel.gen(null)
+ }
+
+ def createGenModelAnnotation(String key, String value) {
+ val result = EcoreFactory::eINSTANCE.createEAnnotation
+ result.source = GenModelPackage::eNS_URI
+ result.details.put(key, value)
+ return result
+ }
+}
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend
new file mode 100644
index 0000000..ea00eae
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/util/MappingFacade.xtend
@@ -0,0 +1,27 @@
+package org.eclipse.emf.ecore.xcore.util
+
+import org.eclipse.emf.ecore.xcore.XOperation
+import org.eclipse.emf.ecore.EOperation
+import org.eclipse.emf.codegen.ecore.genmodel.GenOperation
+import org.eclipse.xtext.common.types.JvmOperation
+
+class MappingFacade {
+
+ def getEOperation(XOperation op) {
+ XcoreEcoreBuilder::get(op) as EOperation
+ }
+
+ def getGenOperation(XOperation op) {
+ XcoreEcoreBuilder::get(op) as GenOperation
+ }
+
+ def getXOperation(GenOperation op) {
+ XcoreEcoreBuilder::get(op) as GenOperation
+ }
+
+ def JvmOperation getJvmOperation(XOperation op) {
+ null //TODO
+ }
+
+
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java
new file mode 100644
index 0000000..ffc929f
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/generator/XcoreGenerator.java
@@ -0,0 +1,79 @@
+package org.eclipse.emf.ecore.xcore.generator;
+
+import com.google.inject.Inject;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.EMap;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.util.MappingFacade;
+import org.eclipse.xtext.common.types.JvmOperation;
+import org.eclipse.xtext.common.types.JvmTypeReference;
+import org.eclipse.xtext.generator.IFileSystemAccess;
+import org.eclipse.xtext.generator.IGenerator;
+import org.eclipse.xtext.xbase.XBlockExpression;
+import org.eclipse.xtext.xbase.compiler.StringBuilderBasedAppendable;
+import org.eclipse.xtext.xbase.compiler.XbaseCompiler;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xtend2.lib.EObjectExtensions;
+
+@SuppressWarnings("all")
+public class XcoreGenerator implements IGenerator {
+
+ @Inject
+ private MappingFacade mappings;
+
+ @Inject
+ private XbaseCompiler compiler;
+
+ public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
+ {
+ EList<EObject> _contents = resource.getContents();
+ EObject _head = IterableExtensions.<EObject>head(_contents);
+ final XPackage pack = ((XPackage) _head);
+ Iterable<EObject> _allContentsIterable = EObjectExtensions.allContentsIterable(pack);
+ Iterable<XOperation> _filter = IterableExtensions.<XOperation>filter(_allContentsIterable, org.eclipse.emf.ecore.xcore.XOperation.class);
+ for (XOperation op : _filter) {
+ {
+ EOperation _eOperation = this.mappings.getEOperation(op);
+ final EOperation eOperation = _eOperation;
+ StringBuilderBasedAppendable _stringBuilderBasedAppendable = new StringBuilderBasedAppendable();
+ final StringBuilderBasedAppendable appendable = _stringBuilderBasedAppendable;
+ JvmOperation _jvmOperation = this.mappings.getJvmOperation(op);
+ JvmTypeReference _returnType = _jvmOperation.getReturnType();
+ final JvmTypeReference expectedType = _returnType;
+ XBlockExpression _body = op.getBody();
+ this.compiler.compile(_body, appendable, expectedType);
+ EList<EAnnotation> _eAnnotations = eOperation.getEAnnotations();
+ String _string = appendable.toString();
+ EAnnotation _createGenModelAnnotation = this.createGenModelAnnotation("body", _string);
+ _eAnnotations.add(_createGenModelAnnotation);
+ }
+ }
+ EList<EObject> _contents_1 = resource.getContents();
+ EObject _get = _contents_1.get(2);
+ this.generateGenModel(((GenModel) _get));
+ }
+ }
+
+ public void generateGenModel(final GenModel genModel) {
+ genModel.gen(null);
+ }
+
+ public EAnnotation createGenModelAnnotation(final String key, final String value) {
+ {
+ EAnnotation _createEAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ final EAnnotation result = _createEAnnotation;
+ result.setSource(GenModelPackage.eNS_URI);
+ EMap<String,String> _details = result.getDetails();
+ _details.put(key, value);
+ return result;
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java
new file mode 100644
index 0000000..70c83e7
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/util/MappingFacade.java
@@ -0,0 +1,31 @@
+package org.eclipse.emf.ecore.xcore.util;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.xcore.XOperation;
+import org.eclipse.emf.ecore.xcore.util.XcoreEcoreBuilder;
+import org.eclipse.xtext.common.types.JvmOperation;
+
+@SuppressWarnings("all")
+public class MappingFacade {
+
+ public EOperation getEOperation(final XOperation op) {
+ EObject _get = XcoreEcoreBuilder.get(op);
+ return ((EOperation) _get);
+ }
+
+ public GenOperation getGenOperation(final XOperation op) {
+ EObject _get = XcoreEcoreBuilder.get(op);
+ return ((GenOperation) _get);
+ }
+
+ public GenOperation getXOperation(final GenOperation op) {
+ EObject _get = XcoreEcoreBuilder.get(op);
+ return ((GenOperation) _get);
+ }
+
+ public JvmOperation getJvmOperation(final XOperation op) {
+ return null;
+ }
+} \ No newline at end of file