mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[generator] Added templates for Guice modules
Signed-off-by: Miro Spönemann <miro.spoenemann@itemis.de>
This commit is contained in:
parent
bf193c5146
commit
72839ab971
10 changed files with 317 additions and 197 deletions
|
@ -33,32 +33,69 @@ import org.eclipse.xtext.resource.IResourceServiceProvider
|
|||
import org.eclipse.xtext.resource.XtextResource
|
||||
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.JavaFileAccess
|
||||
|
||||
@Log
|
||||
class LanguageConfig2 extends CompositeGeneratorFragment2 {
|
||||
|
||||
@Inject Provider<ResourceSet> resourceSetProvider
|
||||
|
||||
@Inject XtextGeneratorTemplates generatorTemplates
|
||||
|
||||
@Accessors
|
||||
String uri
|
||||
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
Grammar grammar
|
||||
|
||||
@Accessors(PUBLIC_GETTER)
|
||||
List<String> fileExtensions
|
||||
|
||||
@Accessors
|
||||
val List<String> loadedResources = newArrayList
|
||||
|
||||
JavaFileAccess runtimeSetupImpl
|
||||
|
||||
GuiceModuleAccess runtimeModule
|
||||
|
||||
GuiceModuleAccess eclipsePluginModule
|
||||
|
||||
def void setFileExtensions(String fileExtensions) {
|
||||
this.fileExtensions = fileExtensions.trim.split("\\s*,\\s*").toList
|
||||
}
|
||||
|
||||
def List<String> getFileExtensions() {
|
||||
if (fileExtensions === null || fileExtensions.empty) {
|
||||
val lowerCase = GrammarUtil.getName(grammar).toLowerCase
|
||||
if (LOG.infoEnabled)
|
||||
LOG.info("No explicit fileExtensions configured. Using '*." + lowerCase + "'.")
|
||||
return Collections.singletonList(lowerCase)
|
||||
}
|
||||
return fileExtensions
|
||||
}
|
||||
|
||||
def void addLoadedResource(String uri) {
|
||||
this.loadedResources.add(uri)
|
||||
}
|
||||
|
||||
def JavaFileAccess getRuntimeSetup() {
|
||||
if (runtimeSetupImpl === null)
|
||||
runtimeSetupImpl = generatorTemplates.startRuntimeGenSetup()
|
||||
return runtimeSetupImpl
|
||||
}
|
||||
|
||||
def GuiceModuleAccess getRuntimeModule() {
|
||||
if (runtimeModule == null)
|
||||
runtimeModule = generatorTemplates.startRuntimeGenModule()
|
||||
return runtimeModule
|
||||
}
|
||||
|
||||
def GuiceModuleAccess getEclipsePluginModule() {
|
||||
if (eclipsePluginModule == null)
|
||||
eclipsePluginModule = generatorTemplates.startEclipsePluginGenModule()
|
||||
return eclipsePluginModule
|
||||
}
|
||||
|
||||
def void initialize() {
|
||||
val rs = resourceSetProvider.get()
|
||||
for (String loadedResource : loadedResources) {
|
||||
|
|
|
@ -66,7 +66,12 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
var IEncodingProvider encodingProvider
|
||||
for (language : languageConfigs) {
|
||||
val injector = language.createInjector()
|
||||
|
||||
language.generate()
|
||||
val templates = injector.getInstance(XtextGeneratorTemplates)
|
||||
language.generateRuntimeSetup(project, templates)
|
||||
language.generateModules(project, templates)
|
||||
|
||||
if (project === null)
|
||||
project = injector.getInstance(IXtextProjectConfig)
|
||||
if (encodingProvider === null)
|
||||
|
@ -74,11 +79,26 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
}
|
||||
if (project !== null) {
|
||||
project.generateManifests()
|
||||
project.generateModules()
|
||||
project.generatePluginXmls(encodingProvider)
|
||||
}
|
||||
}
|
||||
|
||||
protected def generateRuntimeSetup(LanguageConfig2 language, IXtextProjectConfig project,
|
||||
XtextGeneratorTemplates templates) {
|
||||
templates.runtimeSetup.writeTo(project.runtimeSrc)
|
||||
templates.finishRuntimeGenSetup(language.runtimeSetup).writeTo(project.runtimeSrcGen)
|
||||
}
|
||||
|
||||
protected def generateModules(LanguageConfig2 language, IXtextProjectConfig project,
|
||||
XtextGeneratorTemplates templates) {
|
||||
templates.runtimeModule.writeTo(project.runtimeSrc)
|
||||
templates.finishGenModule(language.runtimeModule).writeTo(project.runtimeSrcGen)
|
||||
if (project.eclipsePluginSrc !== null)
|
||||
templates.eclipsePluginModule.writeTo(project.eclipsePluginSrc)
|
||||
if (project.eclipsePluginSrcGen !== null)
|
||||
templates.finishGenModule(language.eclipsePluginModule).writeTo(project.eclipsePluginSrcGen)
|
||||
}
|
||||
|
||||
protected def generateManifests(IXtextProjectConfig project) {
|
||||
project.runtimeManifest?.generate()
|
||||
project.runtimeTestManifest?.generate()
|
||||
|
@ -92,19 +112,6 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
|
|||
project.webTestManifest?.generate()
|
||||
}
|
||||
|
||||
protected def generateModules(IXtextProjectConfig project) {
|
||||
project.runtimeModule?.generate()
|
||||
project.runtimeTestModule?.generate()
|
||||
project.genericIdeModule?.generate()
|
||||
project.genericIdeTestModule?.generate()
|
||||
project.eclipsePluginModule?.generate()
|
||||
project.eclipsePluginTestModule?.generate()
|
||||
project.ideaPluginModule?.generate()
|
||||
project.ideaPluginTestModule?.generate()
|
||||
project.webModule?.generate()
|
||||
project.webTestModule?.generate()
|
||||
}
|
||||
|
||||
protected def generatePluginXmls(IXtextProjectConfig project, IEncodingProvider encodingProvider) {
|
||||
generatePluginXml(project.runtimePluginXml, encodingProvider)
|
||||
generatePluginXml(project.runtimeTestPluginXml, encodingProvider)
|
||||
|
|
|
@ -13,32 +13,52 @@ import static org.eclipse.xtext.GrammarUtil.*
|
|||
|
||||
class XtextGeneratorNaming {
|
||||
|
||||
def getPackage(String qualifiedName) {
|
||||
qualifiedName.substring(0, qualifiedName.lastIndexOf('.'))
|
||||
}
|
||||
|
||||
def getSimple(String qualifiedName) {
|
||||
qualifiedName.substring(qualifiedName.lastIndexOf('.'))
|
||||
}
|
||||
|
||||
def getRuntimeBasePackage(Grammar grammar) {
|
||||
getNamespace(grammar)
|
||||
}
|
||||
|
||||
def getRuntimeGuiceModuleSimple(Grammar grammar) {
|
||||
getName(grammar) + 'RuntimeModule'
|
||||
def getRuntimeModule(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + getName(grammar) + 'RuntimeModule'
|
||||
}
|
||||
|
||||
def getRuntimeGuiceModuleFull(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + grammar.runtimeGuiceModuleSimple
|
||||
def getRuntimeGenModule(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + 'Abstract' + getName(grammar) + 'RuntimeModule'
|
||||
}
|
||||
|
||||
def getRuntimeSetupSimple(Grammar grammar) {
|
||||
getName(grammar) + 'StandaloneSetup'
|
||||
def getRuntimeDefaultModule(Grammar grammar) {
|
||||
'org.eclipse.xtext.service.DefaultRuntimeModule'
|
||||
}
|
||||
|
||||
def getRuntimeSetupFull(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + grammar.runtimeSetupSimple
|
||||
def getRuntimeSetup(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + getName(grammar) + 'StandaloneSetup'
|
||||
}
|
||||
|
||||
def getRuntimeSetupImplSimple(Grammar grammar) {
|
||||
getName(grammar) + 'StandaloneSetupGenerated'
|
||||
def getRuntimeGenSetup(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + getName(grammar) + 'StandaloneSetupGenerated'
|
||||
}
|
||||
|
||||
def getRuntimeSetupImplFull(Grammar grammar) {
|
||||
grammar.runtimeBasePackage + grammar.runtimeSetupImplSimple
|
||||
def getEclipsePluginBasePackage(Grammar grammar) {
|
||||
getNamespace(grammar) + '.ui'
|
||||
}
|
||||
|
||||
def getEclipsePluginModule(Grammar grammar) {
|
||||
grammar.eclipsePluginBasePackage + getName(grammar) + 'UiModule'
|
||||
}
|
||||
|
||||
def getEclipsePluginGenModule(Grammar grammar) {
|
||||
grammar.eclipsePluginBasePackage + 'Abstract' + getName(grammar) + 'UiModule'
|
||||
}
|
||||
|
||||
def getEclipsePluginDefaultModule(Grammar grammar) {
|
||||
'org.eclipse.xtext.ui.DefaultUiModule'
|
||||
}
|
||||
|
||||
}
|
|
@ -8,10 +8,13 @@
|
|||
package org.eclipse.xtext.xtext.generator
|
||||
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
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.TextFileAccess
|
||||
|
||||
@Singleton
|
||||
class XtextGeneratorTemplates {
|
||||
|
||||
@Inject extension XtextGeneratorNaming
|
||||
|
@ -20,25 +23,28 @@ class XtextGeneratorTemplates {
|
|||
|
||||
@Inject CodeConfig codeConfig
|
||||
|
||||
def startPluginXml(TextFileAccess file) {
|
||||
def TextFileAccess startPluginXml(TextFileAccess file) {
|
||||
file.path = 'plugin.xml'
|
||||
file.codeFragments += '''
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.0"?>
|
||||
|
||||
<plugin>
|
||||
'''
|
||||
return file
|
||||
}
|
||||
|
||||
def void finishPluginXml(TextFileAccess file) {
|
||||
def TextFileAccess finishPluginXml(TextFileAccess file) {
|
||||
file.codeFragments += '''
|
||||
</plugin>
|
||||
'''
|
||||
return file
|
||||
}
|
||||
|
||||
def getRuntimeSetup() {
|
||||
def JavaFileAccess getRuntimeSetup() {
|
||||
val grammar = langConfig.grammar
|
||||
val javaFile = new JavaFileAccess(grammar.runtimeBasePackage, codeConfig)
|
||||
val runtimeSetupImpl = javaFile.imported(grammar.runtimeSetupImplFull)
|
||||
val javaFile = new JavaFileAccess(grammar.runtimeSetup, codeConfig)
|
||||
val runtimeSetupImpl = javaFile.imported(grammar.runtimeGenSetup)
|
||||
|
||||
javaFile.typeComment = '''
|
||||
/**
|
||||
|
@ -46,19 +52,20 @@ class XtextGeneratorTemplates {
|
|||
*/
|
||||
'''
|
||||
javaFile.codeFragments += '''
|
||||
public class «grammar.runtimeSetupSimple» extends «runtimeSetupImpl»{
|
||||
public class «grammar.runtimeSetup.simple» extends «runtimeSetupImpl»{
|
||||
|
||||
public static void doSetup() {
|
||||
new «grammar.runtimeSetupSimple»().createInjectorAndDoEMFRegistration();
|
||||
new «grammar.runtimeSetup.simple»().createInjectorAndDoEMFRegistration();
|
||||
}
|
||||
|
||||
}
|
||||
'''
|
||||
return javaFile
|
||||
}
|
||||
|
||||
def startRuntimeSetupImpl() {
|
||||
def JavaFileAccess startRuntimeGenSetup() {
|
||||
val grammar = langConfig.grammar
|
||||
val javaFile = new JavaFileAccess(grammar.runtimeBasePackage, codeConfig)
|
||||
val javaFile = new JavaFileAccess(grammar.runtimeGenSetup, codeConfig)
|
||||
javaFile.imported('org.eclipse.emf.ecore.EPackage')
|
||||
javaFile.imported('org.eclipse.emf.ecore.resource.Resource')
|
||||
javaFile.imported('org.eclipse.xtext.ISetup')
|
||||
|
@ -67,11 +74,11 @@ class XtextGeneratorTemplates {
|
|||
javaFile.imported('com.google.inject.Injector')
|
||||
javaFile.imported('java.util.List')
|
||||
javaFile.imported('java.util.Arrays')
|
||||
val runtimeGuiceModule = javaFile.imported(grammar.runtimeGuiceModuleFull)
|
||||
val usedRuntimeSetups = grammar.usedGrammars.map[javaFile.imported(runtimeSetupFull)]
|
||||
val runtimeGuiceModule = javaFile.imported(grammar.runtimeModule)
|
||||
val usedRuntimeSetups = grammar.usedGrammars.map[javaFile.imported(it.runtimeSetup)]
|
||||
|
||||
javaFile.codeFragments += '''
|
||||
public class «grammar.runtimeSetupImplFull» implements ISetup, ISetupExtension {
|
||||
public class «grammar.runtimeGenSetup.simple» implements ISetup, ISetupExtension {
|
||||
|
||||
@Override
|
||||
public List<String> getFileExtensions() {
|
||||
|
@ -109,13 +116,165 @@ class XtextGeneratorTemplates {
|
|||
|
||||
public void register(Injector injector) {
|
||||
'''
|
||||
javaFile.markedAsGenerated = true
|
||||
return javaFile
|
||||
}
|
||||
|
||||
def void finishRuntimeSetupImpl(JavaFileAccess javaFile) {
|
||||
def JavaFileAccess finishRuntimeGenSetup(JavaFileAccess javaFile) {
|
||||
javaFile.codeFragments += '''
|
||||
}
|
||||
}
|
||||
'''
|
||||
return javaFile
|
||||
}
|
||||
|
||||
private def getBindMethodName(GuiceModuleAccess.Binding it) {
|
||||
(if (!value.provider && value.statements.isEmpty)
|
||||
'bind'
|
||||
else if (value.statements.isEmpty)
|
||||
'provide'
|
||||
else 'configure')
|
||||
+ getSimpleMethodName(key.type)
|
||||
+ if (value.expression !== null && !value.provider) 'ToInstance' else ''
|
||||
}
|
||||
|
||||
private def getSimpleMethodName(String qn) {
|
||||
qn.replaceAll('<', '\\.').replaceAll('>', '\\.').split('\\.').filter[matches('[A-Z].*')].join('$')
|
||||
}
|
||||
|
||||
private def endsWith(CharSequence sequence, char c) {
|
||||
sequence.length > 0 && sequence.charAt(sequence.length - 1) == c
|
||||
}
|
||||
|
||||
def JavaFileAccess getRuntimeModule() {
|
||||
val grammar = langConfig.grammar
|
||||
val javaFile = new JavaFileAccess(grammar.runtimeModule, codeConfig)
|
||||
val runtimeGeneratedModule = javaFile.imported(grammar.runtimeGenModule)
|
||||
javaFile.typeComment = '''
|
||||
/**
|
||||
* Use this class to register components to be used at runtime / without the Equinox extension registry.
|
||||
*/
|
||||
'''
|
||||
javaFile.codeFragments += '''
|
||||
public class «grammar.runtimeModule.simple» extends «runtimeGeneratedModule» {
|
||||
|
||||
}
|
||||
'''
|
||||
return javaFile
|
||||
}
|
||||
|
||||
def GuiceModuleAccess startRuntimeGenModule() {
|
||||
val grammar = langConfig.grammar
|
||||
val module = new GuiceModuleAccess(grammar.runtimeGenModule, codeConfig)
|
||||
module.imported('java.util.Properties')
|
||||
module.imported('org.eclipse.xtext.Constants')
|
||||
module.imported('com.google.inject.Binder')
|
||||
module.imported('com.google.inject.name.Names')
|
||||
val runtimeDefaultModule = module.imported(grammar.runtimeDefaultModule)
|
||||
|
||||
module.typeComment = '''
|
||||
/**
|
||||
* Manual modifications go to {@link «grammar.runtimeModule.simple»}.
|
||||
*/
|
||||
'''
|
||||
module.codeFragments += '''
|
||||
public abstract class «grammar.runtimeGenModule.simple» extends «runtimeDefaultModule» {
|
||||
|
||||
protected Properties properties = null;
|
||||
|
||||
@Override
|
||||
public void configure(Binder binder) {
|
||||
properties = tryBindProperties(binder, "«grammar.name.replaceAll("\\.","/")».properties");
|
||||
super.configure(binder);
|
||||
}
|
||||
|
||||
public void configureLanguageName(Binder binder) {
|
||||
binder.bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME)).toInstance("«grammar.name»");
|
||||
}
|
||||
|
||||
public void configureFileExtensions(Binder binder) {
|
||||
if (properties == null || properties.getProperty(Constants.FILE_EXTENSIONS) == null)
|
||||
binder.bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("«langConfig.fileExtensions.join(',')»");
|
||||
}
|
||||
'''
|
||||
module.markedAsGenerated = true
|
||||
return module
|
||||
}
|
||||
|
||||
def JavaFileAccess getEclipsePluginModule() {
|
||||
val g = langConfig.grammar
|
||||
val javaFile = new JavaFileAccess(g.eclipsePluginModule, codeConfig)
|
||||
val eclipsePluginGenGuiceModule = javaFile.imported(g.eclipsePluginGenModule)
|
||||
javaFile.imported('org.eclipse.ui.plugin.AbstractUIPlugin')
|
||||
javaFile.typeComment = '''
|
||||
/**
|
||||
* Use this class to register components to be used within the Eclipse IDE.
|
||||
*/
|
||||
'''
|
||||
javaFile.codeFragments += '''
|
||||
public class «g.eclipsePluginModule.simple» extends «eclipsePluginGenGuiceModule» {
|
||||
public «g.eclipsePluginModule.simple»(AbstractUIPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
}
|
||||
'''
|
||||
return javaFile
|
||||
}
|
||||
|
||||
def GuiceModuleAccess startEclipsePluginGenModule() {
|
||||
val g = langConfig.grammar
|
||||
val module = new GuiceModuleAccess(g.eclipsePluginGenModule, codeConfig)
|
||||
module.imported('org.eclipse.ui.plugin.AbstractUIPlugin')
|
||||
val eclipsePluginDefaultModule = module.imported(g.eclipsePluginDefaultModule)
|
||||
|
||||
module.typeComment = '''
|
||||
/**
|
||||
* Manual modifications go to {@link «g.eclipsePluginModule.simple»}.
|
||||
*/
|
||||
'''
|
||||
module.codeFragments += '''
|
||||
public abstract class «g.eclipsePluginGenModule.simple» extends «eclipsePluginDefaultModule» {
|
||||
|
||||
public «g.eclipsePluginGenModule.simple»(AbstractUIPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
'''
|
||||
module.markedAsGenerated = true
|
||||
return module
|
||||
}
|
||||
|
||||
def GuiceModuleAccess finishGenModule(GuiceModuleAccess module) {
|
||||
val binder = module.imported('com.google.inject.Binder')
|
||||
val provider = module.imported('com.google.inject.Provider')
|
||||
val singletonBinding = module.imported('org.eclipse.xtext.service.SingletonBinding')
|
||||
for (it : module.bindings) {
|
||||
module.codeFragments += '''
|
||||
«IF !value.provider && value.statements.isEmpty»
|
||||
// contributed by «contributedBy»
|
||||
«IF key.singleton»@«singletonBinding»«IF key.eagerSingleton»(eager=true)«ENDIF»«ENDIF»
|
||||
public «IF value.expression === null»Class<? extends «module.imported(key.type)»>«ELSE»«module.imported(key.type)»«ENDIF» «bindMethodName»() {
|
||||
return «IF value.expression !== null»«value.expression»«ELSE»«value.typeName».class«ENDIF»;
|
||||
}
|
||||
«ELSEIF value.statements.isEmpty»
|
||||
// contributed by «contributedBy»
|
||||
«IF key.singleton»@«singletonBinding»«IF key.eagerSingleton»(eager=true)«ENDIF»«ENDIF»
|
||||
public «IF value.expression==null»Class<? extends «provider»<«key.type»>>«ELSE»«provider»<«key.type»>«ENDIF» «bindMethodName»() {
|
||||
return «IF value.expression!=null»«value.expression»«ELSE»«value.typeName».class«ENDIF»;
|
||||
}
|
||||
«ELSE»
|
||||
// contributed by «contributedBy»
|
||||
public void «bindMethodName»(«binder» binder) {
|
||||
«FOR statement : value.statements»
|
||||
«statement»«IF !statement.endsWith(';')»;«ENDIF»
|
||||
«ENDFOR»
|
||||
}
|
||||
«ENDIF»
|
||||
'''
|
||||
}
|
||||
module.codeFragments += '''
|
||||
}
|
||||
'''
|
||||
return module
|
||||
}
|
||||
|
||||
}
|
|
@ -55,8 +55,6 @@ class ProjectConfigGenerator {
|
|||
package «INTERFACE_NAME.substring(0, INTERFACE_NAME.lastIndexOf('.'))»;
|
||||
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.ModuleAccess;
|
||||
|
||||
/**
|
||||
* Inject an instance of this interface in order to generate code in a generator fragment.
|
||||
|
@ -69,7 +67,6 @@ class ProjectConfigGenerator {
|
|||
IFileSystemAccess2 get«p.toFirstUpper»Src();
|
||||
IFileSystemAccess2 get«p.toFirstUpper»SrcGen();
|
||||
ManifestAccess get«p.toFirstUpper»Manifest();
|
||||
ModuleAccess get«p.toFirstUpper»Module();
|
||||
TextFileAccess get«p.toFirstUpper»PluginXml();
|
||||
|
||||
«ENDFOR»
|
||||
|
@ -92,9 +89,6 @@ class ProjectConfigGenerator {
|
|||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.parser.IEncodingProvider;
|
||||
import org.eclipse.xtext.xtext.generator.model.FileSystemAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.ModuleAccess;
|
||||
|
||||
/**
|
||||
* Use this class to configure output paths in the XtextGenerator.
|
||||
|
@ -109,7 +103,6 @@ class ProjectConfigGenerator {
|
|||
private String «p»SrcPath;
|
||||
private String «p»SrcGenPath;
|
||||
private ManifestAccess «p»ManifestAccess;
|
||||
private ModuleAccess «p»ModuleAccess;
|
||||
private TextFileAccess «p»PluginXmlAccess;
|
||||
«ENDFOR»
|
||||
private String orionJsGenPath;
|
||||
|
@ -152,14 +145,6 @@ class ProjectConfigGenerator {
|
|||
this.«p»ManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess get«p.toFirstUpper»Module() {
|
||||
if («p»ModuleAccess == null) {
|
||||
«p»ModuleAccess = new ModuleAccess(get«p.toFirstUpper»SrcGen());
|
||||
}
|
||||
return «p»ModuleAccess;
|
||||
}
|
||||
|
||||
public void set«p.toFirstUpper»PluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.«p»PluginXmlAccess = new TextFileAccess();
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 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.xtext.xtext.generator.model
|
||||
|
||||
import java.util.List
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtend.lib.annotations.Data
|
||||
|
||||
class GuiceModuleAccess extends JavaFileAccess {
|
||||
|
||||
@Data
|
||||
static class BindKey {
|
||||
String type
|
||||
boolean singleton
|
||||
boolean eagerSingleton
|
||||
}
|
||||
|
||||
@Data
|
||||
static class BindValue {
|
||||
private String expression
|
||||
private String typeName
|
||||
private boolean provider
|
||||
private List<CharSequence> statements
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Binding {
|
||||
BindKey key
|
||||
BindValue value
|
||||
String contributedBy
|
||||
boolean isFinal
|
||||
}
|
||||
|
||||
@Accessors
|
||||
val List<Binding> bindings = newArrayList
|
||||
|
||||
new(String qualifiedName, CodeConfig codeConfig) {
|
||||
super(qualifiedName, codeConfig)
|
||||
}
|
||||
|
||||
}
|
|
@ -8,8 +8,6 @@
|
|||
package org.eclipse.xtext.xtext.generator.model;
|
||||
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.ModuleAccess;
|
||||
|
||||
/**
|
||||
* Inject an instance of this interface in order to generate code in a generator fragment.
|
||||
|
@ -21,61 +19,51 @@ public interface IXtextProjectConfig {
|
|||
IFileSystemAccess2 getRuntimeSrc();
|
||||
IFileSystemAccess2 getRuntimeSrcGen();
|
||||
ManifestAccess getRuntimeManifest();
|
||||
ModuleAccess getRuntimeModule();
|
||||
TextFileAccess getRuntimePluginXml();
|
||||
|
||||
IFileSystemAccess2 getRuntimeTestSrc();
|
||||
IFileSystemAccess2 getRuntimeTestSrcGen();
|
||||
ManifestAccess getRuntimeTestManifest();
|
||||
ModuleAccess getRuntimeTestModule();
|
||||
TextFileAccess getRuntimeTestPluginXml();
|
||||
|
||||
IFileSystemAccess2 getGenericIdeSrc();
|
||||
IFileSystemAccess2 getGenericIdeSrcGen();
|
||||
ManifestAccess getGenericIdeManifest();
|
||||
ModuleAccess getGenericIdeModule();
|
||||
TextFileAccess getGenericIdePluginXml();
|
||||
|
||||
IFileSystemAccess2 getGenericIdeTestSrc();
|
||||
IFileSystemAccess2 getGenericIdeTestSrcGen();
|
||||
ManifestAccess getGenericIdeTestManifest();
|
||||
ModuleAccess getGenericIdeTestModule();
|
||||
TextFileAccess getGenericIdeTestPluginXml();
|
||||
|
||||
IFileSystemAccess2 getEclipsePluginSrc();
|
||||
IFileSystemAccess2 getEclipsePluginSrcGen();
|
||||
ManifestAccess getEclipsePluginManifest();
|
||||
ModuleAccess getEclipsePluginModule();
|
||||
TextFileAccess getEclipsePluginPluginXml();
|
||||
|
||||
IFileSystemAccess2 getEclipsePluginTestSrc();
|
||||
IFileSystemAccess2 getEclipsePluginTestSrcGen();
|
||||
ManifestAccess getEclipsePluginTestManifest();
|
||||
ModuleAccess getEclipsePluginTestModule();
|
||||
TextFileAccess getEclipsePluginTestPluginXml();
|
||||
|
||||
IFileSystemAccess2 getIdeaPluginSrc();
|
||||
IFileSystemAccess2 getIdeaPluginSrcGen();
|
||||
ManifestAccess getIdeaPluginManifest();
|
||||
ModuleAccess getIdeaPluginModule();
|
||||
TextFileAccess getIdeaPluginPluginXml();
|
||||
|
||||
IFileSystemAccess2 getIdeaPluginTestSrc();
|
||||
IFileSystemAccess2 getIdeaPluginTestSrcGen();
|
||||
ManifestAccess getIdeaPluginTestManifest();
|
||||
ModuleAccess getIdeaPluginTestModule();
|
||||
TextFileAccess getIdeaPluginTestPluginXml();
|
||||
|
||||
IFileSystemAccess2 getWebSrc();
|
||||
IFileSystemAccess2 getWebSrcGen();
|
||||
ManifestAccess getWebManifest();
|
||||
ModuleAccess getWebModule();
|
||||
TextFileAccess getWebPluginXml();
|
||||
|
||||
IFileSystemAccess2 getWebTestSrc();
|
||||
IFileSystemAccess2 getWebTestSrcGen();
|
||||
ManifestAccess getWebTestManifest();
|
||||
ModuleAccess getWebTestModule();
|
||||
TextFileAccess getWebTestPluginXml();
|
||||
|
||||
IFileSystemAccess2 getOrionJsGen();
|
||||
|
|
|
@ -27,14 +27,11 @@ class JavaFileAccess extends TextFileAccess {
|
|||
@Accessors
|
||||
boolean markedAsGenerated
|
||||
|
||||
new(String packageName, CodeConfig codeConfig) {
|
||||
this.packageName = packageName
|
||||
this.codeConfig = codeConfig
|
||||
}
|
||||
|
||||
new(String packageName, String simpleName, CodeConfig codeConfig) {
|
||||
new(String qualifiedName, CodeConfig codeConfig) {
|
||||
val simpleNameIndex = qualifiedName.lastIndexOf('.')
|
||||
this.packageName = qualifiedName.substring(0, simpleNameIndex)
|
||||
val simpleName = qualifiedName.substring(simpleNameIndex + 1)
|
||||
this.path = packageName.replace('.', '/') + '/' + simpleName + '.java'
|
||||
this.packageName = packageName
|
||||
this.codeConfig = codeConfig
|
||||
}
|
||||
|
||||
|
@ -60,10 +57,8 @@ class JavaFileAccess extends TextFileAccess {
|
|||
}
|
||||
|
||||
override generate() {
|
||||
for (annot : codeConfig.classAnnotations) {
|
||||
if (annot.appliesTo(this))
|
||||
imported(annot.annotationImport)
|
||||
}
|
||||
val classAnnotations = codeConfig.classAnnotations.filter[appliesTo(this)]
|
||||
classAnnotations.forEach[imported(annotationImport)]
|
||||
val sortedImports = Lists.newArrayList(imports.values())
|
||||
Collections.sort(sortedImports)
|
||||
return '''
|
||||
|
@ -75,10 +70,8 @@ class JavaFileAccess extends TextFileAccess {
|
|||
«ENDFOR»
|
||||
|
||||
«typeComment»
|
||||
«FOR annot : codeConfig.classAnnotations»
|
||||
«IF annot.appliesTo(this)»
|
||||
«annot.generate()»
|
||||
«ENDIF»
|
||||
«FOR annot : classAnnotations»
|
||||
«annot.generate()»
|
||||
«ENDFOR»
|
||||
«FOR fragment : codeFragments»
|
||||
«fragment»
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 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.xtext.xtext.generator.model
|
||||
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2
|
||||
|
||||
class ModuleAccess {
|
||||
|
||||
new(IFileSystemAccess2 outlet) {
|
||||
|
||||
}
|
||||
|
||||
def void generate() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -10,9 +10,6 @@ package org.eclipse.xtext.xtext.generator.model;
|
|||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtext.generator.IFileSystemAccess2;
|
||||
import org.eclipse.xtext.parser.IEncodingProvider;
|
||||
import org.eclipse.xtext.xtext.generator.model.FileSystemAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
|
||||
import org.eclipse.xtext.xtext.generator.model.ModuleAccess;
|
||||
|
||||
/**
|
||||
* Use this class to configure output paths in the XtextGenerator.
|
||||
|
@ -26,52 +23,42 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
private String runtimeSrcPath;
|
||||
private String runtimeSrcGenPath;
|
||||
private ManifestAccess runtimeManifestAccess;
|
||||
private ModuleAccess runtimeModuleAccess;
|
||||
private TextFileAccess runtimePluginXmlAccess;
|
||||
private String runtimeTestSrcPath;
|
||||
private String runtimeTestSrcGenPath;
|
||||
private ManifestAccess runtimeTestManifestAccess;
|
||||
private ModuleAccess runtimeTestModuleAccess;
|
||||
private TextFileAccess runtimeTestPluginXmlAccess;
|
||||
private String genericIdeSrcPath;
|
||||
private String genericIdeSrcGenPath;
|
||||
private ManifestAccess genericIdeManifestAccess;
|
||||
private ModuleAccess genericIdeModuleAccess;
|
||||
private TextFileAccess genericIdePluginXmlAccess;
|
||||
private String genericIdeTestSrcPath;
|
||||
private String genericIdeTestSrcGenPath;
|
||||
private ManifestAccess genericIdeTestManifestAccess;
|
||||
private ModuleAccess genericIdeTestModuleAccess;
|
||||
private TextFileAccess genericIdeTestPluginXmlAccess;
|
||||
private String eclipsePluginSrcPath;
|
||||
private String eclipsePluginSrcGenPath;
|
||||
private ManifestAccess eclipsePluginManifestAccess;
|
||||
private ModuleAccess eclipsePluginModuleAccess;
|
||||
private TextFileAccess eclipsePluginPluginXmlAccess;
|
||||
private String eclipsePluginTestSrcPath;
|
||||
private String eclipsePluginTestSrcGenPath;
|
||||
private ManifestAccess eclipsePluginTestManifestAccess;
|
||||
private ModuleAccess eclipsePluginTestModuleAccess;
|
||||
private TextFileAccess eclipsePluginTestPluginXmlAccess;
|
||||
private String ideaPluginSrcPath;
|
||||
private String ideaPluginSrcGenPath;
|
||||
private ManifestAccess ideaPluginManifestAccess;
|
||||
private ModuleAccess ideaPluginModuleAccess;
|
||||
private TextFileAccess ideaPluginPluginXmlAccess;
|
||||
private String ideaPluginTestSrcPath;
|
||||
private String ideaPluginTestSrcGenPath;
|
||||
private ManifestAccess ideaPluginTestManifestAccess;
|
||||
private ModuleAccess ideaPluginTestModuleAccess;
|
||||
private TextFileAccess ideaPluginTestPluginXmlAccess;
|
||||
private String webSrcPath;
|
||||
private String webSrcGenPath;
|
||||
private ManifestAccess webManifestAccess;
|
||||
private ModuleAccess webModuleAccess;
|
||||
private TextFileAccess webPluginXmlAccess;
|
||||
private String webTestSrcPath;
|
||||
private String webTestSrcGenPath;
|
||||
private ManifestAccess webTestManifestAccess;
|
||||
private ModuleAccess webTestModuleAccess;
|
||||
private TextFileAccess webTestPluginXmlAccess;
|
||||
private String orionJsGenPath;
|
||||
private String aceJsGenPath;
|
||||
|
@ -112,14 +99,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.runtimeManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getRuntimeModule() {
|
||||
if (runtimeModuleAccess == null) {
|
||||
runtimeModuleAccess = new ModuleAccess(getRuntimeSrcGen());
|
||||
}
|
||||
return runtimeModuleAccess;
|
||||
}
|
||||
|
||||
public void setRuntimePluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.runtimePluginXmlAccess = new TextFileAccess();
|
||||
|
@ -167,14 +146,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.runtimeTestManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getRuntimeTestModule() {
|
||||
if (runtimeTestModuleAccess == null) {
|
||||
runtimeTestModuleAccess = new ModuleAccess(getRuntimeTestSrcGen());
|
||||
}
|
||||
return runtimeTestModuleAccess;
|
||||
}
|
||||
|
||||
public void setRuntimeTestPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.runtimeTestPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -222,14 +193,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.genericIdeManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getGenericIdeModule() {
|
||||
if (genericIdeModuleAccess == null) {
|
||||
genericIdeModuleAccess = new ModuleAccess(getGenericIdeSrcGen());
|
||||
}
|
||||
return genericIdeModuleAccess;
|
||||
}
|
||||
|
||||
public void setGenericIdePluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.genericIdePluginXmlAccess = new TextFileAccess();
|
||||
|
@ -277,14 +240,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.genericIdeTestManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getGenericIdeTestModule() {
|
||||
if (genericIdeTestModuleAccess == null) {
|
||||
genericIdeTestModuleAccess = new ModuleAccess(getGenericIdeTestSrcGen());
|
||||
}
|
||||
return genericIdeTestModuleAccess;
|
||||
}
|
||||
|
||||
public void setGenericIdeTestPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.genericIdeTestPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -332,14 +287,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.eclipsePluginManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getEclipsePluginModule() {
|
||||
if (eclipsePluginModuleAccess == null) {
|
||||
eclipsePluginModuleAccess = new ModuleAccess(getEclipsePluginSrcGen());
|
||||
}
|
||||
return eclipsePluginModuleAccess;
|
||||
}
|
||||
|
||||
public void setEclipsePluginPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.eclipsePluginPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -387,14 +334,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.eclipsePluginTestManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getEclipsePluginTestModule() {
|
||||
if (eclipsePluginTestModuleAccess == null) {
|
||||
eclipsePluginTestModuleAccess = new ModuleAccess(getEclipsePluginTestSrcGen());
|
||||
}
|
||||
return eclipsePluginTestModuleAccess;
|
||||
}
|
||||
|
||||
public void setEclipsePluginTestPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.eclipsePluginTestPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -442,14 +381,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.ideaPluginManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getIdeaPluginModule() {
|
||||
if (ideaPluginModuleAccess == null) {
|
||||
ideaPluginModuleAccess = new ModuleAccess(getIdeaPluginSrcGen());
|
||||
}
|
||||
return ideaPluginModuleAccess;
|
||||
}
|
||||
|
||||
public void setIdeaPluginPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.ideaPluginPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -497,14 +428,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.ideaPluginTestManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getIdeaPluginTestModule() {
|
||||
if (ideaPluginTestModuleAccess == null) {
|
||||
ideaPluginTestModuleAccess = new ModuleAccess(getIdeaPluginTestSrcGen());
|
||||
}
|
||||
return ideaPluginTestModuleAccess;
|
||||
}
|
||||
|
||||
public void setIdeaPluginTestPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.ideaPluginTestPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -552,14 +475,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.webManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getWebModule() {
|
||||
if (webModuleAccess == null) {
|
||||
webModuleAccess = new ModuleAccess(getWebSrcGen());
|
||||
}
|
||||
return webModuleAccess;
|
||||
}
|
||||
|
||||
public void setWebPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.webPluginXmlAccess = new TextFileAccess();
|
||||
|
@ -607,14 +522,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
|
|||
this.webTestManifestAccess = manifest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAccess getWebTestModule() {
|
||||
if (webTestModuleAccess == null) {
|
||||
webTestModuleAccess = new ModuleAccess(getWebTestSrcGen());
|
||||
}
|
||||
return webTestModuleAccess;
|
||||
}
|
||||
|
||||
public void setWebTestPluginXml(String path) {
|
||||
if (path != null) {
|
||||
this.webTestPluginXmlAccess = new TextFileAccess();
|
||||
|
|
Loading…
Reference in a new issue