diff options
author | Sebastian Zarnekow | 2011-08-03 09:39:30 +0000 |
---|---|---|
committer | Ed Merks | 2011-08-03 09:42:44 +0000 |
commit | 7ee3b8fdba1811296f0f8075f8a42c67b2b26312 (patch) | |
tree | 5bfa91f81909d97df8ea7e608fdeee5e87653708 | |
parent | cd904127908983eba2c9fe40c545e21da931e699 (diff) | |
download | org.eclipse.emf-7ee3b8fdba1811296f0f8075f8a42c67b2b26312.tar.gz org.eclipse.emf-7ee3b8fdba1811296f0f8075f8a42c67b2b26312.tar.xz org.eclipse.emf-7ee3b8fdba1811296f0f8075f8a42c67b2b26312.zip |
[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?
35 files changed, 775 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.emf.codegen.ecore.xtext.tests</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.jdt.core.javanature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + </natures> +</projectDescription> 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 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 15, 2010</p> +<h3>License</h3> + +<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ 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<QualifiedName, IEObjectDescription> 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<QualifiedName, IEObjectDescription> 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<QualifiedName, IEObjectDescription> index, EClass expectedType, String name) { + IEObjectDescription element = index.get(converter.toQualifiedName(name)); + assertNotNull(element); + assertSame(expectedType, element.getEClass()); + return element; + } + + protected void assertNoEntry(Map<QualifiedName, IEObjectDescription> index, String name) { + IEObjectDescription element = index.get(converter.toQualifiedName(name)); + assertNull(element); + } + + protected Map<QualifiedName, IEObjectDescription> createIndex(Resource ecoreResoure) { + IResourceDescription description = testMe.getResourceDescription(ecoreResoure); + Map<QualifiedName,IEObjectDescription> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.emf.codegen.ecore.xtext.ui</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.jdt.core.javanature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + </natures> +</projectDescription> 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 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 15, 2010</p> +<h3>License</h3> + +<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.xtext.extension_resourceServiceProvider"> + <resourceServiceProvider + class="org.eclipse.emf.codegen.ecore.xtext.ui.ExecutableExtensionFactory:org.eclipse.xtext.ui.resource.generic.EmfResourceUIServiceProvider" + uriExtension="genmodel"> + </resourceServiceProvider> + </extension> + +</plugin> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.emf.codegen.ecore.xtext</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.jdt.core.javanature</nature> + <nature>org.eclipse.pde.PluginNature</nature> + </natures> +</projectDescription> 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 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 15, 2010</p> +<h3>License</h3> + +<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ 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<IEObjectDescription> 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<? extends IDefaultResourceDescriptionStrategy> bindIDefaultResourceDescriptionStrategy() { + return GenmodelResourceDescriptionStrategy.class; + } + + @Override + public Class<? extends IQualifiedNameProvider> 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: + * + * <pre> + * component = org.eclipse.emf.codegen.ecore.xtext.GenmodelSupport{} + * </pre> + * + * 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. : + * + * <pre> + * component = org.eclipse.emf.codegen.ecore.xtext.GenmodelSupport{ + * guiceModule = my.special.CustomizedGenmodelRuntimeModule {} + * } + * </pre> + * + * @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 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 15, 2010</p> +<h3>License</h3> + +<p>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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>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 <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ 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 |