From 7ee3b8fdba1811296f0f8075f8a42c67b2b26312 Mon Sep 17 00:00:00 2001 From: Sebastian Zarnekow Date: Wed, 3 Aug 2011 11:39:30 +0200 Subject: [genmodel] First shot at indexing genmodels To be discussed: Do we want / need to index GenStructuralFeatures? Do we need a hash value in the user data of GenClasses to detect changes of their content?--- .../.classpath | 7 ++ org.eclipse.emf.codegen.ecore.xtext.tests/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 12 ++ .../about.html | 28 +++++ .../build.properties | 5 + .../plugin.properties | 2 + .../GenmodelResourceDescriptionManagerTest.java | 132 +++++++++++++++++++++ org.eclipse.emf.codegen.ecore.xtext.ui/.classpath | 7 ++ org.eclipse.emf.codegen.ecore.xtext.ui/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 15 +++ org.eclipse.emf.codegen.ecore.xtext.ui/about.html | 28 +++++ .../build.properties | 6 + .../plugin.properties | 2 + org.eclipse.emf.codegen.ecore.xtext.ui/plugin.xml | 12 ++ .../emf/codegen/ecore/xtext/ui/Activator.java | 80 +++++++++++++ .../ecore/xtext/ui/ExecutableExtensionFactory.java | 27 +++++ .../ecore/xtext/ui/GenmodelEditorOpener.java | 31 +++++ .../codegen/ecore/xtext/ui/GenmodelUiModule.java | 26 ++++ org.eclipse.emf.codegen.ecore.xtext/.classpath | 7 ++ org.eclipse.emf.codegen.ecore.xtext/.gitignore | 1 + org.eclipse.emf.codegen.ecore.xtext/.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++ .../META-INF/MANIFEST.MF | 13 ++ org.eclipse.emf.codegen.ecore.xtext/about.html | 28 +++++ .../build.properties | 5 + .../plugin.properties | 2 + .../ecore/xtext/GenmodelQualifiedNameProvider.java | 43 +++++++ .../xtext/GenmodelResourceDescriptionStrategy.java | 35 ++++++ .../codegen/ecore/xtext/GenmodelRuntimeModule.java | 40 +++++++ .../emf/codegen/ecore/xtext/GenmodelSupport.java | 45 +++++++ org.eclipse.emf.ecore.xcore.ui/.gitignore | 1 + org.eclipse.emf.ecore.xcore.ui/about.html | 28 +++++ org.eclipse.emf.ecore.xcore.ui/plugin.properties | 2 + 35 files changed, 775 insertions(+) create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/.classpath create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/.project create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/META-INF/MANIFEST.MF create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/about.html create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/build.properties create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/plugin.properties create mode 100644 org.eclipse.emf.codegen.ecore.xtext.tests/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionManagerTest.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/.classpath create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/.project create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/META-INF/MANIFEST.MF create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/about.html create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/build.properties create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/plugin.properties create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/plugin.xml create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/Activator.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/ExecutableExtensionFactory.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelEditorOpener.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelUiModule.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext/.classpath create mode 100644 org.eclipse.emf.codegen.ecore.xtext/.gitignore create mode 100644 org.eclipse.emf.codegen.ecore.xtext/.project create mode 100644 org.eclipse.emf.codegen.ecore.xtext/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.emf.codegen.ecore.xtext/META-INF/MANIFEST.MF create mode 100644 org.eclipse.emf.codegen.ecore.xtext/about.html create mode 100644 org.eclipse.emf.codegen.ecore.xtext/build.properties create mode 100644 org.eclipse.emf.codegen.ecore.xtext/plugin.properties create mode 100644 org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelQualifiedNameProvider.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionStrategy.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelRuntimeModule.java create mode 100644 org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelSupport.java create mode 100644 org.eclipse.emf.ecore.xcore.ui/.gitignore create mode 100644 org.eclipse.emf.ecore.xcore.ui/about.html create mode 100644 org.eclipse.emf.ecore.xcore.ui/plugin.properties diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/.classpath b/org.eclipse.emf.codegen.ecore.xtext.tests/.classpath new file mode 100644 index 000000000..1fa3e6803 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/.project b/org.eclipse.emf.codegen.ecore.xtext.tests/.project new file mode 100644 index 000000000..17ad45a76 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/.project @@ -0,0 +1,28 @@ + + + org.eclipse.emf.codegen.ecore.xtext.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.codegen.ecore.xtext.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..78cea41fe --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Wed Aug 03 10:33:19 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/META-INF/MANIFEST.MF b/org.eclipse.emf.codegen.ecore.xtext.tests/META-INF/MANIFEST.MF new file mode 100644 index 000000000..8262a5d87 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.emf.codegen.ecore.xtext.tests +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.xtext.junit;bundle-version="2.0.0", + org.eclipse.xtext;bundle-version="2.0.0", + org.eclipse.emf.codegen.ecore.xtext;bundle-version="1.0.0", + org.eclipse.emf.codegen.ecore;bundle-version="2.7.0" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/about.html b/org.eclipse.emf.codegen.ecore.xtext.tests/about.html new file mode 100644 index 000000000..68e17ab9e --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 15, 2010

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/build.properties b/org.eclipse.emf.codegen.ecore.xtext.tests/build.properties new file mode 100644 index 000000000..39c1bfa03 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +bin.includes = META-INF/,\ + .,\ + about.html,\ + plugin.properties diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/plugin.properties b/org.eclipse.emf.codegen.ecore.xtext.tests/plugin.properties new file mode 100644 index 000000000..d089281fb --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/plugin.properties @@ -0,0 +1,2 @@ +pluginName = EMF CodeGen Ecore Xtext Integration Tests +providerName = Eclipse Modeling Project \ No newline at end of file diff --git a/org.eclipse.emf.codegen.ecore.xtext.tests/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionManagerTest.java b/org.eclipse.emf.codegen.ecore.xtext.tests/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionManagerTest.java new file mode 100644 index 000000000..6a7760bd1 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.tests/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionManagerTest.java @@ -0,0 +1,132 @@ +/******************************************************************************* + * Copyright (c) 2009 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext; + +import java.util.Collections; +import java.util.Map; + +import junit.framework.TestCase; + +import org.eclipse.emf.codegen.ecore.genmodel.GenClass; +import org.eclipse.emf.codegen.ecore.genmodel.GenModel; +import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory; +import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; +import org.eclipse.emf.ecore.EcorePackage; +import org.eclipse.emf.ecore.plugin.EcorePlugin; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.naming.QualifiedName; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.IResourceDescription; +import org.eclipse.xtext.resource.generic.GenericResourceDescriptionManager; + +import com.google.common.collect.Maps; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * @author Sven Efftinge - Initial contribution and API + * @author Jan Koehnlein + */ +public class GenmodelResourceDescriptionManagerTest extends TestCase { + + private GenericResourceDescriptionManager testMe; + + private IQualifiedNameConverter converter; + + private Resource ecoreGenModel; + + @Override + protected void setUp() throws Exception { + super.setUp(); + Injector injector = Guice.createInjector(new GenmodelRuntimeModule()); + testMe = injector.getInstance(GenericResourceDescriptionManager.class); + converter = injector.getInstance(IQualifiedNameConverter.class); + URI genmodelURI = EcorePlugin.getEPackageNsURIToGenModelLocationMap().get(EcorePackage.eINSTANCE.getNsURI()); + ecoreGenModel = new ResourceSetImpl().getResource(genmodelURI, true); + assertNotNull(ecoreGenModel); + } + + @Override + protected void tearDown() throws Exception { + testMe = null; + converter = null; + ecoreGenModel = null; + super.tearDown(); + } + + public void testEcoreGenmodel() throws Exception { + Map index = createIndex(ecoreGenModel); + getAndCheckEntry(index, GenModelPackage.Literals.GEN_PACKAGE, "org.eclipse.emf.ecore"); + IEObjectDescription description = getAndCheckEntry(index, GenModelPackage.Literals.GEN_CLASS, "org.eclipse.emf.ecore.EClass"); + GenClass genClass = (GenClass) description.getEObjectOrProxy(); + assertEquals(EcorePackage.Literals.ECLASS.getName(), genClass.getEcoreClass().getName()); + // abstract types are available, too + getAndCheckEntry(index, GenModelPackage.Literals.GEN_CLASS, "org.eclipse.emf.ecore.EClassifier"); + + // GenStructuralFeatures are not indexed + assertNoEntry(index, "org.eclipse.emf.ecore.EClassifier.defaultValue"); + assertNoEntry(index, "org.eclipse.emf.ecore.EClassifier.getDefaultValue"); + assertNoEntry(index, "org.eclipse.emf.ecore.EClassifier.DefaultValue"); + } + + public void testNestedPackage() throws Exception { + Resource ecoreResource = new XMIResourceImpl(); + Resource genmodelResource = new XMIResourceImpl(); + EPackage parent = EcoreFactory.eINSTANCE.createEPackage(); + parent.setName("parent"); + parent.setNsURI("http://parent"); + EPackage child = EcoreFactory.eINSTANCE.createEPackage(); + child.setName("child"); + child.setNsURI("http://child"); + EClass eClass = EcoreFactory.eINSTANCE.createEClass(); + eClass.setName("Test"); + child.getEClassifiers().add(eClass); + parent.getESubpackages().add(child); + ecoreResource.getContents().add(parent); + GenModel genModel = GenModelFactory.eINSTANCE.createGenModel(); + genModel.initialize(Collections.singleton(parent)); + genmodelResource.getContents().add(genModel); + genModel.initialize(); + genModel.getGenPackages().get(0).setBasePackage("org.foo.bar"); + genModel.getGenPackages().get(0).getNestedGenPackages().get(0).setBasePackage("org.foo.zonk"); + Map index = createIndex(genmodelResource); + getAndCheckEntry(index, GenModelPackage.Literals.GEN_PACKAGE, "org.foo.bar.parent"); + getAndCheckEntry(index, GenModelPackage.Literals.GEN_PACKAGE, "org.foo.zonk.child"); + getAndCheckEntry(index, GenModelPackage.Literals.GEN_CLASS, "org.foo.zonk.child.Test"); + assertEquals(3, index.size()); + } + + protected IEObjectDescription getAndCheckEntry(Map index, EClass expectedType, String name) { + IEObjectDescription element = index.get(converter.toQualifiedName(name)); + assertNotNull(element); + assertSame(expectedType, element.getEClass()); + return element; + } + + protected void assertNoEntry(Map index, String name) { + IEObjectDescription element = index.get(converter.toQualifiedName(name)); + assertNull(element); + } + + protected Map createIndex(Resource ecoreResoure) { + IResourceDescription description = testMe.getResourceDescription(ecoreResoure); + Map index = Maps.newHashMap(); + for (IEObjectDescription ieObjectDescription : description.getExportedObjects()) { + index.put(ieObjectDescription.getName(), ieObjectDescription); + } + return index; + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/.classpath b/org.eclipse.emf.codegen.ecore.xtext.ui/.classpath new file mode 100644 index 000000000..1fa3e6803 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/.project b/org.eclipse.emf.codegen.ecore.xtext.ui/.project new file mode 100644 index 000000000..efa2e18f2 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/.project @@ -0,0 +1,28 @@ + + + org.eclipse.emf.codegen.ecore.xtext.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.codegen.ecore.xtext.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..78cea41fe --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Wed Aug 03 10:33:19 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/META-INF/MANIFEST.MF b/org.eclipse.emf.codegen.ecore.xtext.ui/META-INF/MANIFEST.MF new file mode 100644 index 000000000..3d9cf551e --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.emf.codegen.ecore.xtext.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.emf.codegen.ecore.xtext;bundle-version="1.0.0", + org.eclipse.emf.codegen.ecore.ui;bundle-version="2.7.0", + org.eclipse.xtext.ui;bundle-version="2.0.0", + org.eclipse.xtext.ui.shared;bundle-version="2.0.0" +Import-Package: org.apache.log4j;version="1.2.15" +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ActivationPolicy: lazy +Bundle-Activator: org.eclipse.emf.codegen.ecore.xtext.ui.Activator diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/about.html b/org.eclipse.emf.codegen.ecore.xtext.ui/about.html new file mode 100644 index 000000000..68e17ab9e --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 15, 2010

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/build.properties b/org.eclipse.emf.codegen.ecore.xtext.ui/build.properties new file mode 100644 index 000000000..ff1f844c8 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + plugin.properties,\ + about.html diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/plugin.properties b/org.eclipse.emf.codegen.ecore.xtext.ui/plugin.properties new file mode 100644 index 000000000..1d44cf4fe --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/plugin.properties @@ -0,0 +1,2 @@ +pluginName = Xtext Ecore Ui Support +providerName = Eclipse Modeling Project \ No newline at end of file diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/plugin.xml b/org.eclipse.emf.codegen.ecore.xtext.ui/plugin.xml new file mode 100644 index 000000000..1222ca016 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/plugin.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/Activator.java b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/Activator.java new file mode 100644 index 000000000..a48fa4b42 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/Activator.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext.ui; + +import org.apache.log4j.Logger; +import org.eclipse.emf.codegen.ecore.xtext.GenmodelRuntimeModule; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.xtext.ui.shared.SharedStateModule; +import org.osgi.framework.BundleContext; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.util.Modules; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + private static final Logger logger = Logger.getLogger(Activator.class); + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.emf.codegen.ecore.xtext.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + private Injector injector; + + /** + * The constructor + */ + public Activator() { + } + + public Injector getInjector() { + return injector; + } + + private void initializeEcoreInjector() { + injector = Guice.createInjector( + Modules.override(Modules.override(new GenmodelRuntimeModule()) + .with(new GenmodelUiModule(plugin))) + .with(new SharedStateModule())); + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + try { + initializeEcoreInjector(); + } catch(Exception e) { + logger.error(e.getMessage(), e); + throw e; + } + } + + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + injector = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/ExecutableExtensionFactory.java b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/ExecutableExtensionFactory.java new file mode 100644 index 000000000..4337c6390 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/ExecutableExtensionFactory.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext.ui; + +import org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory; +import org.osgi.framework.Bundle; + +import com.google.inject.Injector; + +public class ExecutableExtensionFactory extends AbstractGuiceAwareExecutableExtensionFactory { + + @Override + protected Bundle getBundle() { + return Activator.getDefault().getBundle(); + } + + @Override + protected Injector getInjector() { + return Activator.getDefault().getInjector(); + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelEditorOpener.java b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelEditorOpener.java new file mode 100644 index 000000000..ee5a321bf --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelEditorOpener.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext.ui; + +import java.util.Collections; + +import org.eclipse.emf.codegen.ecore.genmodel.presentation.GenModelEditor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.ui.IEditorPart; +import org.eclipse.xtext.ui.editor.LanguageSpecificURIEditorOpener; + +public class GenmodelEditorOpener extends LanguageSpecificURIEditorOpener { + + @Override + protected void selectAndReveal(IEditorPart openEditor, URI uri, + EReference crossReference, int indexInList, boolean select) { + GenModelEditor editor = (GenModelEditor) openEditor.getAdapter(GenModelEditor.class); + if (editor != null) { + EObject eObject = editor.getEditingDomain().getResourceSet().getEObject(uri, true); + editor.setSelectionToViewer(Collections.singletonList(eObject)); + } + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelUiModule.java b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelUiModule.java new file mode 100644 index 000000000..6b63df39e --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext.ui/src/org/eclipse/emf/codegen/ecore/xtext/ui/GenmodelUiModule.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext.ui; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.xtext.ui.LanguageSpecific; +import org.eclipse.xtext.ui.editor.IURIEditorOpener; +import org.eclipse.xtext.ui.resource.generic.EmfUiModule; + +public class GenmodelUiModule extends EmfUiModule { + + public GenmodelUiModule(AbstractUIPlugin plugin) { + super(plugin); + } + + @Override + public void configureLanguageSpecificURIEditorOpener(com.google.inject.Binder binder) { + binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(GenmodelEditorOpener.class); + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext/.classpath b/org.eclipse.emf.codegen.ecore.xtext/.classpath new file mode 100644 index 000000000..1fa3e6803 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.emf.codegen.ecore.xtext/.gitignore b/org.eclipse.emf.codegen.ecore.xtext/.gitignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/.gitignore @@ -0,0 +1 @@ +bin diff --git a/org.eclipse.emf.codegen.ecore.xtext/.project b/org.eclipse.emf.codegen.ecore.xtext/.project new file mode 100644 index 000000000..b9a610dc1 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/.project @@ -0,0 +1,28 @@ + + + org.eclipse.emf.codegen.ecore.xtext + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/org.eclipse.emf.codegen.ecore.xtext/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.codegen.ecore.xtext/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..78cea41fe --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Wed Aug 03 10:33:19 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate diff --git a/org.eclipse.emf.codegen.ecore.xtext/META-INF/MANIFEST.MF b/org.eclipse.emf.codegen.ecore.xtext/META-INF/MANIFEST.MF new file mode 100644 index 000000000..0bfc1bf2c --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: org.eclipse.emf.codegen.ecore.xtext;singleton:=true +Bundle-Version: 1.0.0.qualifier +Require-Bundle: org.eclipse.emf.codegen.ecore;bundle-version="2.7.0", + org.eclipse.xtext;bundle-version="2.0.0", + org.eclipse.core.runtime +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Bundle-Name: %pluginName +Import-Package: org.apache.log4j;version="1.2.15" +Export-Package: org.eclipse.emf.codegen.ecore.xtext +Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/org.eclipse.emf.codegen.ecore.xtext/about.html b/org.eclipse.emf.codegen.ecore.xtext/about.html new file mode 100644 index 000000000..68e17ab9e --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 15, 2010

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.emf.codegen.ecore.xtext/build.properties b/org.eclipse.emf.codegen.ecore.xtext/build.properties new file mode 100644 index 000000000..8020d8bd4 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + about.html diff --git a/org.eclipse.emf.codegen.ecore.xtext/plugin.properties b/org.eclipse.emf.codegen.ecore.xtext/plugin.properties new file mode 100644 index 000000000..4bd96f2bd --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/plugin.properties @@ -0,0 +1,2 @@ +pluginName = EMF CodeGen Ecore Xtext Integration +providerName = Eclipse Modeling Project \ No newline at end of file diff --git a/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelQualifiedNameProvider.java b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelQualifiedNameProvider.java new file mode 100644 index 000000000..c716e144d --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelQualifiedNameProvider.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2011 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext; + +import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier; +import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.naming.IQualifiedNameConverter; +import org.eclipse.xtext.naming.IQualifiedNameProvider; +import org.eclipse.xtext.naming.QualifiedName; + +import com.google.inject.Inject; + +/** + * @author Sebastian Zarnekow - Initial contribution and API + */ +public class GenmodelQualifiedNameProvider extends IQualifiedNameProvider.AbstractImpl { + + @Inject + private IQualifiedNameConverter qualifiedNameConverter; + + public QualifiedName getFullyQualifiedName(final EObject obj) { + if (obj instanceof GenPackage) { + String packageName = ((GenPackage) obj).getQualifiedPackageName(); + return qualifiedNameConverter.toQualifiedName(packageName); + + } else if (obj instanceof GenClassifier) { + GenClassifier classifier = (GenClassifier) obj; + GenPackage genPackage = classifier.getGenPackage(); + String packageName = genPackage.getQualifiedPackageName(); + String classifierName = classifier.getName(); + return qualifiedNameConverter.toQualifiedName(packageName).append(classifierName); + } + return null; + } + + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionStrategy.java b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionStrategy.java new file mode 100644 index 000000000..12897be0a --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelResourceDescriptionStrategy.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2011 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext; + +import org.eclipse.emf.codegen.ecore.genmodel.GenClassifier; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.resource.IEObjectDescription; +import org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy; +import org.eclipse.xtext.util.IAcceptor; + +import com.google.inject.Singleton; + +/** + * @author Sebastian Zarnekow - Initial contribution and API + * + * TODO: We should probably add some hashed user data over all information that + * impacts the code generation in order to be properly notify clients about these changes + */ +@Singleton +public class GenmodelResourceDescriptionStrategy extends DefaultResourceDescriptionStrategy { + + @Override + public boolean createEObjectDescriptions(EObject eObject, IAcceptor acceptor) { + super.createEObjectDescriptions(eObject, acceptor); + if (eObject instanceof GenClassifier) + return false; + return true; + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelRuntimeModule.java b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelRuntimeModule.java new file mode 100644 index 000000000..f2ad3d682 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelRuntimeModule.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext; + +import org.eclipse.xtext.naming.IQualifiedNameProvider; +import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy; +import org.eclipse.xtext.resource.generic.AbstractGenericResourceRuntimeModule; + +/** + * Default Guice bindings for managing Genmodel resources in the context of Xtext. + * + * @author Jan Koehnlein - Initial contribution and API + */ +public class GenmodelRuntimeModule extends AbstractGenericResourceRuntimeModule { + + @Override + protected String getLanguageName() { + return "org.eclipse.emf.codegen.ecore.genmodel.presentation.GenModelEditorID"; + } + + @Override + protected String getFileExtensions() { + return "genmodel"; + } + + public Class bindIDefaultResourceDescriptionStrategy() { + return GenmodelResourceDescriptionStrategy.class; + } + + @Override + public Class bindIQualifiedNameProvider() { + return GenmodelQualifiedNameProvider.class; + } + +} diff --git a/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelSupport.java b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelSupport.java new file mode 100644 index 000000000..7e81fdf76 --- /dev/null +++ b/org.eclipse.emf.codegen.ecore.xtext/src/org/eclipse/emf/codegen/ecore/xtext/GenmodelSupport.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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 + *******************************************************************************/ +package org.eclipse.emf.codegen.ecore.xtext; + +import org.eclipse.xtext.resource.generic.AbstractGenericResourceSupport; + +import com.google.inject.Module; + +/** + * + * This class is intended to be used from an MWE workflow. + * + * It instantiates and registers the Genmodel support for Xtext, which allows for referencing Genmodels from any Xtext + * language. + * + * Usage: + * + *
+ *    component = org.eclipse.emf.codegen.ecore.xtext.GenmodelSupport{}
+ * 
+ * + * If you want to provide a different guice guiceModule than the default one ({@link GenmodelRuntimeModule}) in order to + * change any implementation classes, you can make use of the property guiceModule. E.g. : + * + *
+ *    component = org.eclipse.emf.codegen.ecore.xtext.GenmodelSupport{
+ *       guiceModule = my.special.CustomizedGenmodelRuntimeModule {}
+ *    }
+ * 
+ * + * @author Sven Efftinge - Initial contribution and API + */ +public class GenmodelSupport extends AbstractGenericResourceSupport { + + @Override + protected Module createGuiceModule() { + return new GenmodelRuntimeModule(); + } + +} diff --git a/org.eclipse.emf.ecore.xcore.ui/.gitignore b/org.eclipse.emf.ecore.xcore.ui/.gitignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/org.eclipse.emf.ecore.xcore.ui/.gitignore @@ -0,0 +1 @@ +bin diff --git a/org.eclipse.emf.ecore.xcore.ui/about.html b/org.eclipse.emf.ecore.xcore.ui/about.html new file mode 100644 index 000000000..68e17ab9e --- /dev/null +++ b/org.eclipse.emf.ecore.xcore.ui/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 15, 2010

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.emf.ecore.xcore.ui/plugin.properties b/org.eclipse.emf.ecore.xcore.ui/plugin.properties new file mode 100644 index 000000000..023d5be53 --- /dev/null +++ b/org.eclipse.emf.ecore.xcore.ui/plugin.properties @@ -0,0 +1,2 @@ +pluginName = EMF CodeGen Ecore Xtext UI Integration +providerName = Eclipse Modeling Project \ No newline at end of file -- cgit v1.2.3