[generator] Moved configuration classes to base package,

added naming property to LanguageConfig2

Signed-off-by: Miro Spönemann <miro.spoenemann@itemis.de>
This commit is contained in:
Miro Spönemann 2015-07-08 13:31:26 +02:00
parent 2ee457fd8d
commit 588af7bf44
13 changed files with 168 additions and 105 deletions

View file

@ -5,7 +5,7 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.xtext.generator.model
package org.eclipse.xtext.xtext.generator
import com.google.inject.Injector
import java.io.IOException
@ -18,7 +18,7 @@ import java.util.jar.Manifest
import org.eclipse.emf.common.EMFPlugin
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.util.Strings
import org.eclipse.xtext.xtext.generator.IGuiceAwareGeneratorComponent
import org.eclipse.xtext.xtext.generator.model.IClassAnnotation
/**
* Configuration object for generated code.

View file

@ -14,10 +14,6 @@ import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.parser.IEncodingProvider
import org.eclipse.xtext.resource.XtextResourceSet
import org.eclipse.xtext.service.AbstractGenericModule
import org.eclipse.xtext.xtext.generator.model.CodeConfig
import org.eclipse.xtext.xtext.generator.model.IXtextProjectConfig
import org.eclipse.xtext.xtext.generator.model.WizardConfig
import org.eclipse.xtext.xtext.generator.model.XtextProjectConfig
class DefaultGeneratorModule extends AbstractGenericModule {

View file

@ -5,10 +5,12 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.xtext.generator.model;
package org.eclipse.xtext.xtext.generator;
import org.eclipse.xtext.generator.IFileSystemAccess2;
import org.eclipse.xtext.xtext.generator.IGuiceAwareGeneratorComponent;
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Inject an instance of this interface in order to generate code in a generator fragment.

View file

@ -38,7 +38,6 @@ import org.eclipse.xtext.resource.containers.IAllContainersState
import org.eclipse.xtext.resource.impl.ResourceDescriptionsData
import org.eclipse.xtext.util.internal.Log
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess
import org.eclipse.xtext.xtext.generator.model.IXtextProjectConfig
import org.eclipse.xtext.xtext.generator.model.StandaloneSetupAccess
import org.eclipse.xtext.xtext.generator.model.TypeReference
@ -56,6 +55,12 @@ class LanguageConfig2 extends CompositeGeneratorFragment2 {
@Accessors(PUBLIC_GETTER)
List<String> fileExtensions
@Accessors(PUBLIC_SETTER)
ResourceSet forcedResourceSet
@Accessors
XtextGeneratorNaming naming
@Accessors
val List<String> loadedResources = newArrayList
@ -97,7 +102,7 @@ class LanguageConfig2 extends CompositeGeneratorFragment2 {
override initialize(Injector injector) {
super.initialize(injector)
val rs = resourceSetProvider.get()
val rs = forcedResourceSet ?: resourceSetProvider.get()
for (String loadedResource : loadedResources) {
val loadedResourceUri = URI.createURI(loadedResource)
switch (loadedResourceUri.fileExtension) {
@ -170,6 +175,11 @@ class LanguageConfig2 extends CompositeGeneratorFragment2 {
val grammar = resource.getContents().get(0) as Grammar
validateGrammar(grammar)
this.grammar = grammar
if (naming === null) {
naming = new XtextGeneratorNaming
}
naming.grammar = grammar
}
private def void installIndex(ResourceSet resourceSet) {

View file

@ -5,13 +5,14 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.xtext.generator.model
package org.eclipse.xtext.xtext.generator
import com.google.inject.Injector
import org.eclipse.emf.mwe.core.issues.Issues
import org.eclipse.emf.mwe2.runtime.Mandatory
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.xtext.generator.XtextGenerator
import org.eclipse.xtext.xtext.generator.model.ManifestAccess
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess
@Accessors
class WizardConfig extends XtextProjectConfig {

View file

@ -28,8 +28,7 @@ import org.eclipse.xtext.GeneratedMetamodel
import org.eclipse.xtext.Grammar
import org.eclipse.xtext.XtextStandaloneSetup
import org.eclipse.xtext.util.MergeableManifest
import org.eclipse.xtext.xtext.generator.model.CodeConfig
import org.eclipse.xtext.xtext.generator.model.IXtextProjectConfig
import org.eclipse.xtext.util.internal.Log
import org.eclipse.xtext.xtext.generator.model.ManifestAccess
import org.eclipse.xtext.xtext.generator.model.TypeReference
@ -39,21 +38,17 @@ import org.eclipse.xtext.xtext.generator.model.TypeReference
*
* <p><b>NOTE: This is a reimplementation of org.eclipse.xtext.generator.Generator</b></p>
*/
@Log
class XtextGenerator extends AbstractWorkflowComponent2 implements IGuiceAwareGeneratorComponent {
@Accessors
DefaultGeneratorModule configuration
@Accessors
String activator
@Accessors
val List<LanguageConfig2> languageConfigs = newArrayList
Injector injector
@Inject extension XtextGeneratorNaming
@Inject IXtextProjectConfig projectConfig
@Inject XtextGeneratorTemplates templates
@ -91,6 +86,7 @@ class XtextGenerator extends AbstractWorkflowComponent2 implements IGuiceAwareGe
protected def Injector createInjector() {
if (injector === null) {
LOG.info('Initializing Xtext generator')
if (configuration === null)
configuration = new DefaultGeneratorModule
injector = Guice.createInjector(configuration)
@ -108,19 +104,18 @@ class XtextGenerator extends AbstractWorkflowComponent2 implements IGuiceAwareGe
injector.getInstance(CodeConfig) => [ codeConfig |
codeConfig.initialize(injector)
]
injector.getInstance(XtextGeneratorNaming) => [ naming |
naming.eclipsePluginActivator = activator
]
}
protected override invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
createInjector()
for (language : languageConfigs) {
LOG.info('Generating ' + language.grammar.name)
language.generate(language)
language.generateRuntimeSetup()
language.generateModules()
language.generateExecutableExtensionFactory()
}
LOG.info('Generating common infrastructure')
generatePluginXmls()
generateManifests()
generateActivator()
@ -166,7 +161,7 @@ class XtextGenerator extends AbstractWorkflowComponent2 implements IGuiceAwareGe
}
var TypeReference activator
if (manifest === projectConfig.eclipsePluginManifest) {
activator = languageConfigs.head?.grammar.eclipsePluginActivator
activator = languageConfigs.head?.naming?.eclipsePluginActivator
}
val file = new File(manifest.path)
if (file.exists) {
@ -207,7 +202,7 @@ class XtextGenerator extends AbstractWorkflowComponent2 implements IGuiceAwareGe
}
protected def generateActivator() {
if (projectConfig.eclipsePluginSrcGen !== null)
if (projectConfig.eclipsePluginSrcGen !== null && !languageConfigs.empty)
templates.createEclipsePluginActivator(languageConfigs).writeTo(projectConfig.eclipsePluginSrcGen)
}

View file

@ -8,6 +8,7 @@
package org.eclipse.xtext.xtext.generator
import com.google.inject.Singleton
import java.util.Map
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.Grammar
import org.eclipse.xtext.xtext.generator.model.TypeReference
@ -17,58 +18,106 @@ import static org.eclipse.xtext.GrammarUtil.*
@Singleton
class XtextGeneratorNaming {
static val Map<String, XtextGeneratorNaming> registry = newHashMap
static def XtextGeneratorNaming naming(Grammar g) {
synchronized (registry) {
if (registry.containsKey(g.name))
return registry.get(g.name)
}
val naming = new XtextGeneratorNaming
naming.setGrammar(g)
return naming
}
Grammar grammar
@Accessors(PUBLIC_SETTER)
String eclipsePluginActivator
def getRuntimeBasePackage(Grammar grammar) {
getNamespace(grammar)
@Accessors(PUBLIC_SETTER)
String runtimeBasePackage
@Accessors(PUBLIC_SETTER)
String eclipsePluginBasePackage
@Accessors(PUBLIC_SETTER)
String genericIdeBasePackage
protected def void setGrammar(Grammar grammar) {
this.grammar = grammar
synchronized (registry) {
registry.put(grammar.name, this)
}
}
def getRuntimeModule(Grammar grammar) {
new TypeReference(grammar.runtimeBasePackage, getName(grammar) + 'RuntimeModule')
def getRuntimeBasePackage() {
if (runtimeBasePackage === null)
runtimeBasePackage = getNamespace(grammar)
return runtimeBasePackage
}
def getRuntimeGenModule(Grammar grammar) {
new TypeReference(grammar.runtimeBasePackage, 'Abstract' + getName(grammar) + 'RuntimeModule')
def getRuntimeModule() {
new TypeReference(getRuntimeBasePackage, getName(grammar) + 'RuntimeModule')
}
def getRuntimeDefaultModule(Grammar grammar) {
def getRuntimeGenModule() {
new TypeReference(getRuntimeBasePackage, 'Abstract' + getName(grammar) + 'RuntimeModule')
}
def getRuntimeDefaultModule() {
new TypeReference('org.eclipse.xtext.service.DefaultRuntimeModule')
}
def getRuntimeSetup(Grammar grammar) {
new TypeReference(grammar.runtimeBasePackage, getName(grammar) + 'StandaloneSetup')
def getRuntimeSetup() {
new TypeReference(getRuntimeBasePackage, getName(grammar) + 'StandaloneSetup')
}
def getRuntimeGenSetup(Grammar grammar) {
new TypeReference(grammar.runtimeBasePackage, getName(grammar) + 'StandaloneSetupGenerated')
def getRuntimeGenSetup() {
new TypeReference(getRuntimeBasePackage, getName(grammar) + 'StandaloneSetupGenerated')
}
def getEclipsePluginBasePackage(Grammar grammar) {
getNamespace(grammar) + '.ui'
def getEclipsePluginBasePackage() {
if (eclipsePluginBasePackage === null)
eclipsePluginBasePackage = getNamespace(grammar) + '.ui'
return eclipsePluginBasePackage
}
def getEclipsePluginModule(Grammar grammar) {
new TypeReference(grammar.eclipsePluginBasePackage, getName(grammar) + 'UiModule')
def getEclipsePluginModule() {
new TypeReference(getEclipsePluginBasePackage, getName(grammar) + 'UiModule')
}
def getEclipsePluginGenModule(Grammar grammar) {
new TypeReference(grammar.eclipsePluginBasePackage, 'Abstract' + getName(grammar) + 'UiModule')
def getEclipsePluginGenModule() {
new TypeReference(getEclipsePluginBasePackage, 'Abstract' + getName(grammar) + 'UiModule')
}
def getEclipsePluginDefaultModule(Grammar grammar) {
def getEclipsePluginDefaultModule() {
new TypeReference('org.eclipse.xtext.ui.DefaultUiModule')
}
def getEclipsePluginExecutableExtensionFactory(Grammar grammar) {
new TypeReference(grammar.eclipsePluginBasePackage, getName(grammar) + 'ExecutableExtensionFactory')
def getEclipsePluginExecutableExtensionFactory() {
new TypeReference(getEclipsePluginBasePackage, getName(grammar) + 'ExecutableExtensionFactory')
}
def getEclipsePluginActivator(Grammar grammar) {
def getEclipsePluginActivator() {
if (eclipsePluginActivator === null) {
eclipsePluginActivator = grammar.eclipsePluginBasePackage + '.internal.' + getName(grammar) + 'Activator'
eclipsePluginActivator = getEclipsePluginBasePackage + '.internal.' + getName(grammar) + 'Activator'
}
return new TypeReference(eclipsePluginActivator)
}
def getGenericIdeBasePackage() {
if (genericIdeBasePackage === null)
genericIdeBasePackage = getNamespace(grammar) + '.ide'
return genericIdeBasePackage
}
def getGenericIdeModule() {
new TypeReference(getGenericIdeBasePackage, getName(grammar) + 'IdeModule')
}
def getGenericIdeGenModule() {
new TypeReference(getGenericIdeBasePackage, 'Abstract' + getName(grammar) + 'IdeModule')
}
}

View file

@ -31,7 +31,6 @@ import org.eclipse.xtext.parser.IEncodingProvider
import org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl
import org.eclipse.xtext.service.SingletonBinding
import org.eclipse.xtext.util.Modules2
import org.eclipse.xtext.xtext.generator.model.CodeConfig
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess
import org.eclipse.xtext.xtext.generator.model.JavaFileAccess
import org.eclipse.xtext.xtext.generator.model.ManifestAccess
@ -40,13 +39,12 @@ import org.eclipse.xtext.xtext.generator.model.SuppressWarningsAnnotation
import org.eclipse.xtext.xtext.generator.model.TextFileAccess
import org.eclipse.xtext.xtext.generator.model.TypeReference
import static extension org.eclipse.xtext.xtext.generator.XtextGeneratorNaming.*
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
@Singleton
class XtextGeneratorTemplates {
@Inject extension XtextGeneratorNaming
@Inject CodeConfig codeConfig
@Inject IEncodingProvider encodingProvider
@ -69,8 +67,8 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createRuntimeSetup(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val javaFile = new JavaFileAccess(g.runtimeSetup, codeConfig)
val it = langConfig.naming
val javaFile = new JavaFileAccess(runtimeSetup, codeConfig)
javaFile.encodingProvider = encodingProvider
javaFile.typeComment = '''
@ -79,10 +77,10 @@ class XtextGeneratorTemplates {
*/
'''
javaFile.javaContent = '''
public class «g.runtimeSetup.simpleName» extends «g.runtimeGenSetup»{
public class «runtimeSetup.simpleName» extends «runtimeGenSetup»{
public static void doSetup() {
new «g.runtimeSetup.simpleName»().createInjectorAndDoEMFRegistration();
new «runtimeSetup.simpleName»().createInjectorAndDoEMFRegistration();
}
}
@ -91,8 +89,8 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createRuntimeGenSetup(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val javaFile = new JavaFileAccess(g.runtimeGenSetup, codeConfig)
val it = langConfig.naming
val javaFile = new JavaFileAccess(runtimeGenSetup, codeConfig)
javaFile.encodingProvider = encodingProvider
for (type : langConfig.runtimeGenSetup.imports) {
javaFile.importType(type)
@ -100,7 +98,7 @@ class XtextGeneratorTemplates {
javaFile.annotations += new SuppressWarningsAnnotation
javaFile.javaContent = '''
public class «g.runtimeGenSetup.simpleName» implements «ISetup», «ISetupExtension» {
public class «runtimeGenSetup.simpleName» implements «ISetup», «ISetupExtension» {
@Override
public «List»<String> getFileExtensions() {
@ -109,10 +107,10 @@ class XtextGeneratorTemplates {
@Override
public «Injector» createInjectorAndDoEMFRegistration() {
«FOR usedGrammar : g.usedGrammars»
«usedGrammar.runtimeSetup».doSetup();
«FOR usedGrammar : langConfig.grammar.usedGrammars»
«usedGrammar.naming.runtimeSetup».doSetup();
«ENDFOR»
«IF g.usedGrammars.isEmpty»
«IF langConfig.grammar.usedGrammars.isEmpty»
// register default ePackages
if (!«'org.eclipse.emf.ecore.resource.Resource'.typeRef».Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
@ -134,7 +132,7 @@ class XtextGeneratorTemplates {
}
public «Injector» createInjector() {
return «Guice».createInjector(new «g.runtimeModule»());
return «Guice».createInjector(new «runtimeModule»());
}
public void register(«Injector» injector) {
@ -190,8 +188,8 @@ class XtextGeneratorTemplates {
'''
def JavaFileAccess createRuntimeModule(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val javaFile = new JavaFileAccess(g.runtimeModule, codeConfig)
val it = langConfig.naming
val javaFile = new JavaFileAccess(runtimeModule, codeConfig)
javaFile.encodingProvider = encodingProvider
javaFile.typeComment = '''
/**
@ -199,7 +197,7 @@ class XtextGeneratorTemplates {
*/
'''
javaFile.javaContent = '''
public class «g.runtimeModule.simpleName» extends «g.runtimeGenModule» {
public class «runtimeModule.simpleName» extends «runtimeGenModule» {
}
'''
@ -207,33 +205,33 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createRuntimeGenModule(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val it = langConfig.naming
val superClass =
if (langConfig.runtimeGenModule.superClassName !== null)
new TypeReference(langConfig.runtimeGenModule.superClassName)
else g.runtimeDefaultModule
val javaFile = new JavaFileAccess(g.runtimeGenModule, codeConfig)
else runtimeDefaultModule
val javaFile = new JavaFileAccess(runtimeGenModule, codeConfig)
javaFile.encodingProvider = encodingProvider
javaFile.typeComment = '''
/**
* Manual modifications go to {@link «g.runtimeModule.simpleName»}.
* Manual modifications go to {@link «runtimeModule.simpleName»}.
*/
'''
javaFile.annotations += new SuppressWarningsAnnotation
javaFile.javaContent = '''
public abstract class «g.runtimeGenModule.simpleName» extends «superClass» {
public abstract class «runtimeGenModule.simpleName» extends «superClass» {
protected «Properties» properties = null;
@Override
public void configure(«Binder» binder) {
properties = tryBindProperties(binder, "«g.name.replaceAll("\\.","/")».properties");
properties = tryBindProperties(binder, "«langConfig.grammar.name.replaceAll("\\.","/")».properties");
super.configure(binder);
}
public void configureLanguageName(«Binder» binder) {
binder.bind(String.class).annotatedWith(«Names».named(«Constants».LANGUAGE_NAME)).toInstance("«g.name»");
binder.bind(String.class).annotatedWith(«Names».named(«Constants».LANGUAGE_NAME)).toInstance("«langConfig.grammar.name»");
}
public void configureFileExtensions(«Binder» binder) {
@ -252,8 +250,8 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createEclipsePluginModule(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val javaFile = new JavaFileAccess(g.eclipsePluginModule, codeConfig)
val it = langConfig.naming
val javaFile = new JavaFileAccess(eclipsePluginModule, codeConfig)
javaFile.encodingProvider = encodingProvider
javaFile.typeComment = '''
/**
@ -261,8 +259,8 @@ class XtextGeneratorTemplates {
*/
'''
javaFile.javaContent = '''
public class «g.eclipsePluginModule.simpleName» extends «g.eclipsePluginGenModule» {
public «g.eclipsePluginModule.simpleName»(«'org.eclipse.ui.plugin.AbstractUIPlugin'.typeRef» plugin) {
public class «eclipsePluginModule.simpleName» extends «eclipsePluginGenModule» {
public «eclipsePluginModule.simpleName»(«'org.eclipse.ui.plugin.AbstractUIPlugin'.typeRef» plugin) {
super(plugin);
}
}
@ -271,24 +269,24 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createEclipsePluginGenModule(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val it = langConfig.naming
val superClass =
if (langConfig.eclipsePluginGenModule.superClassName !== null)
new TypeReference(langConfig.eclipsePluginGenModule.superClassName)
else g.eclipsePluginDefaultModule
val javaFile = new JavaFileAccess(g.eclipsePluginGenModule, codeConfig)
else eclipsePluginDefaultModule
val javaFile = new JavaFileAccess(eclipsePluginGenModule, codeConfig)
javaFile.encodingProvider = encodingProvider
javaFile.typeComment = '''
/**
* Manual modifications go to {@link «g.eclipsePluginModule.simpleName»}.
* Manual modifications go to {@link «eclipsePluginModule.simpleName»}.
*/
'''
javaFile.annotations += new SuppressWarningsAnnotation
javaFile.javaContent = '''
public abstract class «g.eclipsePluginGenModule.simpleName» extends «superClass» {
public abstract class «eclipsePluginGenModule.simpleName» extends «superClass» {
public «g.eclipsePluginGenModule.simpleName»(«'org.eclipse.ui.plugin.AbstractUIPlugin'.typeRef» plugin) {
public «eclipsePluginGenModule.simpleName»(«'org.eclipse.ui.plugin.AbstractUIPlugin'.typeRef» plugin) {
super(plugin);
}
@ -333,8 +331,8 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createEclipsePluginExecutableExtensionFactory(LanguageConfig2 langConfig) {
val g = langConfig.grammar
val javaFile = new JavaFileAccess(g.eclipsePluginExecutableExtensionFactory, codeConfig)
val it = langConfig.naming
val javaFile = new JavaFileAccess(eclipsePluginExecutableExtensionFactory, codeConfig)
javaFile.encodingProvider = encodingProvider
javaFile.typeComment = '''
@ -344,16 +342,16 @@ class XtextGeneratorTemplates {
*/
'''
javaFile.javaContent = '''
public class «g.eclipsePluginExecutableExtensionFactory.simpleName» extends «'org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory'.typeRef» {
public class «eclipsePluginExecutableExtensionFactory.simpleName» extends «'org.eclipse.xtext.ui.guice.AbstractGuiceAwareExecutableExtensionFactory'.typeRef» {
@Override
protected «'org.osgi.framework.Bundle'.typeRef» getBundle() {
return «g.eclipsePluginActivator».getInstance().getBundle();
return «eclipsePluginActivator».getInstance().getBundle();
}
@Override
protected «Injector» getInjector() {
return «g.eclipsePluginActivator».getInstance().getInjector(«g.eclipsePluginActivator».«g.name.toUpperCase.replaceAll('\\.', '_')»);
return «eclipsePluginActivator».getInstance().getInjector(«eclipsePluginActivator».«langConfig.grammar.name.toUpperCase.replaceAll('\\.', '_')»);
}
}
@ -363,8 +361,7 @@ class XtextGeneratorTemplates {
}
def JavaFileAccess createEclipsePluginActivator(List<LanguageConfig2> langConfigs) {
val gs = langConfigs.map[grammar].toList
val activator = gs.head.eclipsePluginActivator
val activator = langConfigs.head.naming.eclipsePluginActivator
val javaFile = new JavaFileAccess(activator, codeConfig)
javaFile.encodingProvider = encodingProvider
@ -377,8 +374,8 @@ class XtextGeneratorTemplates {
javaFile.javaContent = '''
public class «activator.simpleName» extends «'org.eclipse.ui.plugin.AbstractUIPlugin'» {
«FOR grammar : gs»
public static final String «grammar.name.toUpperCase.replaceAll('\\.', '_')» = "«grammar.name»";
«FOR lang : langConfigs»
public static final String «lang.grammar.name.toUpperCase.replaceAll('\\.', '_')» = "«lang.grammar.name»";
«ENDFOR»
private static final «Logger» logger = «Logger».getLogger(«activator.simpleName».class);
@ -429,18 +426,18 @@ class XtextGeneratorTemplates {
}
protected Module getRuntimeModule(String grammar) {
«FOR grammar : gs»
if («grammar.name.toUpperCase.replaceAll('\\.', '_')».equals(grammar)) {
return new «grammar.runtimeModule»();
«FOR lang : langConfigs»
if («lang.grammar.name.toUpperCase.replaceAll('\\.', '_')».equals(grammar)) {
return new «lang.naming.runtimeModule»();
}
«ENDFOR»
throw new IllegalArgumentException(grammar);
}
protected «Module» getUiModule(String grammar) {
«FOR grammar : gs»
if («grammar.name.toUpperCase.replaceAll('\\.', '_')».equals(grammar)) {
return new «grammar.eclipsePluginModule»(this);
«FOR lang : langConfigs»
if («lang.grammar.name.toUpperCase.replaceAll('\\.', '_')».equals(grammar)) {
return new «lang.naming.eclipsePluginModule»(this);
}
«ENDFOR»
throw new IllegalArgumentException(grammar);

View file

@ -5,7 +5,7 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.xtext.generator.model;
package org.eclipse.xtext.xtext.generator;
import com.google.common.collect.Maps;
import com.google.inject.Injector;
@ -14,6 +14,9 @@ import org.eclipse.emf.mwe.core.issues.Issues;
import org.eclipse.xtext.generator.IFileSystemAccess2;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.xtext.generator.XtextGenerator;
import org.eclipse.xtext.xtext.generator.model.FileSystemAccess;
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Use this class to configure output paths in the XtextGenerator.

View file

@ -17,8 +17,8 @@ import java.io.File
*/
class ProjectConfigGenerator {
static val INTERFACE_NAME = 'org.eclipse.xtext.xtext.generator.model.IXtextProjectConfig'
static val IMPL_NAME = 'org.eclipse.xtext.xtext.generator.model.XtextProjectConfig'
static val INTERFACE_NAME = 'org.eclipse.xtext.xtext.generator.IXtextProjectConfig'
static val IMPL_NAME = 'org.eclipse.xtext.xtext.generator.XtextProjectConfig'
static val PROJECTS = #[
'runtime', 'runtimeTest', 'genericIde', 'genericIdeTest', 'eclipsePlugin', 'eclipsePluginTest',
@ -56,6 +56,8 @@ class ProjectConfigGenerator {
import org.eclipse.xtext.generator.IFileSystemAccess2;
import org.eclipse.xtext.xtext.generator.IGuiceAwareGeneratorComponent;
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Inject an instance of this interface in order to generate code in a generator fragment.
@ -94,6 +96,9 @@ class ProjectConfigGenerator {
import org.eclipse.xtext.generator.IFileSystemAccess2;
import org.eclipse.xtext.util.Strings;
import org.eclipse.xtext.xtext.generator.XtextGenerator;
import org.eclipse.xtext.xtext.generator.model.FileSystemAccess;
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Use this class to configure output paths in the XtextGenerator.

View file

@ -15,6 +15,7 @@ import org.eclipse.emf.codegen.util.CodeGenUtil
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend2.lib.StringConcatenation
import org.eclipse.xtend2.lib.StringConcatenationClient
import org.eclipse.xtext.xtext.generator.CodeConfig
class JavaFileAccess extends TextFileAccess {

View file

@ -13,7 +13,6 @@ import static org.eclipse.emf.ecore.util.EcoreUtil.*;
import static org.eclipse.xtext.EcoreUtil2.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@ -65,17 +64,22 @@ public class GrammarUtil {
}
public static String getName(Grammar g) {
if (Strings.isEmpty(g.getName()))
String fullName = g.getName();
if (Strings.isEmpty(fullName))
return null;
String[] splitted = g.getName().split("\\.");
return splitted[splitted.length - 1];
int nameIndex = fullName.lastIndexOf('.');
return fullName.substring(nameIndex + 1);
}
public static String getNamespace(Grammar g) {
if (Strings.isEmpty(g.getName()))
String fullName = g.getName();
if (Strings.isEmpty(fullName))
return null;
String[] splitted = g.getName().split("\\.");
return Strings.concat(".", Arrays.asList(splitted), 1);
int nameIndex = fullName.lastIndexOf('.');
if (nameIndex < 0)
return "";
else
return fullName.substring(0, nameIndex);
}
public static Grammar getGrammar(EObject grammarElement) {

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
grammar org.eclipse.xtext.common.Terminals hidden(WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;