Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-04-27 10:50:55 -0400
committerpelder2009-04-27 10:50:55 -0400
commit6a24e094718bf0054043217b0af95e86fac4f5bf (patch)
tree9aa2fff310fd3233e1021b6ea256590cddb9d46e
parent5e85ff303829de93b5c1e5df4b5e47aae2515449 (diff)
downloadorg.eclipse.jet-6a24e094718bf0054043217b0af95e86fac4f5bf.tar.gz
org.eclipse.jet-6a24e094718bf0054043217b0af95e86fac4f5bf.tar.xz
org.eclipse.jet-6a24e094718bf0054043217b0af95e86fac4f5bf.zip
[237825] Streamlining generated Transformation class
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java89
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.jet62
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java50
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java50
4 files changed, 117 insertions, 134 deletions
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 5025d31..5657cb5 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
@@ -63,27 +63,37 @@ boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)con
out.write(NL);
out.write(NL);
if(useJava5){
- out.write(" private static Map<String, Integer> pathToTemplateOrdinalMap = null;"); //$NON-NLS-1$
+ out.write(" private final static Map<String, Integer> pathToTemplateOrdinalMap = new HashMap<String,Integer>("); //$NON-NLS-1$
+ out.write(templateMap.size());
+ out.write(");"); //$NON-NLS-1$
out.write(NL);
} else {
- out.write(" private static Map pathToTemplateOrdinalMap = null;"); //$NON-NLS-1$
+ out.write(" private final static Map pathToTemplateOrdinalMap = new HashMap("); //$NON-NLS-1$
+ out.write(templateMap.size());
+ out.write(");"); //$NON-NLS-1$
out.write(NL);
}
+ out.write(" static {"); //$NON-NLS-1$
out.write(NL);
- out.write(" /*"); //$NON-NLS-1$
- out.write(NL);
- out.write(" * (non-Javadoc)"); //$NON-NLS-1$
- out.write(NL);
- out.write(" * "); //$NON-NLS-1$
- out.write(NL);
- out.write(" * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()"); //$NON-NLS-1$
- out.write(NL);
- out.write(" */"); //$NON-NLS-1$
+ int ordinal = 0;
+ for(Iterator i=templateMap.keySet().iterator(); i.hasNext(); ordinal++) {
+ String templatePath = (String)i.next();
+ out.write(" pathToTemplateOrdinalMap.put("); //$NON-NLS-1$
+ out.write( JavaUtil.asJavaQuotedString(templatePath) );
+ out.write(", //$NON-NLS-1$"); //$NON-NLS-1$
out.write(NL);
- out.write(" public JET2TemplateLoader getDelegateLoader() {"); //$NON-NLS-1$
+ if(useJava5) {
+ out.write(" Integer.valueOf("); //$NON-NLS-1$
+ out.write( ordinal );
+ out.write("));"); //$NON-NLS-1$
out.write(NL);
- out.write(" return this.delegate;"); //$NON-NLS-1$
+ } else {
+ out.write(" new Integer("); //$NON-NLS-1$
+ out.write( ordinal );
+ out.write("));"); //$NON-NLS-1$
out.write(NL);
+ }
+ }
out.write(" }"); //$NON-NLS-1$
out.write(NL);
out.write(NL);
@@ -99,12 +109,6 @@ boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)con
out.write(NL);
out.write(" public JET2Template getTemplate(final String templatePath) {"); //$NON-NLS-1$
out.write(NL);
- out.write(" if (pathToTemplateOrdinalMap == null) {"); //$NON-NLS-1$
- out.write(NL);
- out.write(" initPathToFactoryMap();"); //$NON-NLS-1$
- out.write(NL);
- out.write(" }"); //$NON-NLS-1$
- out.write(NL);
if(useJava5) {
out.write(" final Integer ordinal = pathToTemplateOrdinalMap.get(templatePath);"); //$NON-NLS-1$
out.write(NL);
@@ -112,58 +116,49 @@ boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)con
out.write(" final Integer ordinal = (Integer)pathToTemplateOrdinalMap.get(templatePath);"); //$NON-NLS-1$
out.write(NL);
}
- out.write(" switch (ordinal != null ? ordinal.intValue() : -1) {"); //$NON-NLS-1$
+ out.write(" if(ordinal != null) {"); //$NON-NLS-1$
out.write(NL);
- int ordinal = 0;
+ out.write(" switch (ordinal.intValue()) {"); //$NON-NLS-1$
+ out.write(NL);
+ ordinal = 0;
for(Iterator i=templateMap.entrySet().iterator(); i.hasNext(); ordinal++) {
Map.Entry entry = (Map.Entry)i.next();
- out.write(" case "); //$NON-NLS-1$
+ out.write(" case "); //$NON-NLS-1$
out.write( ordinal );
out.write(": // "); //$NON-NLS-1$
out.write( entry.getKey() );
out.write(NL);
- out.write(" return new "); //$NON-NLS-1$
+ out.write(" return new "); //$NON-NLS-1$
out.write( entry.getValue() );
out.write("();"); //$NON-NLS-1$
out.write(NL);
}
- out.write(" default:"); //$NON-NLS-1$
+ out.write(" default:"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" break;"); //$NON-NLS-1$
out.write(NL);
- out.write(" return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;"); //$NON-NLS-1$
+ out.write(" }"); //$NON-NLS-1$
out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
+ out.write(" return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;"); //$NON-NLS-1$
+ out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
out.write(NL);
- out.write(" private static synchronized void initPathToFactoryMap() {"); //$NON-NLS-1$
+ out.write(" /*"); //$NON-NLS-1$
out.write(NL);
- out.write(" if (pathToTemplateOrdinalMap == null) {"); //$NON-NLS-1$
+ out.write(" * (non-Javadoc)"); //$NON-NLS-1$
out.write(NL);
- if(useJava5) {
- out.write(" pathToTemplateOrdinalMap = new HashMap<String,Integer>("); //$NON-NLS-1$
- out.write(templateMap.size());
- out.write(");"); //$NON-NLS-1$
+ out.write(" * "); //$NON-NLS-1$
out.write(NL);
- } else {
- out.write(" pathToTemplateOrdinalMap = new HashMap("); //$NON-NLS-1$
- out.write(templateMap.size());
- out.write(");"); //$NON-NLS-1$
+ out.write(" * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()"); //$NON-NLS-1$
out.write(NL);
- }
- ordinal = 0;
- for(Iterator i=templateMap.keySet().iterator(); i.hasNext(); ordinal++) {
- String templatePath = (String)i.next();
- out.write(" pathToTemplateOrdinalMap.put("); //$NON-NLS-1$
- out.write( JavaUtil.asJavaQuotedString(templatePath) );
- out.write(", //$NON-NLS-1$"); //$NON-NLS-1$
+ out.write(" */"); //$NON-NLS-1$
out.write(NL);
- out.write(" new Integer("); //$NON-NLS-1$
- out.write( ordinal );
- out.write("));"); //$NON-NLS-1$
+ out.write(" public JET2TemplateLoader getDelegateLoader() {"); //$NON-NLS-1$
out.write(NL);
- }
- out.write(" }"); //$NON-NLS-1$
+ out.write(" return this.delegate;"); //$NON-NLS-1$
out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
diff --git a/plugins/org.eclipse.jet/templates/jet2transform.jet b/plugins/org.eclipse.jet/templates/jet2transform.jet
index faae06a..a6b8d63 100644
--- a/plugins/org.eclipse.jet/templates/jet2transform.jet
+++ b/plugins/org.eclipse.jet/templates/jet2transform.jet
@@ -37,18 +37,21 @@ public class <%= parms.getClassName() %> implements JET2TemplateLoader,
private JET2TemplateLoader delegate = null;
<% if(useJava5){ %>
- private static Map<String, Integer> pathToTemplateOrdinalMap = null;
+ private final static Map<String, Integer> pathToTemplateOrdinalMap = new HashMap<String,Integer>(<%=templateMap.size()%>);
<% } else { %>
- private static Map pathToTemplateOrdinalMap = null;
+ private final static Map pathToTemplateOrdinalMap = new HashMap(<%=templateMap.size()%>);
+<% } %>
+ static {
+<% int ordinal = 0;
+ for(Iterator i=templateMap.keySet().iterator(); i.hasNext(); ordinal++) {
+ String templatePath = (String)i.next(); %>
+ pathToTemplateOrdinalMap.put(<%= JavaUtil.asJavaQuotedString(templatePath) %>, //$NON-NLS-1$
+<% if(useJava5) { %>
+ Integer.valueOf(<%= ordinal %>));
+<% } else { %>
+ new Integer(<%= ordinal %>));
+<% } %>
<% } %>
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
- */
- public JET2TemplateLoader getDelegateLoader() {
- return this.delegate;
}
/*
@@ -57,40 +60,33 @@ public class <%= parms.getClassName() %> implements JET2TemplateLoader,
* @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)
*/
public JET2Template getTemplate(final String templatePath) {
- if (pathToTemplateOrdinalMap == null) {
- initPathToFactoryMap();
- }
<% if(useJava5) { %>
final Integer ordinal = pathToTemplateOrdinalMap.get(templatePath);
<% } else { %>
final Integer ordinal = (Integer)pathToTemplateOrdinalMap.get(templatePath);
<% } %>
- switch (ordinal != null ? ordinal.intValue() : -1) {
-<% int ordinal = 0;
+ if(ordinal != null) {
+ switch (ordinal.intValue()) {
+<% ordinal = 0;
for(Iterator i=templateMap.entrySet().iterator(); i.hasNext(); ordinal++) {
Map.Entry entry = (Map.Entry)i.next(); %>
- case <%= ordinal %>: // <%= entry.getKey() %>
- return new <%= entry.getValue() %>();
+ case <%= ordinal %>: // <%= entry.getKey() %>
+ return new <%= entry.getValue() %>();
<% } %>
- default:
- return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;
+ default:
+ break;
+ }
}
+ return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;
}
- private static synchronized void initPathToFactoryMap() {
- if (pathToTemplateOrdinalMap == null) {
-<% if(useJava5) { %>
- pathToTemplateOrdinalMap = new HashMap<String,Integer>(<%=templateMap.size()%>);
-<% } else { %>
- pathToTemplateOrdinalMap = new HashMap(<%=templateMap.size()%>);
-<% } %>
-<% ordinal = 0;
- for(Iterator i=templateMap.keySet().iterator(); i.hasNext(); ordinal++) {
- String templatePath = (String)i.next(); %>
- pathToTemplateOrdinalMap.put(<%= JavaUtil.asJavaQuotedString(templatePath) %>, //$NON-NLS-1$
- new Integer(<%= ordinal %>));
-<% } %>
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return this.delegate;
}
/*
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java
index a469191..073d081 100644
--- a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java
@@ -12,15 +12,12 @@ public class TemplateLoaderClass implements JET2TemplateLoader,
private JET2TemplateLoader delegate = null;
- private static Map pathToTemplateOrdinalMap = null;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
- */
- public JET2TemplateLoader getDelegateLoader() {
- return this.delegate;
+ private final static Map pathToTemplateOrdinalMap = new HashMap(2);
+ static {
+ pathToTemplateOrdinalMap.put("simple.v2.input.jet", //$NON-NLS-1$
+ new Integer(0));
+ pathToTemplateOrdinalMap.put("simple.v2.input2.jet", //$NON-NLS-1$
+ new Integer(1));
}
/*
@@ -29,28 +26,27 @@ public class TemplateLoaderClass implements JET2TemplateLoader,
* @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)
*/
public JET2Template getTemplate(final String templatePath) {
- if (pathToTemplateOrdinalMap == null) {
- initPathToFactoryMap();
- }
final Integer ordinal = (Integer)pathToTemplateOrdinalMap.get(templatePath);
- switch (ordinal != null ? ordinal.intValue() : -1) {
- case 0: // simple.v2.input.jet
- return new org.eclipse.jet.compiled._jet_simplev2input();
- case 1: // simple.v2.input2.jet
- return new org.eclipse.jet.compiled._jet_simplev2input2();
- default:
- return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;
+ if(ordinal != null) {
+ switch (ordinal.intValue()) {
+ case 0: // simple.v2.input.jet
+ return new org.eclipse.jet.compiled._jet_simplev2input();
+ case 1: // simple.v2.input2.jet
+ return new org.eclipse.jet.compiled._jet_simplev2input2();
+ default:
+ break;
+ }
}
+ return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;
}
- private static synchronized void initPathToFactoryMap() {
- if (pathToTemplateOrdinalMap == null) {
- pathToTemplateOrdinalMap = new HashMap(2);
- pathToTemplateOrdinalMap.put("simple.v2.input.jet", //$NON-NLS-1$
- new Integer(0));
- pathToTemplateOrdinalMap.put("simple.v2.input2.jet", //$NON-NLS-1$
- new Integer(1));
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return this.delegate;
}
/*
diff --git a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java
index 2edc603..ffe430e 100644
--- a/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java
@@ -12,15 +12,12 @@ public class TemplateLoaderClass implements JET2TemplateLoader,
private JET2TemplateLoader delegate = null;
- private static Map<String, Integer> pathToTemplateOrdinalMap = null;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
- */
- public JET2TemplateLoader getDelegateLoader() {
- return this.delegate;
+ private final static Map<String, Integer> pathToTemplateOrdinalMap = new HashMap<String,Integer>(2);
+ static {
+ pathToTemplateOrdinalMap.put("simple.v2.input.jet", //$NON-NLS-1$
+ Integer.valueOf(0));
+ pathToTemplateOrdinalMap.put("simple.v2.input2.jet", //$NON-NLS-1$
+ Integer.valueOf(1));
}
/*
@@ -29,28 +26,27 @@ public class TemplateLoaderClass implements JET2TemplateLoader,
* @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)
*/
public JET2Template getTemplate(final String templatePath) {
- if (pathToTemplateOrdinalMap == null) {
- initPathToFactoryMap();
- }
final Integer ordinal = pathToTemplateOrdinalMap.get(templatePath);
- switch (ordinal != null ? ordinal.intValue() : -1) {
- case 0: // simple.v2.input.jet
- return new org.eclipse.jet.compiled._jet_simplev2input();
- case 1: // simple.v2.input2.jet
- return new org.eclipse.jet.compiled._jet_simplev2input2();
- default:
- return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;
+ if(ordinal != null) {
+ switch (ordinal.intValue()) {
+ case 0: // simple.v2.input.jet
+ return new org.eclipse.jet.compiled._jet_simplev2input();
+ case 1: // simple.v2.input2.jet
+ return new org.eclipse.jet.compiled._jet_simplev2input2();
+ default:
+ break;
+ }
}
+ return this.delegate != null ? this.delegate.getTemplate(templatePath) : null;
}
- private static synchronized void initPathToFactoryMap() {
- if (pathToTemplateOrdinalMap == null) {
- pathToTemplateOrdinalMap = new HashMap<String,Integer>(2);
- pathToTemplateOrdinalMap.put("simple.v2.input.jet", //$NON-NLS-1$
- new Integer(0));
- pathToTemplateOrdinalMap.put("simple.v2.input2.jet", //$NON-NLS-1$
- new Integer(1));
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return this.delegate;
}
/*

Back to the top