summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-05-22 15:45:34 (EDT)
committer pelder2007-05-22 15:45:34 (EDT)
commit9aa330f3e4a1ecb4a705ba8eae64bb18084c9339 (patch)
treea3b16b57f79770a42d82c5a50bb294e84b67f2db
parente4e178c19d40345d98dbdd43dfe8b9003081141a (diff)
downloadorg.eclipse.jet-9aa330f3e4a1ecb4a705ba8eae64bb18084c9339.zip
org.eclipse.jet-9aa330f3e4a1ecb4a705ba8eae64bb18084c9339.tar.gz
org.eclipse.jet-9aa330f3e4a1ecb4a705ba8eae64bb18084c9339.tar.bz2
[187871] Generated NL constant in JET2 templates is inefficient and sometimes unnecessary
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/HasNewlinesUtil.java54
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v2/JET2JavaGeneratorNew.java5
-rw-r--r--plugins/org.eclipse.jet/templates/v2/jet2java.jet5
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java2
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java2
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java2
6 files changed, 65 insertions, 5 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/HasNewlinesUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/HasNewlinesUtil.java
new file mode 100644
index 0000000..bc68e8c
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/HasNewlinesUtil.java
@@ -0,0 +1,54 @@
+/**
+ * <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: HasNewlinesUtil.java,v 1.1 2007/05/22 19:45:33 pelder Exp $
+ */
+package org.eclipse.jet.internal.compiler;
+
+import org.eclipse.jet.core.parser.ast.JETASTElement;
+import org.eclipse.jet.core.parser.ast.JETASTVisitor;
+import org.eclipse.jet.core.parser.ast.TextElement;
+import org.eclipse.jet.internal.core.NewLineUtil;
+
+/**
+ * Utility for testing whether a JET AST has new lines in any of its text elements
+ */
+public class HasNewlinesUtil extends JETASTVisitor
+{
+ public static boolean test(JETASTElement element)
+ {
+ HasNewlinesUtil util = new HasNewlinesUtil();
+ element.accept(util);
+
+ return util.hasNewLines;
+ }
+
+ private boolean hasNewLines;
+
+ private HasNewlinesUtil() {
+ hasNewLines = false;
+ }
+
+ public boolean visit(TextElement text)
+ {
+ if(!hasNewLines)
+ {
+ hasNewLines = NewLineUtil.NEW_LINE_PATTERN.matcher(new String(text.getText())).find();
+
+ }
+ return super.visit(text);
+ }
+
+
+}
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 40b1b76..21d66cd 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
@@ -5,6 +5,7 @@ import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.core.parser.ast.*;
import org.eclipse.jet.internal.compiler.V2CodeGenVisitor;
+import org.eclipse.jet.internal.compiler.HasNewlinesUtil;
import org.eclipse.jet.internal.compiler.TagUsageVisitor;
import org.eclipse.jet.taglib.TagLibraryReference;
import java.util.Arrays;
@@ -90,11 +91,13 @@ public class JET2JavaGeneratorNew implements JET2Template {
out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
+ if(HasNewlinesUtil.test(cu)) {
out.write(NL);
out.write(" private static final String "); //$NON-NLS-1$
out.write(nlConstantName);
- out.write(" = System.getProperties().getProperty(\"line.separator\"); //$NON-NLS-1$"); //$NON-NLS-1$
+ out.write(" = System.getProperty(\"line.separator\"); //$NON-NLS-1$"); //$NON-NLS-1$
out.write(NL);
+ }
if(tuv.hasTags()) {
out.write(" "); //$NON-NLS-1$
out.write(NL);
diff --git a/plugins/org.eclipse.jet/templates/v2/jet2java.jet b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
index 9c74a2e..7406ad5 100644
--- a/plugins/org.eclipse.jet/templates/v2/jet2java.jet
+++ b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
@@ -3,6 +3,7 @@
%>
<%@jet imports="org.eclipse.jet.core.parser.ast.*"%>
<%@jet imports="org.eclipse.jet.internal.compiler.V2CodeGenVisitor"%>
+<%@jet imports="org.eclipse.jet.internal.compiler.HasNewlinesUtil"%>
<%@jet imports="org.eclipse.jet.internal.compiler.TagUsageVisitor"%>
<%@jet imports="org.eclipse.jet.taglib.TagLibraryReference"%>
<%@jet imports="java.util.Arrays"%>
@@ -51,8 +52,10 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
public <%= cu.getOutputJavaClassName() %>() {
super();
}
+<% if(HasNewlinesUtil.test(cu)) { %>
- private static final String <%=nlConstantName%> = System.getProperties().getProperty("line.separator"); //$NON-NLS-1$
+ private static final String <%=nlConstantName%> = System.getProperty("line.separator"); //$NON-NLS-1$
+<% } %>
<% if(tuv.hasTags()) { %>
<% cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java
index bb25c36..b0a469b 100644
--- a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.input.jet.expected.java
@@ -13,7 +13,7 @@ public class _jet_simplev2input 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_test_tokenize_4_1 = new TagInfo("test:tokenize", //$NON-NLS-1$
4, 1,
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java
index 3baccfb..4757149 100644
--- a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.nopredefs.expected.java
@@ -10,7 +10,7 @@ public class _jet_simplev2usePredefTagLibs 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/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java
index dfe6f79..bb5ad30 100644
--- a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.usePredefTagLibs.jet.predefs.expected.java
@@ -13,7 +13,7 @@ public class _jet_simplev2usePredefTagLibs 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_3_1 = new TagInfo("c:get", //$NON-NLS-1$
3, 1,