[generator] Added templates for plugin.xml and standalone setup

Signed-off-by: Miro Spönemann <miro.spoenemann@itemis.de>
This commit is contained in:
Miro Spönemann 2015-07-01 11:37:53 +02:00
parent 4d00a50d2f
commit bf193c5146
14 changed files with 568 additions and 203 deletions

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=ISO-8859-1

View file

@ -10,6 +10,7 @@ package org.eclipse.xtext.xtext.generator
import com.google.inject.Guice
import com.google.inject.Injector
import com.google.inject.Module
import java.io.File
import java.util.List
import org.eclipse.emf.mwe.core.WorkflowContext
import org.eclipse.emf.mwe.core.issues.Issues
@ -20,7 +21,9 @@ import org.eclipse.xtext.XtextStandaloneSetup
import org.eclipse.xtext.util.Modules2
import org.eclipse.xtext.xtext.generator.model.CodeConfig
import org.eclipse.xtext.xtext.generator.model.IXtextProjectConfig
import org.eclipse.xtext.xtext.generator.model.TextFileAccess
import org.eclipse.xtext.xtext.generator.model.XtextProjectConfig
import org.eclipse.xtext.parser.IEncodingProvider
/**
* The Xtext language infrastructure generator. Can be configured with {@link IGeneratorFragment}
@ -60,16 +63,19 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
protected override invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
var IXtextProjectConfig project = projectConfig
var IEncodingProvider encodingProvider
for (language : languageConfigs) {
val injector = language.createInjector()
language.generate()
if (project === null)
project = injector.getInstance(IXtextProjectConfig)
if (encodingProvider === null)
encodingProvider = injector.getInstance(IEncodingProvider)
}
if (project !== null) {
project.generateManifests()
project.generatePluginXmls()
project.generateModules()
project.generatePluginXmls(encodingProvider)
}
}
@ -86,19 +92,6 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
project.webTestManifest?.generate()
}
protected def generatePluginXmls(IXtextProjectConfig project) {
project.runtimePluginXml?.generate()
project.runtimeTestPluginXml?.generate()
project.genericIdePluginXml?.generate()
project.genericIdeTestPluginXml?.generate()
project.eclipsePluginPluginXml?.generate()
project.eclipsePluginTestPluginXml?.generate()
project.ideaPluginPluginXml?.generate()
project.ideaPluginTestPluginXml?.generate()
project.webPluginXml?.generate()
project.webTestPluginXml?.generate()
}
protected def generateModules(IXtextProjectConfig project) {
project.runtimeModule?.generate()
project.runtimeTestModule?.generate()
@ -112,6 +105,33 @@ class XtextGenerator extends AbstractWorkflowComponent2 {
project.webTestModule?.generate()
}
protected def generatePluginXmls(IXtextProjectConfig project, IEncodingProvider encodingProvider) {
generatePluginXml(project.runtimePluginXml, encodingProvider)
generatePluginXml(project.runtimeTestPluginXml, encodingProvider)
generatePluginXml(project.genericIdePluginXml, encodingProvider)
generatePluginXml(project.genericIdeTestPluginXml, encodingProvider)
generatePluginXml(project.eclipsePluginPluginXml, encodingProvider)
generatePluginXml(project.eclipsePluginTestPluginXml, encodingProvider)
generatePluginXml(project.ideaPluginPluginXml, encodingProvider)
generatePluginXml(project.ideaPluginTestPluginXml, encodingProvider)
generatePluginXml(project.webPluginXml, encodingProvider)
generatePluginXml(project.webTestPluginXml, encodingProvider)
}
protected def generatePluginXml(TextFileAccess pluginXml, IEncodingProvider encodingProvider) {
if (pluginXml !== null) {
pluginXml.encodingProvider = encodingProvider
if (new File(pluginXml.path).exists) {
if (pluginXml.path.endsWith('.xml')) {
pluginXml.path = pluginXml.path + '_gen'
pluginXml.writeToFile()
}
} else {
pluginXml.writeToFile()
}
}
}
protected def Injector createInjector(LanguageConfig2 languageConfig) {
val guiceConfig = <Module>newArrayList(new DefaultGeneratorModule)
guiceConfig.addAll(modules)

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* 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
import org.eclipse.xtext.Grammar
import static org.eclipse.xtext.GrammarUtil.*
class XtextGeneratorNaming {
def getRuntimeBasePackage(Grammar grammar) {
getNamespace(grammar)
}
def getRuntimeGuiceModuleSimple(Grammar grammar) {
getName(grammar) + 'RuntimeModule'
}
def getRuntimeGuiceModuleFull(Grammar grammar) {
grammar.runtimeBasePackage + grammar.runtimeGuiceModuleSimple
}
def getRuntimeSetupSimple(Grammar grammar) {
getName(grammar) + 'StandaloneSetup'
}
def getRuntimeSetupFull(Grammar grammar) {
grammar.runtimeBasePackage + grammar.runtimeSetupSimple
}
def getRuntimeSetupImplSimple(Grammar grammar) {
getName(grammar) + 'StandaloneSetupGenerated'
}
def getRuntimeSetupImplFull(Grammar grammar) {
grammar.runtimeBasePackage + grammar.runtimeSetupImplSimple
}
}

View file

@ -0,0 +1,121 @@
/*******************************************************************************
* 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
import com.google.inject.Inject
import org.eclipse.xtext.xtext.generator.model.CodeConfig
import org.eclipse.xtext.xtext.generator.model.JavaFileAccess
import org.eclipse.xtext.xtext.generator.model.TextFileAccess
class XtextGeneratorTemplates {
@Inject extension XtextGeneratorNaming
@Inject LanguageConfig2 langConfig
@Inject CodeConfig codeConfig
def startPluginXml(TextFileAccess file) {
file.codeFragments += '''
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
'''
}
def void finishPluginXml(TextFileAccess file) {
file.codeFragments += '''
</plugin>
'''
}
def getRuntimeSetup() {
val grammar = langConfig.grammar
val javaFile = new JavaFileAccess(grammar.runtimeBasePackage, codeConfig)
val runtimeSetupImpl = javaFile.imported(grammar.runtimeSetupImplFull)
javaFile.typeComment = '''
/**
* Initialization support for running Xtext languages without Equinox extension registry.
*/
'''
javaFile.codeFragments += '''
public class «grammar.runtimeSetupSimple» extends «runtimeSetupImpl»{
public static void doSetup() {
new «grammar.runtimeSetupSimple»().createInjectorAndDoEMFRegistration();
}
}
'''
}
def startRuntimeSetupImpl() {
val grammar = langConfig.grammar
val javaFile = new JavaFileAccess(grammar.runtimeBasePackage, codeConfig)
javaFile.imported('org.eclipse.emf.ecore.EPackage')
javaFile.imported('org.eclipse.emf.ecore.resource.Resource')
javaFile.imported('org.eclipse.xtext.ISetup')
javaFile.imported('org.eclipse.xtext.ISetupExtension')
javaFile.imported('com.google.inject.Guice')
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)]
javaFile.codeFragments += '''
public class «grammar.runtimeSetupImplFull» implements ISetup, ISetupExtension {
@Override
public List<String> getFileExtensions() {
return Arrays.asList(«FOR fileExtension : langConfig.fileExtensions SEPARATOR ','»"«fileExtension»"«ENDFOR»);
}
@Override
public Injector createInjectorAndDoEMFRegistration() {
«FOR usedSetup : usedRuntimeSetups»
«usedSetup».doSetup();
«ENDFOR»
«IF grammar.usedGrammars.isEmpty»
// register default ePackages
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xmi", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xtextbin", new org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl());
if (!EPackage.Registry.INSTANCE.containsKey(org.eclipse.xtext.XtextPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(org.eclipse.xtext.XtextPackage.eNS_URI, org.eclipse.xtext.XtextPackage.eINSTANCE);
«ENDIF»
Injector injector = createInjector();
register(injector);
return injector;
}
public Injector createInjector() {
return Guice.createInjector(new «runtimeGuiceModule»());
}
public void register(Injector injector) {
'''
}
def void finishRuntimeSetupImpl(JavaFileAccess javaFile) {
javaFile.codeFragments += '''
}
}
'''
}
}

View file

@ -52,28 +52,27 @@ class ProjectConfigGenerator {
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package «INTERFACE_NAME.substring(0, INTERFACE_NAME.lastIndexOf('.'))»;
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;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Inject an instance of this interface in order to generate code in a generator fragment.
*
* <p>This file has been generated with {@link «ProjectConfigGenerator.name»}.</p>
* <p>This file has been generated with {@link «ProjectConfigGenerator.name»}.</p>
*/
public interface «INTERFACE_NAME.substring(INTERFACE_NAME.lastIndexOf('.') + 1)» {
public interface «INTERFACE_NAME.substring(INTERFACE_NAME.lastIndexOf('.') + 1)» {
«FOR p : PROJECTS»
IFileSystemAccess2 get«p.toFirstUpper»Src();
IFileSystemAccess2 get«p.toFirstUpper»SrcGen();
ManifestAccess get«p.toFirstUpper»Manifest();
PluginXmlAccess get«p.toFirstUpper»PluginXml();
ModuleAccess get«p.toFirstUpper»Module();
«FOR p : PROJECTS»
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»
«ENDFOR»
IFileSystemAccess2 getOrionJsGen();
IFileSystemAccess2 getAceJsGen();
@ -88,7 +87,7 @@ class ProjectConfigGenerator {
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package «IMPL_NAME.substring(0, IMPL_NAME.lastIndexOf('.'))»;
package «IMPL_NAME.substring(0, IMPL_NAME.lastIndexOf('.'))»;
import com.google.inject.Inject;
import org.eclipse.xtext.generator.IFileSystemAccess2;
@ -96,82 +95,86 @@ class ProjectConfigGenerator {
import org.eclipse.xtext.xtext.generator.model.FileSystemAccess;
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
import org.eclipse.xtext.xtext.generator.model.ModuleAccess;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Use this class to configure output paths in the XtextGenerator.
*
* <p>This file has been generated with {@link «ProjectConfigGenerator.name»}.</p>
* <p>This file has been generated with {@link «ProjectConfigGenerator.name»}.</p>
*/
public class «IMPL_NAME.substring(IMPL_NAME.lastIndexOf('.') + 1)» implements «INTERFACE_NAME.substring(INTERFACE_NAME.lastIndexOf('.') + 1)» {
public class «IMPL_NAME.substring(IMPL_NAME.lastIndexOf('.') + 1)» implements «INTERFACE_NAME.substring(INTERFACE_NAME.lastIndexOf('.') + 1)» {
@Inject private IEncodingProvider encodingProvider;
«FOR p : PROJECTS»
private String «p»SrcPath;
private String «p»SrcGenPath;
private ManifestAccess «p»ManifestAccess;
private PluginXmlAccess «p»PluginXmlAccess;
private ModuleAccess «p»ModuleAccess;
«ENDFOR»
«FOR p : PROJECTS»
private String «p»SrcPath;
private String «p»SrcGenPath;
private ManifestAccess «p»ManifestAccess;
private ModuleAccess «p»ModuleAccess;
private TextFileAccess «p»PluginXmlAccess;
«ENDFOR»
private String orionJsGenPath;
private String aceJsGenPath;
public void initialize() {
}
«FOR p : PROJECTS»
«FOR p : PROJECTS»
@Override
public IFileSystemAccess2 get«p.toFirstUpper»Src() {
if («p»SrcPath != null)
return new FileSystemAccess(«p»SrcPath, encodingProvider);
public IFileSystemAccess2 get«p.toFirstUpper»Src() {
if («p»SrcPath != null)
return new FileSystemAccess(«p»SrcPath, encodingProvider);
else
return null;
}
public void set«p.toFirstUpper»Src(String path) {
this.«p»SrcPath = path;
public void set«p.toFirstUpper»Src(String path) {
this.«p»SrcPath = path;
}
@Override
public IFileSystemAccess2 get«p.toFirstUpper»SrcGen() {
if («p»SrcGenPath != null)
return new FileSystemAccess(«p»SrcGenPath, encodingProvider);
public IFileSystemAccess2 get«p.toFirstUpper»SrcGen() {
if («p»SrcGenPath != null)
return new FileSystemAccess(«p»SrcGenPath, encodingProvider);
else
return null;
}
public void set«p.toFirstUpper»SrcGen(String path) {
this.«p»SrcGenPath = path;
public void set«p.toFirstUpper»SrcGen(String path) {
this.«p»SrcGenPath = path;
}
@Override
public ManifestAccess get«p.toFirstUpper»Manifest() {
return «p»ManifestAccess;
public ManifestAccess get«p.toFirstUpper»Manifest() {
return «p»ManifestAccess;
}
public void set«p.toFirstUpper»Manifest(ManifestAccess manifest) {
this.«p»ManifestAccess = manifest;
public void set«p.toFirstUpper»Manifest(ManifestAccess manifest) {
this.«p»ManifestAccess = manifest;
}
@Override
public PluginXmlAccess get«p.toFirstUpper»PluginXml() {
return «p»PluginXmlAccess;
}
public void set«p.toFirstUpper»PluginXml(PluginXmlAccess pluginXml) {
this.«p»PluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess get«p.toFirstUpper»Module() {
if («p»ModuleAccess == null) {
«p»ModuleAccess = new ModuleAccess(get«p.toFirstUpper»SrcGen());
public ModuleAccess get«p.toFirstUpper»Module() {
if («p»ModuleAccess == null) {
«p»ModuleAccess = new ModuleAccess(get«p.toFirstUpper»SrcGen());
}
return «p»ModuleAccess;
return «p»ModuleAccess;
}
«ENDFOR»
public void set«p.toFirstUpper»PluginXml(String path) {
if (path != null) {
this.«p»PluginXmlAccess = new TextFileAccess();
this.«p»PluginXmlAccess.setPath(path);
} else {
this.«p»PluginXmlAccess = null;
}
}
@Override
public TextFileAccess get«p.toFirstUpper»PluginXml() {
return this.«p»PluginXmlAccess;
}
«ENDFOR»
@Override
public IFileSystemAccess2 getOrionJsGen() {
if (orionJsGenPath != null)

View file

@ -37,6 +37,7 @@ class CodeConfig {
String fileHeaderTemplate = "/*\n * generated by Xtext\n */"
@Accessors(PUBLIC_GETTER)
val List<IClassAnnotation> classAnnotations = newArrayList
/**

View file

@ -28,7 +28,7 @@ class FileSystemAccess implements IFileSystemAccess2 {
new(String path, IEncodingProvider encodingProvider) {
this.path = path
this.baseUri = URI.createPlatformResourceURI(path, true)
this.baseUri = URI.createFileURI(path)
this.encodingProvider = encodingProvider
}

View file

@ -24,7 +24,7 @@ class GeneratedClassAnnotation implements IClassAnnotation {
@Accessors
String comment
override String toString() {
override generate() {
val stringBuilder = new StringBuilder('@Generated(')
if (includeDate || !Strings.isEmpty(comment)) {
stringBuilder += 'value = '
@ -46,12 +46,16 @@ class GeneratedClassAnnotation implements IClassAnnotation {
stringBuilder += '"'
}
stringBuilder += ')'
return stringBuilder.toString()
return stringBuilder
}
protected def String getGeneratorName() {
return XtextGenerator.name
}
override appliesTo(JavaFileAccess javaFile) {
return javaFile.markedAsGenerated
}
override getAnnotationImport() {
return 'javax.annotation.Generated'

View file

@ -13,10 +13,15 @@ package org.eclipse.xtext.xtext.generator.model
*/
interface IClassAnnotation {
/**
/**
* Convert the class annotation to a string suitable for use in Java code generation.
*/
override String toString()
def CharSequence generate()
/**
* Determine whether this annotation should be applied to the given Java file.
*/
def boolean appliesTo(JavaFileAccess javaFile)
/**
* Return the qualified name of the annotation interface for use in import declarations,

View file

@ -10,7 +10,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;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Inject an instance of this interface in order to generate code in a generator fragment.
@ -22,62 +21,62 @@ public interface IXtextProjectConfig {
IFileSystemAccess2 getRuntimeSrc();
IFileSystemAccess2 getRuntimeSrcGen();
ManifestAccess getRuntimeManifest();
PluginXmlAccess getRuntimePluginXml();
ModuleAccess getRuntimeModule();
TextFileAccess getRuntimePluginXml();
IFileSystemAccess2 getRuntimeTestSrc();
IFileSystemAccess2 getRuntimeTestSrcGen();
ManifestAccess getRuntimeTestManifest();
PluginXmlAccess getRuntimeTestPluginXml();
ModuleAccess getRuntimeTestModule();
TextFileAccess getRuntimeTestPluginXml();
IFileSystemAccess2 getGenericIdeSrc();
IFileSystemAccess2 getGenericIdeSrcGen();
ManifestAccess getGenericIdeManifest();
PluginXmlAccess getGenericIdePluginXml();
ModuleAccess getGenericIdeModule();
TextFileAccess getGenericIdePluginXml();
IFileSystemAccess2 getGenericIdeTestSrc();
IFileSystemAccess2 getGenericIdeTestSrcGen();
ManifestAccess getGenericIdeTestManifest();
PluginXmlAccess getGenericIdeTestPluginXml();
ModuleAccess getGenericIdeTestModule();
TextFileAccess getGenericIdeTestPluginXml();
IFileSystemAccess2 getEclipsePluginSrc();
IFileSystemAccess2 getEclipsePluginSrcGen();
ManifestAccess getEclipsePluginManifest();
PluginXmlAccess getEclipsePluginPluginXml();
ModuleAccess getEclipsePluginModule();
TextFileAccess getEclipsePluginPluginXml();
IFileSystemAccess2 getEclipsePluginTestSrc();
IFileSystemAccess2 getEclipsePluginTestSrcGen();
ManifestAccess getEclipsePluginTestManifest();
PluginXmlAccess getEclipsePluginTestPluginXml();
ModuleAccess getEclipsePluginTestModule();
TextFileAccess getEclipsePluginTestPluginXml();
IFileSystemAccess2 getIdeaPluginSrc();
IFileSystemAccess2 getIdeaPluginSrcGen();
ManifestAccess getIdeaPluginManifest();
PluginXmlAccess getIdeaPluginPluginXml();
ModuleAccess getIdeaPluginModule();
TextFileAccess getIdeaPluginPluginXml();
IFileSystemAccess2 getIdeaPluginTestSrc();
IFileSystemAccess2 getIdeaPluginTestSrcGen();
ManifestAccess getIdeaPluginTestManifest();
PluginXmlAccess getIdeaPluginTestPluginXml();
ModuleAccess getIdeaPluginTestModule();
TextFileAccess getIdeaPluginTestPluginXml();
IFileSystemAccess2 getWebSrc();
IFileSystemAccess2 getWebSrcGen();
ManifestAccess getWebManifest();
PluginXmlAccess getWebPluginXml();
ModuleAccess getWebModule();
TextFileAccess getWebPluginXml();
IFileSystemAccess2 getWebTestSrc();
IFileSystemAccess2 getWebTestSrcGen();
ManifestAccess getWebTestManifest();
PluginXmlAccess getWebTestPluginXml();
ModuleAccess getWebTestModule();
TextFileAccess getWebTestPluginXml();
IFileSystemAccess2 getOrionJsGen();
IFileSystemAccess2 getAceJsGen();

View file

@ -0,0 +1,89 @@
/*******************************************************************************
* 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 com.google.common.collect.Lists
import java.util.Collections
import java.util.Map
import org.eclipse.emf.codegen.util.CodeGenUtil
import org.eclipse.xtend.lib.annotations.Accessors
class JavaFileAccess extends TextFileAccess {
val Map<String, String> imports = newHashMap
val String packageName
val CodeConfig codeConfig
@Accessors
CharSequence typeComment
@Accessors
boolean markedAsGenerated
new(String packageName, CodeConfig codeConfig) {
this.packageName = packageName
this.codeConfig = codeConfig
}
new(String packageName, String simpleName, CodeConfig codeConfig) {
this.path = packageName.replace('.', '/') + '/' + simpleName + '.java'
this.packageName = packageName
this.codeConfig = codeConfig
}
def String imported(Class<?> clazz) {
return imported(clazz.name.replace('$', '.'))
}
def String imported(String clazz) {
val simpleNameIndex = clazz.lastIndexOf('.')
val simpleName = clazz.substring(simpleNameIndex + 1)
val packageName = clazz.substring(0, simpleNameIndex)
if (CodeGenUtil.isJavaDefaultType(simpleName) || this.packageName == packageName)
return simpleName
val imported = imports.get(simpleName)
if (imported != null) {
if (imported.equals(clazz))
return simpleName
else
return clazz
}
imports.put(simpleName, clazz)
return simpleName
}
override generate() {
for (annot : codeConfig.classAnnotations) {
if (annot.appliesTo(this))
imported(annot.annotationImport)
}
val sortedImports = Lists.newArrayList(imports.values())
Collections.sort(sortedImports)
return '''
«codeConfig.fileHeader»
package «packageName»;
«FOR importName : sortedImports»
import «importName»;
«ENDFOR»
«typeComment»
«FOR annot : codeConfig.classAnnotations»
«IF annot.appliesTo(this)»
«annot.generate()»
«ENDIF»
«ENDFOR»
«FOR fragment : codeFragments»
«fragment»
«ENDFOR»
'''
}
}

View file

@ -1,21 +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.xtend.lib.annotations.Accessors
class PluginXmlAccess {
@Accessors
String path
def void generate() {
}
}

View file

@ -0,0 +1,49 @@
/*******************************************************************************
* 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 com.google.common.io.Files
import java.io.File
import java.nio.charset.Charset
import java.util.List
import org.eclipse.emf.common.util.URI
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend2.lib.StringConcatenation
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.parser.IEncodingProvider
class TextFileAccess {
@Accessors
String path
@Accessors
val List<CharSequence> codeFragments = newArrayList
@Accessors
IEncodingProvider encodingProvider
def CharSequence generate() {
val result = new StringConcatenation
for (fragment : codeFragments) {
result.append(fragment)
}
return result
}
def writeTo(IFileSystemAccess2 fileSystemAccess) {
fileSystemAccess.generateFile(path, generate())
}
def writeToFile() {
val uri = URI.createFileURI(path)
val charset = Charset.forName(encodingProvider.getEncoding(uri))
Files.write(generate(), new File(path), charset)
}
}

View file

@ -13,7 +13,6 @@ 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;
import org.eclipse.xtext.xtext.generator.model.PluginXmlAccess;
/**
* Use this class to configure output paths in the XtextGenerator.
@ -27,53 +26,53 @@ public class XtextProjectConfig implements IXtextProjectConfig {
private String runtimeSrcPath;
private String runtimeSrcGenPath;
private ManifestAccess runtimeManifestAccess;
private PluginXmlAccess runtimePluginXmlAccess;
private ModuleAccess runtimeModuleAccess;
private TextFileAccess runtimePluginXmlAccess;
private String runtimeTestSrcPath;
private String runtimeTestSrcGenPath;
private ManifestAccess runtimeTestManifestAccess;
private PluginXmlAccess runtimeTestPluginXmlAccess;
private ModuleAccess runtimeTestModuleAccess;
private TextFileAccess runtimeTestPluginXmlAccess;
private String genericIdeSrcPath;
private String genericIdeSrcGenPath;
private ManifestAccess genericIdeManifestAccess;
private PluginXmlAccess genericIdePluginXmlAccess;
private ModuleAccess genericIdeModuleAccess;
private TextFileAccess genericIdePluginXmlAccess;
private String genericIdeTestSrcPath;
private String genericIdeTestSrcGenPath;
private ManifestAccess genericIdeTestManifestAccess;
private PluginXmlAccess genericIdeTestPluginXmlAccess;
private ModuleAccess genericIdeTestModuleAccess;
private TextFileAccess genericIdeTestPluginXmlAccess;
private String eclipsePluginSrcPath;
private String eclipsePluginSrcGenPath;
private ManifestAccess eclipsePluginManifestAccess;
private PluginXmlAccess eclipsePluginPluginXmlAccess;
private ModuleAccess eclipsePluginModuleAccess;
private TextFileAccess eclipsePluginPluginXmlAccess;
private String eclipsePluginTestSrcPath;
private String eclipsePluginTestSrcGenPath;
private ManifestAccess eclipsePluginTestManifestAccess;
private PluginXmlAccess eclipsePluginTestPluginXmlAccess;
private ModuleAccess eclipsePluginTestModuleAccess;
private TextFileAccess eclipsePluginTestPluginXmlAccess;
private String ideaPluginSrcPath;
private String ideaPluginSrcGenPath;
private ManifestAccess ideaPluginManifestAccess;
private PluginXmlAccess ideaPluginPluginXmlAccess;
private ModuleAccess ideaPluginModuleAccess;
private TextFileAccess ideaPluginPluginXmlAccess;
private String ideaPluginTestSrcPath;
private String ideaPluginTestSrcGenPath;
private ManifestAccess ideaPluginTestManifestAccess;
private PluginXmlAccess ideaPluginTestPluginXmlAccess;
private ModuleAccess ideaPluginTestModuleAccess;
private TextFileAccess ideaPluginTestPluginXmlAccess;
private String webSrcPath;
private String webSrcGenPath;
private ManifestAccess webManifestAccess;
private PluginXmlAccess webPluginXmlAccess;
private ModuleAccess webModuleAccess;
private TextFileAccess webPluginXmlAccess;
private String webTestSrcPath;
private String webTestSrcGenPath;
private ManifestAccess webTestManifestAccess;
private PluginXmlAccess webTestPluginXmlAccess;
private ModuleAccess webTestModuleAccess;
private TextFileAccess webTestPluginXmlAccess;
private String orionJsGenPath;
private String aceJsGenPath;
@ -113,15 +112,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.runtimeManifestAccess = manifest;
}
@Override
public PluginXmlAccess getRuntimePluginXml() {
return runtimePluginXmlAccess;
}
public void setRuntimePluginXml(PluginXmlAccess pluginXml) {
this.runtimePluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getRuntimeModule() {
if (runtimeModuleAccess == null) {
@ -130,6 +120,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return runtimeModuleAccess;
}
public void setRuntimePluginXml(String path) {
if (path != null) {
this.runtimePluginXmlAccess = new TextFileAccess();
this.runtimePluginXmlAccess.setPath(path);
} else {
this.runtimePluginXmlAccess = null;
}
}
@Override
public TextFileAccess getRuntimePluginXml() {
return this.runtimePluginXmlAccess;
}
@Override
public IFileSystemAccess2 getRuntimeTestSrc() {
if (runtimeTestSrcPath != null)
@ -163,15 +167,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.runtimeTestManifestAccess = manifest;
}
@Override
public PluginXmlAccess getRuntimeTestPluginXml() {
return runtimeTestPluginXmlAccess;
}
public void setRuntimeTestPluginXml(PluginXmlAccess pluginXml) {
this.runtimeTestPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getRuntimeTestModule() {
if (runtimeTestModuleAccess == null) {
@ -180,6 +175,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return runtimeTestModuleAccess;
}
public void setRuntimeTestPluginXml(String path) {
if (path != null) {
this.runtimeTestPluginXmlAccess = new TextFileAccess();
this.runtimeTestPluginXmlAccess.setPath(path);
} else {
this.runtimeTestPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getRuntimeTestPluginXml() {
return this.runtimeTestPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getGenericIdeSrc() {
if (genericIdeSrcPath != null)
@ -213,15 +222,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.genericIdeManifestAccess = manifest;
}
@Override
public PluginXmlAccess getGenericIdePluginXml() {
return genericIdePluginXmlAccess;
}
public void setGenericIdePluginXml(PluginXmlAccess pluginXml) {
this.genericIdePluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getGenericIdeModule() {
if (genericIdeModuleAccess == null) {
@ -230,6 +230,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return genericIdeModuleAccess;
}
public void setGenericIdePluginXml(String path) {
if (path != null) {
this.genericIdePluginXmlAccess = new TextFileAccess();
this.genericIdePluginXmlAccess.setPath(path);
} else {
this.genericIdePluginXmlAccess = null;
}
}
@Override
public TextFileAccess getGenericIdePluginXml() {
return this.genericIdePluginXmlAccess;
}
@Override
public IFileSystemAccess2 getGenericIdeTestSrc() {
if (genericIdeTestSrcPath != null)
@ -263,15 +277,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.genericIdeTestManifestAccess = manifest;
}
@Override
public PluginXmlAccess getGenericIdeTestPluginXml() {
return genericIdeTestPluginXmlAccess;
}
public void setGenericIdeTestPluginXml(PluginXmlAccess pluginXml) {
this.genericIdeTestPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getGenericIdeTestModule() {
if (genericIdeTestModuleAccess == null) {
@ -280,6 +285,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return genericIdeTestModuleAccess;
}
public void setGenericIdeTestPluginXml(String path) {
if (path != null) {
this.genericIdeTestPluginXmlAccess = new TextFileAccess();
this.genericIdeTestPluginXmlAccess.setPath(path);
} else {
this.genericIdeTestPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getGenericIdeTestPluginXml() {
return this.genericIdeTestPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getEclipsePluginSrc() {
if (eclipsePluginSrcPath != null)
@ -313,15 +332,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.eclipsePluginManifestAccess = manifest;
}
@Override
public PluginXmlAccess getEclipsePluginPluginXml() {
return eclipsePluginPluginXmlAccess;
}
public void setEclipsePluginPluginXml(PluginXmlAccess pluginXml) {
this.eclipsePluginPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getEclipsePluginModule() {
if (eclipsePluginModuleAccess == null) {
@ -330,6 +340,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return eclipsePluginModuleAccess;
}
public void setEclipsePluginPluginXml(String path) {
if (path != null) {
this.eclipsePluginPluginXmlAccess = new TextFileAccess();
this.eclipsePluginPluginXmlAccess.setPath(path);
} else {
this.eclipsePluginPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getEclipsePluginPluginXml() {
return this.eclipsePluginPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getEclipsePluginTestSrc() {
if (eclipsePluginTestSrcPath != null)
@ -363,15 +387,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.eclipsePluginTestManifestAccess = manifest;
}
@Override
public PluginXmlAccess getEclipsePluginTestPluginXml() {
return eclipsePluginTestPluginXmlAccess;
}
public void setEclipsePluginTestPluginXml(PluginXmlAccess pluginXml) {
this.eclipsePluginTestPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getEclipsePluginTestModule() {
if (eclipsePluginTestModuleAccess == null) {
@ -380,6 +395,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return eclipsePluginTestModuleAccess;
}
public void setEclipsePluginTestPluginXml(String path) {
if (path != null) {
this.eclipsePluginTestPluginXmlAccess = new TextFileAccess();
this.eclipsePluginTestPluginXmlAccess.setPath(path);
} else {
this.eclipsePluginTestPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getEclipsePluginTestPluginXml() {
return this.eclipsePluginTestPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getIdeaPluginSrc() {
if (ideaPluginSrcPath != null)
@ -413,15 +442,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.ideaPluginManifestAccess = manifest;
}
@Override
public PluginXmlAccess getIdeaPluginPluginXml() {
return ideaPluginPluginXmlAccess;
}
public void setIdeaPluginPluginXml(PluginXmlAccess pluginXml) {
this.ideaPluginPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getIdeaPluginModule() {
if (ideaPluginModuleAccess == null) {
@ -430,6 +450,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return ideaPluginModuleAccess;
}
public void setIdeaPluginPluginXml(String path) {
if (path != null) {
this.ideaPluginPluginXmlAccess = new TextFileAccess();
this.ideaPluginPluginXmlAccess.setPath(path);
} else {
this.ideaPluginPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getIdeaPluginPluginXml() {
return this.ideaPluginPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getIdeaPluginTestSrc() {
if (ideaPluginTestSrcPath != null)
@ -463,15 +497,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.ideaPluginTestManifestAccess = manifest;
}
@Override
public PluginXmlAccess getIdeaPluginTestPluginXml() {
return ideaPluginTestPluginXmlAccess;
}
public void setIdeaPluginTestPluginXml(PluginXmlAccess pluginXml) {
this.ideaPluginTestPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getIdeaPluginTestModule() {
if (ideaPluginTestModuleAccess == null) {
@ -480,6 +505,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return ideaPluginTestModuleAccess;
}
public void setIdeaPluginTestPluginXml(String path) {
if (path != null) {
this.ideaPluginTestPluginXmlAccess = new TextFileAccess();
this.ideaPluginTestPluginXmlAccess.setPath(path);
} else {
this.ideaPluginTestPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getIdeaPluginTestPluginXml() {
return this.ideaPluginTestPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getWebSrc() {
if (webSrcPath != null)
@ -513,15 +552,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.webManifestAccess = manifest;
}
@Override
public PluginXmlAccess getWebPluginXml() {
return webPluginXmlAccess;
}
public void setWebPluginXml(PluginXmlAccess pluginXml) {
this.webPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getWebModule() {
if (webModuleAccess == null) {
@ -530,6 +560,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return webModuleAccess;
}
public void setWebPluginXml(String path) {
if (path != null) {
this.webPluginXmlAccess = new TextFileAccess();
this.webPluginXmlAccess.setPath(path);
} else {
this.webPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getWebPluginXml() {
return this.webPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getWebTestSrc() {
if (webTestSrcPath != null)
@ -563,15 +607,6 @@ public class XtextProjectConfig implements IXtextProjectConfig {
this.webTestManifestAccess = manifest;
}
@Override
public PluginXmlAccess getWebTestPluginXml() {
return webTestPluginXmlAccess;
}
public void setWebTestPluginXml(PluginXmlAccess pluginXml) {
this.webTestPluginXmlAccess = pluginXml;
}
@Override
public ModuleAccess getWebTestModule() {
if (webTestModuleAccess == null) {
@ -580,6 +615,20 @@ public class XtextProjectConfig implements IXtextProjectConfig {
return webTestModuleAccess;
}
public void setWebTestPluginXml(String path) {
if (path != null) {
this.webTestPluginXmlAccess = new TextFileAccess();
this.webTestPluginXmlAccess.setPath(path);
} else {
this.webTestPluginXmlAccess = null;
}
}
@Override
public TextFileAccess getWebTestPluginXml() {
return this.webTestPluginXmlAccess;
}
@Override
public IFileSystemAccess2 getOrionJsGen() {
if (orionJsGenPath != null)