mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 16:58:56 +00:00
[generator] Created new project org.eclipse.xtext.xtext.generator
Signed-off-by: Miro Spönemann <miro.spoenemann@itemis.de>
This commit is contained in:
parent
99d3b94a32
commit
167c9f97d4
12 changed files with 387 additions and 0 deletions
8
plugins/org.eclipse.xtext.xtext.generator/.classpath
Normal file
8
plugins/org.eclipse.xtext.xtext.generator/.classpath
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="xtend-gen"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
34
plugins/org.eclipse.xtext.xtext.generator/.project
Normal file
34
plugins/org.eclipse.xtext.xtext.generator/.project
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>org.eclipse.xtext.xtext.generator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,7 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,25 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-SymbolicName: org.eclipse.xtext.xtext.generator;singleton:=true
|
||||
Bundle-Version: 2.9.0.qualifier
|
||||
Bundle-Localization: plugin
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-Vendor: %providerName
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: org.eclipse.xtext;x-installation:=greedy,
|
||||
org.eclipse.xtext.util;x-installation:=greedy,
|
||||
org.eclipse.xtext.xbase.lib;visibility:=reexport;x-installation:=greedy,
|
||||
org.eclipse.xtext.ecore,
|
||||
org.eclipse.xtend.lib,
|
||||
org.eclipse.emf.codegen.ecore;bundle-version="2.10.2";visibility:=reexport;x-installation:=greedy,
|
||||
org.eclipse.emf.ecore;bundle-version="2.10.2",
|
||||
org.eclipse.emf.common;bundle-version="2.10.1",
|
||||
org.eclipse.emf.mwe2.lib;bundle-version="2.7.0";visibility:=reexport,
|
||||
org.eclipse.core.runtime;bundle-version="3.6.0",
|
||||
org.eclipse.jdt.core;bundle-version="3.6.0";resolution:=optional,
|
||||
org.antlr.runtime;bundle-version="[3.2.0,3.2.1)",
|
||||
de.itemis.xtext.antlr;bundle-version="2.0.0";resolution:=optional;visibility:=reexport
|
||||
Import-Package: com.ibm.icu.text;version="4.0.0",
|
||||
org.apache.commons.logging;version="1.0.4";resolution:=optional;x-installation:=greedy,
|
||||
org.apache.log4j;version="1.2.15"
|
28
plugins/org.eclipse.xtext.xtext.generator/about.html
Normal file
28
plugins/org.eclipse.xtext.xtext.generator/about.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
|
||||
<title>About</title>
|
||||
</head>
|
||||
<body lang="EN-US">
|
||||
<h2>About This Content</h2>
|
||||
|
||||
<p>June 5, 2007</p>
|
||||
<h3>License</h3>
|
||||
|
||||
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
|
||||
indicated below, the Content is provided to you under the terms and conditions of the
|
||||
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
|
||||
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
|
||||
For purposes of the EPL, "Program" will mean the Content.</p>
|
||||
|
||||
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
|
||||
being redistributed by another party ("Redistributor") and different terms and conditions may
|
||||
apply to your use of any object code in the Content. Check the Redistributor's license that was
|
||||
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
|
||||
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
|
||||
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
source.. = src/,\
|
||||
xtend-gen/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
about.html,\
|
||||
plugin.properties
|
||||
src.includes = about.html
|
|
@ -0,0 +1,2 @@
|
|||
pluginName = Xtext Generator 2
|
||||
providerName = Eclipse Modeling Project
|
42
plugins/org.eclipse.xtext.xtext.generator/pom.xml
Normal file
42
plugins/org.eclipse.xtext.xtext.generator/pom.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.xtext</groupId>
|
||||
<artifactId>org.eclipse.xtext.tycho.parent</artifactId>
|
||||
<version>2.9.0-SNAPSHOT</version>
|
||||
<relativePath>../../maven/org.eclipse.xtext.tycho.parent</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
<artifactId>org.eclipse.xtext.xtext.generator</artifactId>
|
||||
<name>Xtext Generator 2</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.xtext</groupId>
|
||||
<artifactId>org.eclipse.xtext.ecore</artifactId>
|
||||
<version>[${project.version}]</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.xtend</groupId>
|
||||
<artifactId>org.eclipse.xtend.lib</artifactId>
|
||||
<version>[${project.version}]</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.emf</groupId>
|
||||
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
|
||||
<version>${emf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.emf</groupId>
|
||||
<artifactId>org.eclipse.emf.codegen.ecore</artifactId>
|
||||
<version>${emf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.xtext</groupId>
|
||||
<artifactId>xtext-antlr-generator</artifactId>
|
||||
<version>${antlr-generator-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,63 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.util.Strings
|
||||
|
||||
/**
|
||||
* A class annotation configuration for the <code>@Generated</code> annotation.
|
||||
*/
|
||||
class GeneratedClassAnnotation implements IClassAnnotation {
|
||||
|
||||
@Accessors
|
||||
boolean includeDate = false
|
||||
|
||||
@Accessors
|
||||
String comment
|
||||
|
||||
override String toString() {
|
||||
val stringBuilder = new StringBuilder('@Generated(')
|
||||
if (includeDate || !Strings.isEmpty(comment)) {
|
||||
stringBuilder += 'value = '
|
||||
}
|
||||
stringBuilder += '"'
|
||||
stringBuilder += generatorName
|
||||
stringBuilder += '"'
|
||||
if (includeDate) {
|
||||
val dateFormat = new SimpleDateFormat('yyyy-MM-dd\'T\'HH:mmZ')
|
||||
val date = dateFormat.format(new Date)
|
||||
stringBuilder += ', date = "'
|
||||
stringBuilder += date
|
||||
stringBuilder += '"'
|
||||
}
|
||||
if (!Strings.isEmpty(comment)) {
|
||||
val convertedComment = Strings.convertToJavaString(comment)
|
||||
stringBuilder += ', comments = "'
|
||||
stringBuilder += convertedComment
|
||||
stringBuilder += '"'
|
||||
}
|
||||
stringBuilder += ')'
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
protected def String getGeneratorName() {
|
||||
return XtextGenerator.name
|
||||
}
|
||||
|
||||
override getAnnotationImport() {
|
||||
return 'javax.annotation.Generated'
|
||||
}
|
||||
|
||||
private def void +=(StringBuilder stringBuilder, String s) {
|
||||
stringBuilder.append(s)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
/**
|
||||
* Class annotations can be added to the {@link XtextGenerator} workflow component in order
|
||||
* to configure specific Java annotations to be added to each generated class.
|
||||
*/
|
||||
interface IClassAnnotation {
|
||||
|
||||
/**
|
||||
* Convert the class annotation to a string suitable for use in Java code generation.
|
||||
*/
|
||||
override String toString()
|
||||
|
||||
/**
|
||||
* Return the qualified name of the annotation interface for use in import declarations,
|
||||
* or {@code null} if no import is required.
|
||||
*/
|
||||
def String getAnnotationImport()
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
/**
|
||||
* A fragment that contributes to the {@link XtextGenerator}.
|
||||
*/
|
||||
interface IGeneratorFragment {
|
||||
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.net.URL
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.List
|
||||
import java.util.jar.Manifest
|
||||
import org.eclipse.emf.common.EMFPlugin
|
||||
import org.eclipse.emf.mwe.core.WorkflowContext
|
||||
import org.eclipse.emf.mwe.core.issues.Issues
|
||||
import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent2
|
||||
import org.eclipse.emf.mwe.core.monitor.ProgressMonitor
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.XtextStandaloneSetup
|
||||
|
||||
/**
|
||||
* The Xtext language infrastructure generator. Can be configured with {@link IGeneratorFragment}
|
||||
* instances as well as with some properties declared via setter or adder methods.
|
||||
*
|
||||
* <p><b>NOTE: This is a reimplementation of org.eclipse.xtext.generator.Generator</b></p>
|
||||
*/
|
||||
class XtextGenerator extends AbstractWorkflowComponent2 {
|
||||
|
||||
static val FILE_HEADER_VAR_TIME = '${time}'
|
||||
static val FILE_HEADER_VAR_DATE = '${date}'
|
||||
static val FILE_HEADER_VAR_YEAR = '${year}'
|
||||
static val FILE_HEADER_VAR_USER = '${user}'
|
||||
static val FILE_HEADER_VAR_VERSION = '${version}'
|
||||
|
||||
@Accessors
|
||||
String encoding = System.getProperty('file.encoding')
|
||||
|
||||
@Accessors
|
||||
String fileHeader = "/*\n * generated by Xtext\n */"
|
||||
|
||||
val List<IClassAnnotation> classAnnotations = newArrayList
|
||||
|
||||
new() {
|
||||
new XtextStandaloneSetup().createInjectorAndDoEMFRegistration()
|
||||
}
|
||||
|
||||
protected override invokeInternal(WorkflowContext ctx, ProgressMonitor monitor, Issues issues) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class annotations are used configure specific Java annotations to be added to each generated class.
|
||||
*/
|
||||
def void addClassAnnotation(IClassAnnotation annotation) {
|
||||
this.classAnnotations.add(annotation)
|
||||
}
|
||||
|
||||
protected def getTransformedFileHeader() {
|
||||
var result = fileHeader
|
||||
if (result != null) {
|
||||
if (result.contains(FILE_HEADER_VAR_TIME)) {
|
||||
val dateFormat = new SimpleDateFormat('HH:mm:ss')
|
||||
val time = dateFormat.format(new Date)
|
||||
result = result.replace(FILE_HEADER_VAR_TIME, time)
|
||||
}
|
||||
if (result.contains(FILE_HEADER_VAR_DATE)) {
|
||||
val dateFormat = new SimpleDateFormat('MMM d, yyyy')
|
||||
val date = dateFormat.format(new Date)
|
||||
result = result.replace(FILE_HEADER_VAR_DATE, date)
|
||||
}
|
||||
if (result.contains(FILE_HEADER_VAR_YEAR)) {
|
||||
val dateFormat = new SimpleDateFormat('yyyy')
|
||||
val year = dateFormat.format(new Date)
|
||||
result = result.replace(FILE_HEADER_VAR_YEAR, year)
|
||||
}
|
||||
if (result.contains(FILE_HEADER_VAR_USER)) {
|
||||
val user = System.getProperty("user.name")
|
||||
if (user != null) {
|
||||
result = result.replace(FILE_HEADER_VAR_USER, user)
|
||||
}
|
||||
}
|
||||
if (result.contains(FILE_HEADER_VAR_VERSION)) {
|
||||
val version = getVersion()
|
||||
if (version != null) {
|
||||
result = result.replace(FILE_HEADER_VAR_VERSION, version)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the exact version from the Manifest of the plugin.
|
||||
*/
|
||||
private def getVersion() {
|
||||
var InputStream is
|
||||
try {
|
||||
val url = new URL(Plugin.INSTANCE.baseURL + 'META-INF/MANIFEST.MF')
|
||||
is = url.openStream()
|
||||
val manifest = new Manifest(is)
|
||||
return manifest.getMainAttributes().getValue('Bundle-Version')
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try { is.close() }
|
||||
catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only needed to determine the Manifest file and its version of this plugin in standalone mode.
|
||||
*/
|
||||
private static class Plugin extends EMFPlugin {
|
||||
public static final Plugin INSTANCE = new Plugin
|
||||
private new() {
|
||||
super(#[]);
|
||||
}
|
||||
override getPluginResourceLocator() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue