summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2007-07-11 15:21:13 (EDT)
committerpelder2007-07-11 15:21:13 (EDT)
commit49364f8b6aa750497cf2f0733982d40154749e1c (patch)
treef74e79964158b09fa5a72b54d78298ec899fb38f
parent41f81d40fc42738ee3b7a2847fc34bf6ab05595b (diff)
downloadorg.eclipse.jet-49364f8b6aa750497cf2f0733982d40154749e1c.zip
org.eclipse.jet-49364f8b6aa750497cf2f0733982d40154749e1c.tar.gz
org.eclipse.jet-49364f8b6aa750497cf2f0733982d40154749e1c.tar.bz2
[195858] JET1 code generator emits writes for empty strings
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/v1/JET1JavaGenerator.java40
-rw-r--r--plugins/org.eclipse.jet/templates/v1/jet2java.jet12
2 files changed, 30 insertions, 22 deletions
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 beceae0..83eb51a 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
@@ -18,7 +18,7 @@ public class JET1JavaGenerator implements JET2Template {
public void generate(final JET2Context context, final JET2Writer __out) {
JET2Writer out = __out;
-
+
JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
out.write("package "); //$NON-NLS-1$
@@ -26,26 +26,26 @@ public class JET1JavaGenerator implements JET2Template {
out.write(";"); //$NON-NLS-1$
out.write(NL);
out.write(NL);
- for(Iterator i=cu.getImports().iterator();i.hasNext();) {
+ for(Iterator i=cu.getImports().iterator();i.hasNext();) {
String importName = (String)i.next();
out.write("import "); //$NON-NLS-1$
out.write(importName);
out.write(";"); //$NON-NLS-1$
out.write(NL);
- }
+ }
out.write(NL);
out.write("public class "); //$NON-NLS-1$
out.write( cu.getOutputJavaClassName() );
out.write(NL);
out.write("{"); //$NON-NLS-1$
out.write(NL);
- cu.accept(new SafeJETASTVisitor(context,out) {
+ cu.accept(new SafeJETASTVisitor(context,out) {
public boolean visit(JavaDeclaration decl) {
- writeAndRecord(decl);
+ writeAndRecord(decl);
out.write("\t"); //$NON-NLS-1$
out.write(NL);
-
+
return true;
}
});
@@ -75,10 +75,11 @@ public class JET1JavaGenerator implements JET2Template {
out.write(NL);
out.write(" protected final String NL = nl == null ? (System.getProperties().getProperty(\"line.separator\")) : nl; //$NON-NLS-1$"); //$NON-NLS-1$
out.write(NL);
- cu.accept(new SafeJETASTVisitor(context,out) {
+ cu.accept(new SafeJETASTVisitor(context,out) {
private int textCount = 0;
public boolean visit(TextElement text) {
- textCount++;
+ if(text.getText().length > 0) {
+ textCount++;
out.write(" protected final String TEXT_"); //$NON-NLS-1$
out.write(textCount);
@@ -87,8 +88,9 @@ public class JET1JavaGenerator implements JET2Template {
out.write(";"); //$NON-NLS-1$
out.write(JavaUtil.nlsCommentsForJavaQuoteStringWithNLRemoved(text.getText()));
out.write(NL);
-
- return true;
+
+ }
+ return true;
}
});
@@ -99,32 +101,34 @@ public class JET1JavaGenerator implements JET2Template {
out.write(NL);
out.write(" final StringBuffer stringBuffer = new StringBuffer();"); //$NON-NLS-1$
out.write(NL);
- cu.accept(new SafeJETASTVisitor(context,out) {
+ cu.accept(new SafeJETASTVisitor(context,out) {
private int textCount = 0;
public boolean visit(TextElement text) {
- textCount++;
+ if(text.getText().length > 0) {
+ textCount++;
out.write(" stringBuffer.append(TEXT_"); //$NON-NLS-1$
out.write(textCount);
out.write(");"); //$NON-NLS-1$
out.write(NL);
-
- return true;
+
+ }
+ return true;
}
public boolean visit(JavaScriptlet scriptlet) {
- writeAndRecord(scriptlet);
+ writeAndRecord(scriptlet);
out.write(NL);
-
+
return true;
}
public boolean visit(JavaExpression expr) {
out.write(" stringBuffer.append("); //$NON-NLS-1$
- writeAndRecord(expr);
+ writeAndRecord(expr);
out.write(");"); //$NON-NLS-1$
out.write(NL);
-
+
return true;
}
});
diff --git a/plugins/org.eclipse.jet/templates/v1/jet2java.jet b/plugins/org.eclipse.jet/templates/v1/jet2java.jet
index e5fe1cf..7ab35d5 100644
--- a/plugins/org.eclipse.jet/templates/v1/jet2java.jet
+++ b/plugins/org.eclipse.jet/templates/v1/jet2java.jet
@@ -40,11 +40,13 @@ public class <%= cu.getOutputJavaClassName() %>
<% cu.accept(new SafeJETASTVisitor(context,out) {
private int textCount = 0;
public boolean visit(TextElement text) {
- textCount++;
+ if(text.getText().length > 0) {
+ textCount++;
%>
protected final String TEXT_<%=textCount%> = <%=JavaUtil.asJavaQuoteStringWithNLRemoved(text.getText())%>;<%=JavaUtil.nlsCommentsForJavaQuoteStringWithNLRemoved(text.getText())%>
<%
- return true;
+ }
+ return true;
}
});
%>
@@ -55,11 +57,13 @@ public class <%= cu.getOutputJavaClassName() %>
<% cu.accept(new SafeJETASTVisitor(context,out) {
private int textCount = 0;
public boolean visit(TextElement text) {
- textCount++;
+ if(text.getText().length > 0) {
+ textCount++;
%>
stringBuffer.append(TEXT_<%=textCount%>);
<%
- return true;
+ }
+ return true;
}
public boolean visit(JavaScriptlet scriptlet) {
%>