summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-06-01 16:33:35 (EDT)
committerpelder2007-06-01 16:33:35 (EDT)
commit6cabfeb8b0015f25ddb03bb575d9801c5a05b54c (patch)
treeabcc20b3f12b77e2fbb2b47c0697ca177f1379e0
parentb90ede1920bca18583181e1d713ee9d832d18d7a (diff)
downloadorg.eclipse.jet-6cabfeb8b0015f25ddb03bb575d9801c5a05b54c.zip
org.eclipse.jet-6cabfeb8b0015f25ddb03bb575d9801c5a05b54c.tar.gz
org.eclipse.jet-6cabfeb8b0015f25ddb03bb575d9801c5a05b54c.tar.bz2
[190570] JET Editor does not have access to required JET internals
-rw-r--r--plugins/org.eclipse.jet/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilationHelper.java285
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java97
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/DummyMain.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JETTemplateMapGenerator.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/TagDataDeclGenerator.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteJavaExpressionTemplate.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteTextElementTemplate.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLEndGenerator.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLStartGenerator.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java9
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java10
-rw-r--r--plugins/org.eclipse.jet/templates/v1/jet2java.jet8
-rw-r--r--plugins/org.eclipse.jet/templates/v2/jet2java.jet8
-rw-r--r--tests/org.eclipse.jet.tests/data/alljet2.jet.expected.java65
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java3
18 files changed, 462 insertions, 43 deletions
diff --git a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
index 98ec3c2..1e695e4 100644
--- a/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jet/META-INF/MANIFEST.MF
@@ -25,7 +25,7 @@ Export-Package: org.eclipse.jet,
org.eclipse.jet.compiler,
org.eclipse.jet.internal;x-friends:="org.eclipse.jet.tests,org.eclipse.jet.ui",
org.eclipse.jet.internal.builder;x-friends:="org.eclipse.jet.tests",
- org.eclipse.jet.internal.compiler;x-friends:="org.eclipse.jet.tests",
+ org.eclipse.jet.internal.compiler;x-friends:="org.eclipse.jet.tests,org.eclipse.jet.editor",
org.eclipse.jet.internal.compiler.templates;x-friends:="org.eclipse.jet.tests",
org.eclipse.jet.internal.exceptions;x-friends:="org.eclipse.jet.tests",
org.eclipse.jet.internal.extensionpoints;x-friends:="org.eclipse.jet.tests",
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilationHelper.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilationHelper.java
new file mode 100644
index 0000000..560d47d
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilationHelper.java
@@ -0,0 +1,285 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2007 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: CompilationHelper.java,v 1.1 2007/06/01 20:33:32 pelder Exp $
+ */
+package org.eclipse.jet.internal.compiler;
+
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.compiler.CompileOptionsManager;
+import org.eclipse.jet.core.compiler.JETCompilerOptions;
+import org.eclipse.jet.core.parser.ITagLibraryResolver;
+import org.eclipse.jet.core.parser.ITemplateResolver;
+import org.eclipse.jet.core.parser.ast.JETAST;
+import org.eclipse.jet.core.parser.ast.JETASTParser;
+import org.eclipse.jet.core.parser.ast.JETCompilationUnit;
+import org.eclipse.jet.internal.InternalJET2Platform;
+import org.eclipse.jet.internal.parser.resources.WorkspaceTemplateResolverBuilder;
+import org.eclipse.jet.taglib.TagLibrary;
+import org.eclipse.jet.taglib.TagLibraryManager;
+import org.eclipse.jet.taglib.TagLibraryReference;
+import org.eclipse.jet.transform.IJETBundleDescriptor;
+
+
+/**
+ * Utility class for accessing JET compiler components. This is particularly useful for editors.
+ *
+ * <p>
+ * Each compilation helper is specific to a given project. Once constructed, the helper is based on
+ * a snapshot of the project's JET state (compilation options).
+ * </p>
+ * <p>
+ * Provisional API. This method is subject to significant change or removal in a future release.
+ * </p>
+ */
+public class CompilationHelper
+{
+ private static final ITagLibraryResolver TAG_LIBRARY_RESOLVER = new ITagLibraryResolver()
+ {
+
+ public TagLibrary getLibrary(String tagLibraryID)
+ {
+ return TagLibraryManager.getInstance().getTagLibrary(tagLibraryID);
+ }
+
+ };
+
+ private final IProject project;
+
+ private IJETBundleDescriptor projectDescription;
+
+ private Map options;
+
+ private Map predefinedTagLibraryMap;
+
+ private JETASTParser astParser;
+
+ /**
+ * Create a compilation helper for a specific project.
+ * @param project an open Eclipse project
+ * @throws NullPointerException if project is <code>null</code>
+ * @throws IllegalArgumentException if project does not exist or is not open
+ */
+ public CompilationHelper(IProject project)
+ {
+ if (project == null)
+ {
+ throw new NullPointerException();
+ }
+ if (!project.exists() || !project.isOpen())
+ {
+ throw new IllegalArgumentException();
+ }
+ this.project = project;
+ }
+
+ /**
+ * Return an AST parser capable of compiling JET templates in the given Eclipse project.
+ * @return an AST Parser
+ *
+ */
+ public JETASTParser getASTParser()
+ {
+ if(astParser == null) {
+ Map options = getOptions();
+
+ int jetSpec = JETCompilerOptions.getIntOption(options, JETCompilerOptions.OPTION_JET_SPECIFICATION_VERSION);
+
+ JETASTParser.Builder builder = new JETASTParser.Builder(jetSpec);
+ builder.tagLibraryResolver(TAG_LIBRARY_RESOLVER);
+ builder.templateResolver(buildTemplateResolver());
+ builder.predefinedTagLibraries(getPredefinedTagLibraryMap());
+
+ astParser = builder.build();
+ }
+ return astParser;
+ }
+
+ /**
+ * Return the JET AST for the given template path.
+ * This method always returns an AST; use {@link JETCompilationUnit#getProblems()} to discover problems.
+ * @param templatePath the JET template path
+ * @return a {@link JETCompilationUnit}.
+ */
+ public JETCompilationUnit getAST(String templatePath) {
+ return (JETCompilationUnit)getASTParser().parse(templatePath);
+ }
+
+ /**
+ * Return the JET AST for the given template source.
+ * This method always returns an AST; use {@link JETCompilationUnit#getProblems()} to discover problems.
+ * @param source
+ * @return a {@link JETCompilationUnit}.
+ */
+ public JETCompilationUnit getASTFromSource(String source) {
+ return (JETCompilationUnit)getASTParser().parse(source.toCharArray());
+ }
+
+ /**
+ * Return the Java code corresponding to the given compilation unit.
+ * @param ast
+ * @return a string
+ */
+ public String getJavaCode(JETCompilationUnit ast) {
+ ensurePackageAndClassSet(ast);
+ // run the code generator
+ TemplateRunner templateRunner = new TemplateRunner();
+ String cgTemplatePath = getJetVersion() == JETAST.JET_SPEC_V1 ? "templates/v1/jet2java.jet" : "templates/v2/jet2java.jet"; //$NON-NLS-1$ //$NON-NLS-2$
+ String code = templateRunner.generate(cgTemplatePath, Collections.singletonMap("cu", ast)); //$NON-NLS-1$
+ return code;
+ }
+
+ private void ensurePackageAndClassSet(JETCompilationUnit ast)
+ {
+ if(ast.getOutputJavaPackage() == null) {
+ ast.setOutputJavaPackage(JETCompilerOptions.getStringOption(getOptions(), JETCompilerOptions.OPTION_COMPILED_TEMPLATE_PACKAGE));
+ }
+ if(ast.getOutputJavaClassName() == null ) {
+ ast.setOutputJavaClassName("_jet_Unkonwn_"); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Return the Java code corresponding to the given compilation unit.
+ * @param ast
+ * @return a string
+ */
+ public String getJavaCode(JETCompilationUnit ast, Map javaElementPositionMap) {
+ // run the code generator
+ Map arguments = new HashMap(2);
+ arguments.put("cu", ast); //$NON-NLS-1$
+ arguments.put("positionMap", javaElementPositionMap); //$NON-NLS-1$
+ TemplateRunner templateRunner = new TemplateRunner();
+ String cgTemplatePath = getJetVersion() == JETAST.JET_SPEC_V1 ? "templates/v1/jet2java.jet" : "templates/v2/jet2java.jet"; //$NON-NLS-1$ //$NON-NLS-2$
+ String code = templateRunner.generate(cgTemplatePath, arguments);
+ return code;
+ }
+
+ /**
+ * Return the JET Version
+ * @return either {@link JETAST#JET_SPEC_V1} or {@link JETAST#JET_SPEC_V2}.
+ */
+ public int getJetVersion()
+ {
+ return JETCompilerOptions.getIntOption(getOptions(), JETCompilerOptions.OPTION_JET_SPECIFICATION_VERSION);
+ }
+
+ /**
+ * Return the project's compiler options
+ * @return
+ */
+ public Map getOptions()
+ {
+ if(options == null) {
+ options = CompileOptionsManager.getOptions(project);
+ }
+ return options;
+ }
+
+ /**
+ * Create a map of tag library prefix to tag library id.
+ * @param tagLibraryReferences an array of tag library references
+ * @return a map
+ */
+ public Map getPredefinedTagLibraryMap()
+ {
+ if(predefinedTagLibraryMap == null) {
+ IJETBundleDescriptor descriptor = getDescriptor();
+ if (descriptor != null)
+ {
+ TagLibraryReference[] tagLibraryReferences = descriptor.getTagLibraryReferences();
+ predefinedTagLibraryMap = new HashMap(tagLibraryReferences.length);
+ for (int i = 0; i < tagLibraryReferences.length; i++)
+ {
+ if (tagLibraryReferences[i].isAutoImport())
+ {
+ predefinedTagLibraryMap.put(tagLibraryReferences[i].getPrefix(), tagLibraryReferences[i].getTagLibraryId());
+ }
+ }
+ }
+ else
+ {
+ predefinedTagLibraryMap = Collections.EMPTY_MAP;
+ }
+ }
+ return predefinedTagLibraryMap;
+ }
+
+ private IJETBundleDescriptor getDescriptor()
+ {
+ if (projectDescription == null)
+ {
+ projectDescription = JET2Platform.getProjectDescription(project.getName());
+ }
+
+ return projectDescription;
+ }
+
+ /**
+ * @param project
+ * @param options
+ * @return
+ */
+ private ITemplateResolver buildTemplateResolver()
+ {
+ final Map options = getOptions();
+ final WorkspaceTemplateResolverBuilder templateResolverWorkspaceTemplateResolverBuilder = new WorkspaceTemplateResolverBuilder(project);
+ URI altBaseLocations[] = getAltBaseLocations(options);
+ if (altBaseLocations.length > 0)
+ {
+ templateResolverWorkspaceTemplateResolverBuilder.addAltBaseLocations(altBaseLocations);
+ }
+ final ITemplateResolver templateResolver = templateResolverWorkspaceTemplateResolverBuilder.build();
+ return templateResolver;
+ }
+
+ private URI[] getAltBaseLocations(Map options)
+ {
+ final String value = JETCompilerOptions.getStringOption(options, JETCompilerOptions.OPTION_V1_BASE_TRANSFORMATION);
+ if (value == null || value.trim().length() == 0)
+ {
+ return new URI [0];
+ }
+ String[] uriStrings = value.split(","); //$NON-NLS-1$
+
+ List altLocations = new ArrayList(uriStrings.length);
+
+ for (int i = 0; i < uriStrings.length; i++)
+ {
+ String uriString = uriStrings[i].endsWith("/") ? uriStrings[i] : uriStrings[i] + "/"; //$NON-NLS-1$ //$NON-NLS-2$
+ try
+ {
+ URI uri = new URI(uriString);
+ altLocations.add(uri);
+ }
+ catch (URISyntaxException e)
+ {
+ InternalJET2Platform.logError(null, e);
+ }
+ }
+
+ return (URI[])altLocations.toArray(new URI [altLocations.size()]);
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
index ebfbacd..ed06d76 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/SafeJETASTVisitor.java
@@ -12,10 +12,11 @@
*
* </copyright>
*
- * $Id: SafeJETASTVisitor.java,v 1.2 2007/04/30 17:33:08 pelder Exp $
+ * $Id: SafeJETASTVisitor.java,v 1.3 2007/06/01 20:33:32 pelder Exp $
*/
package org.eclipse.jet.internal.compiler;
+import java.util.Map;
import java.util.regex.Matcher;
import org.eclipse.jet.BufferedJET2Writer;
@@ -23,11 +24,11 @@ import org.eclipse.jet.IWriterListener;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.core.parser.ast.JETASTVisitor;
+import org.eclipse.jet.core.parser.ast.JavaElement;
import org.eclipse.jet.internal.core.NewLineUtil;
import org.eclipse.jet.internal.taglib.DocumentHelper;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
@@ -37,7 +38,7 @@ import org.eclipse.jface.text.Position;
public class SafeJETASTVisitor extends JETASTVisitor
{
- private final class IndentingWriter implements JET2Writer {
+ private final class IndentingWriter implements JET2Writer, BufferedJET2Writer {
private final JET2Writer delegate;
@@ -88,11 +89,7 @@ public class SafeJETASTVisitor extends JETASTVisitor
public int getLength()
{
- if(delegate instanceof BufferedJET2Writer) {
- return ((BufferedJET2Writer)delegate).getContentLength();
- } else {
- throw new IllegalStateException();
- }
+ return getContentLength();
}
public JET2Writer getParentWriter()
@@ -123,13 +120,8 @@ public class SafeJETASTVisitor extends JETASTVisitor
public void replace(int offset, int length, String text)
{
- if(delegate instanceof BufferedJET2Writer) {
- ((BufferedJET2Writer)delegate).replaceContent(offset, length, text);
- } else {
- throw new UnsupportedOperationException();
- }
-
- }
+ replaceContent(offset, length, text);
+ }
public void write(boolean b)
{
@@ -217,11 +209,67 @@ public class SafeJETASTVisitor extends JETASTVisitor
{
return delegate.getEventListeners();
}
+
+
+ public Object getAdapter(Class adapterClass)
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ return ((BufferedJET2Writer)delegate).getAdapter(adapterClass);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getContent()
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ return ((BufferedJET2Writer)delegate).getContent();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getContent(int offset, int length)
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ return ((BufferedJET2Writer)delegate).getContent(offset, length);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getContentLength()
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ return ((BufferedJET2Writer)delegate).getContentLength();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public void replaceContent(int offset, int length, String text)
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ ((BufferedJET2Writer)delegate).replaceContent(offset, length, text);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public void setContent(String content)
+ {
+ if(delegate instanceof BufferedJET2Writer) {
+ ((BufferedJET2Writer)delegate).setContent(content);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
}
protected final JET2Context context;
protected final JET2Writer out;
private String indent;
private final String stdIndent;
+ private final Map positionMap;
public SafeJETASTVisitor(JET2Context context, JET2Writer out) {
this(context, out, " "); //$NON-NLS-1$
@@ -232,6 +280,7 @@ public class SafeJETASTVisitor extends JETASTVisitor
this.out = new IndentingWriter(out);
this.stdIndent = stdIndent;
this.indent = ""; //$NON-NLS-1$
+ this.positionMap = (Map)(context.hasVariable("positionMap") ? context.getVariable("positionMap") : null); //$NON-NLS-1$ //$NON-NLS-2$
}
public SafeJETASTVisitor in()
@@ -250,4 +299,22 @@ public class SafeJETASTVisitor extends JETASTVisitor
{
return indent;
}
+
+ /**
+ * @param element
+ */
+ protected void writeAndRecord(JavaElement element)
+ {
+ String javaContent = element.getJavaContent();
+ out.write(javaContent);
+ if (positionMap != null)
+ {
+ int len = javaContent.length();
+ Position position = new Position(((BufferedJET2Writer)out).getContentLength() - len, len);
+ positionMap.put((JavaElement)element, position);
+ IDocument document = (IDocument)((BufferedJET2Writer)out).getAdapter(IDocument.class);
+ DocumentHelper.installPositionCategory(document, this.getClass().getName());
+
+ }
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/DummyMain.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/DummyMain.java
index 141fbf1..d8ed0cf 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/DummyMain.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/DummyMain.java
@@ -13,7 +13,7 @@ public class DummyMain implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
private static final TagInfo _td_c_log_2_1 = new TagInfo("c:log", //$NON-NLS-1$
2, 1,
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
index a5bc178..98d4ebb 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2JavaGenerator.java
@@ -45,7 +45,7 @@ public class JET2JavaGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
private static final TagInfo _td_c_include_80_4 = new TagInfo("c:include", //$NON-NLS-1$
80, 4,
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java
index 9abaa71..00a974b 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java
@@ -16,7 +16,7 @@ public class JET2TransformGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JETTemplateMapGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JETTemplateMapGenerator.java
index 31a37dc..5ed127f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JETTemplateMapGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JETTemplateMapGenerator.java
@@ -16,7 +16,7 @@ public class JETTemplateMapGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/TagDataDeclGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/TagDataDeclGenerator.java
index d9f3583..e4bb17a 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/TagDataDeclGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/TagDataDeclGenerator.java
@@ -15,7 +15,7 @@ public class TagDataDeclGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteJavaExpressionTemplate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteJavaExpressionTemplate.java
index 03f4d2a..a533b3d 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteJavaExpressionTemplate.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteJavaExpressionTemplate.java
@@ -11,7 +11,7 @@ public class WriteJavaExpressionTemplate implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteTextElementTemplate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteTextElementTemplate.java
index 8f38a90..bedbc27 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteTextElementTemplate.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/WriteTextElementTemplate.java
@@ -12,7 +12,7 @@ public class WriteTextElementTemplate implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLEndGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLEndGenerator.java
index ab4b8bc..5640e9f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLEndGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLEndGenerator.java
@@ -14,7 +14,7 @@ public class XMLEndGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
private static final TagInfo _td_c_get_7_1 = new TagInfo("c:get", //$NON-NLS-1$
7, 1,
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLStartGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLStartGenerator.java
index 9b91c5e..672f462 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLStartGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/XMLStartGenerator.java
@@ -14,7 +14,7 @@ public class XMLStartGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
private static final TagInfo _td_c_get_6_1 = new TagInfo("c:get", //$NON-NLS-1$
6, 1,
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java
index 22330f0..beceae0 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java
@@ -14,7 +14,7 @@ public class JET1JavaGenerator implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
@@ -42,8 +42,8 @@ public class JET1JavaGenerator implements JET2Template {
cu.accept(new SafeJETASTVisitor(context,out) {
public boolean visit(JavaDeclaration decl) {
+ writeAndRecord(decl);
out.write("\t"); //$NON-NLS-1$
- out.write( decl.getJavaContent() );
out.write(NL);
return true;
@@ -113,8 +113,7 @@ public class JET1JavaGenerator implements JET2Template {
}
public boolean visit(JavaScriptlet scriptlet) {
- out.write(" "); //$NON-NLS-1$
- out.write( scriptlet.getJavaContent() );
+ writeAndRecord(scriptlet);
out.write(NL);
return true;
@@ -122,7 +121,7 @@ public class JET1JavaGenerator implements JET2Template {
public boolean visit(JavaExpression expr) {
out.write(" stringBuffer.append("); //$NON-NLS-1$
- out.write( expr.getJavaContent() );
+ writeAndRecord(expr);
out.write(");"); //$NON-NLS-1$
out.write(NL);
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java
index 21d66cd..121723c 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java
@@ -19,7 +19,7 @@ public class JET2JavaGeneratorNew implements JET2Template {
super();
}
- private static final String NL = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
@@ -75,8 +75,7 @@ public class JET2JavaGeneratorNew implements JET2Template {
cu.accept(new V2CodeGenVisitor(context,out) {
public boolean visit(JavaDeclaration decl) {
- out.write(" "); //$NON-NLS-1$
- out.write( decl.getJavaContent() );
+ writeAndRecord(decl);
out.write(NL);
return true;
@@ -174,8 +173,7 @@ public class JET2JavaGeneratorNew implements JET2Template {
}
public boolean visit(JavaScriptlet scriptlet) {
- out.write(" "); //$NON-NLS-1$
- out.write( scriptlet.getJavaContent() );
+ writeAndRecord(scriptlet);
out.write(NL);
return true;
@@ -183,7 +181,7 @@ public class JET2JavaGeneratorNew implements JET2Template {
public boolean visit(JavaExpression expr) {
out.write(" out.write("); //$NON-NLS-1$
- out.write( expr.getJavaContent() );
+ writeAndRecord(expr);
out.write(");"); //$NON-NLS-1$
out.write(NL);
diff --git a/plugins/org.eclipse.jet/templates/v1/jet2java.jet b/plugins/org.eclipse.jet/templates/v1/jet2java.jet
index 1c49546..e5fe1cf 100644
--- a/plugins/org.eclipse.jet/templates/v1/jet2java.jet
+++ b/plugins/org.eclipse.jet/templates/v1/jet2java.jet
@@ -20,7 +20,8 @@ public class <%= cu.getOutputJavaClassName() %>
<% cu.accept(new SafeJETASTVisitor(context,out) {
public boolean visit(JavaDeclaration decl) {
%>
- <%= decl.getJavaContent() %>
+ <% writeAndRecord(decl); %>
+
<%
return true;
}
@@ -62,13 +63,14 @@ public class <%= cu.getOutputJavaClassName() %>
}
public boolean visit(JavaScriptlet scriptlet) {
%>
- <%= scriptlet.getJavaContent() %>
+ <% writeAndRecord(scriptlet); %>
+
<%
return true;
}
public boolean visit(JavaExpression expr) {
%>
- stringBuffer.append(<%= expr.getJavaContent() %>);
+ stringBuffer.append(<% writeAndRecord(expr); %>);
<%
return true;
}
diff --git a/plugins/org.eclipse.jet/templates/v2/jet2java.jet b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
index 7406ad5..d646fc7 100644
--- a/plugins/org.eclipse.jet/templates/v2/jet2java.jet
+++ b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
@@ -43,7 +43,8 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
<% cu.accept(new V2CodeGenVisitor(context,out) {
public boolean visit(JavaDeclaration decl) {
%>
- <%= decl.getJavaContent() %>
+ <% writeAndRecord(decl); %>
+
<%
return true;
}
@@ -102,13 +103,14 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
}
public boolean visit(JavaScriptlet scriptlet) {
%>
- <%= scriptlet.getJavaContent() %>
+ <% writeAndRecord(scriptlet); %>
+
<%
return true;
}
public boolean visit(JavaExpression expr) {
%>
- out.write(<%= expr.getJavaContent() %>);
+ out.write(<% writeAndRecord(expr); %>);
<%
return true;
}
diff --git a/tests/org.eclipse.jet.tests/data/alljet2.jet.expected.java b/tests/org.eclipse.jet.tests/data/alljet2.jet.expected.java
new file mode 100644
index 0000000..4d19cf8
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/alljet2.jet.expected.java
@@ -0,0 +1,65 @@
+package org.eclipse.emf.examples;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+
+public class Foo implements JET2Template {
+
+
+int foo() {
+ return 3;
+}
+
+ public Foo() {
+ super();
+ }
+
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ public void generate(final JET2Context context, final JET2Writer __out) {
+ JET2Writer out = __out;
+ out.write("Some top level text."); //$NON-NLS-1$
+ out.write(NL);
+ out.write( "An expression" );
+ out.write(NL);
+
+if(foo() > 0) {
+ foo();
+}
+
+ out.write("<test:container one=\"test one\" two='test two'>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" <test:empty/>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" <test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" some text <nontest:text attributes=\"foo\"/>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" </test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write("</test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write("<test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" "); //$NON-NLS-1$
+ out.write( foo(); );
+ out.write(NL);
+ if(foo() > 0) {
+ out.write(" some text"); //$NON-NLS-1$
+ out.write(NL);
+ }
+ out.write("</test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ if(foo() > 0) {
+ out.write(" some text"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" <test:empty/>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" <test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" </test:container>"); //$NON-NLS-1$
+ out.write(NL);
+ }
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java
index cb7b1d0..631c78c 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/AllTests.java
@@ -13,8 +13,9 @@ public class AllTests {
suite.addTestSuite(TestSimplifiedCompiler.class);
suite.addTestSuite(TestJET2Parser.class);
suite.addTest(TextTrimmingTests.suite());
+ suite.addTest(TestCompilationHelper.suite());
suite.addTestSuite(LineInfoTests.class);
- //$JUnit-END$
+//$JUnit-END$
return suite;
}