Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2009-04-13 15:42:09 -0400
committerpelder2009-04-13 15:42:09 -0400
commit7150bffe2b9e6e0a5f06eb2080fb769007b65226 (patch)
tree219fded0156a8ca2d07d6db9081004ce12ef1fc9
parentea3b1abcf7805fef62b4c339fe33709af114fe5f (diff)
downloadorg.eclipse.jet-7150bffe2b9e6e0a5f06eb2080fb769007b65226.tar.gz
org.eclipse.jet-7150bffe2b9e6e0a5f06eb2080fb769007b65226.tar.xz
org.eclipse.jet-7150bffe2b9e6e0a5f06eb2080fb769007b65226.zip
[272059] Compiler warnings about unused functions on JET generated template loader class
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java12
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java193
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.jet146
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.expected.java105
-rw-r--r--tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java66
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestSimplifiedCompiler.java23
6 files changed, 302 insertions, 243 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java
index 15a7181..3ffb14f 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/JavaUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2009 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
@@ -99,6 +99,16 @@ public class JavaUtil
}
/**
+ * Return a Java string, including initial and final double quotes, and inserting
+ * any required Java escape sequences.
+ * @param content the text to quote
+ * @return the quoted Java string
+ */
+ public static String asJavaQuotedString(String content) {
+ return asJavaQuotedString(content.toCharArray());
+ }
+
+ /**
* Return a Java String expression with + NL + in place of new line data
* @param text
* @return
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 c0ac206..b16e549 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
@@ -1,13 +1,23 @@
+/*
+ * Copyright (c) 2006, 2009 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
+ */
package org.eclipse.jet.internal.compiler.templates;
import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import org.eclipse.jet.internal.JavaUtil;
import org.eclipse.jet.internal.compiler.LoaderGenerationParameters;
public class JET2TransformGenerator implements JET2Template {
@@ -22,8 +32,8 @@ public class JET2TransformGenerator implements JET2Template {
JET2Writer out = __out;
LoaderGenerationParameters parms = (LoaderGenerationParameters)context.getVariable("args"); //$NON-NLS-1$
-Map templateMap = (Map) parms.getTemplateMap();;
-boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)context.getVariable("useJava5")).booleanValue() : false;
+SortedMap templateMap = new TreeMap(parms.getTemplateMap());
+boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)context.getVariable("useJava5")).booleanValue() : false; //$NON-NLS-1$ //$NON-NLS-2$
out.write("package "); //$NON-NLS-1$
out.write( parms.getPackageName() );
@@ -35,177 +45,150 @@ boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)con
out.write("import java.util.Map;"); //$NON-NLS-1$
out.write(NL);
out.write(NL);
+ out.write("import org.eclipse.jet.JET2Template;"); //$NON-NLS-1$
+ out.write(NL);
out.write("import org.eclipse.jet.JET2TemplateLoader;"); //$NON-NLS-1$
out.write(NL);
out.write("import org.eclipse.jet.JET2TemplateLoaderExtension;"); //$NON-NLS-1$
out.write(NL);
- out.write("import org.eclipse.jet.JET2Template;"); //$NON-NLS-1$
- out.write(NL);
out.write(NL);
out.write("public class "); //$NON-NLS-1$
out.write( parms.getClassName() );
- out.write(" implements JET2TemplateLoader, JET2TemplateLoaderExtension {"); //$NON-NLS-1$
- out.write(NL);
- out.write(NL);
- out.write(" private static final class TemplateFactoryMethod {"); //$NON-NLS-1$
- out.write(NL);
+ out.write(" implements JET2TemplateLoader,"); //$NON-NLS-1$
out.write(NL);
- out.write(" private final String templatePath;"); //$NON-NLS-1$
+ out.write(" JET2TemplateLoaderExtension {"); //$NON-NLS-1$
out.write(NL);
- out.write(" private final String templateClass;"); //$NON-NLS-1$
out.write(NL);
+ out.write(" private JET2TemplateLoader delegate = null;"); //$NON-NLS-1$
out.write(NL);
- out.write(" public TemplateFactoryMethod(String templatePath, String templateClass) {"); //$NON-NLS-1$
- out.write(NL);
- out.write(" this.templatePath = templatePath;"); //$NON-NLS-1$
- out.write(NL);
- out.write(" this.templateClass = templateClass;"); //$NON-NLS-1$
- out.write(NL);
- out.write(" "); //$NON-NLS-1$
- out.write(NL);
- out.write(" }"); //$NON-NLS-1$
- out.write(NL);
- out.write(" "); //$NON-NLS-1$
out.write(NL);
- out.write(" public String getTemplateClass() {"); //$NON-NLS-1$
+ if(useJava5){
+ out.write(" private static Map<String, Integer> pathToTemplateOrdinalMap = null;"); //$NON-NLS-1$
out.write(NL);
- out.write(" return this.templateClass;"); //$NON-NLS-1$
+ } else {
+ out.write(" private static Map pathToTemplateOrdinalMap = null;"); //$NON-NLS-1$
out.write(NL);
- out.write(" }"); //$NON-NLS-1$
+ }
out.write(NL);
+ out.write(" /*"); //$NON-NLS-1$
out.write(NL);
- out.write(" public String getTemplatePath() {"); //$NON-NLS-1$
+ out.write(" * (non-Javadoc)"); //$NON-NLS-1$
out.write(NL);
- out.write(" return this.templatePath;"); //$NON-NLS-1$
+ out.write(" * "); //$NON-NLS-1$
out.write(NL);
- out.write(" }"); //$NON-NLS-1$
+ out.write(" * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()"); //$NON-NLS-1$
out.write(NL);
+ out.write(" */"); //$NON-NLS-1$
out.write(NL);
- out.write(" public JET2Template newTemplate() {"); //$NON-NLS-1$
+ out.write(" public JET2TemplateLoader getDelegateLoader() {"); //$NON-NLS-1$
out.write(NL);
- out.write(" JET2Template template = null;"); //$NON-NLS-1$
+ out.write(" return delegate;"); //$NON-NLS-1$
out.write(NL);
- out.write(" try {"); //$NON-NLS-1$
+ out.write(" }"); //$NON-NLS-1$
out.write(NL);
- out.write(" template = (JET2Template) Class.forName(this.templateClass).newInstance();"); //$NON-NLS-1$
out.write(NL);
- out.write(" } catch (InstantiationException e) {"); //$NON-NLS-1$
+ out.write(" /*"); //$NON-NLS-1$
out.write(NL);
- out.write(" // ignore"); //$NON-NLS-1$
+ out.write(" * (non-Javadoc)"); //$NON-NLS-1$
out.write(NL);
- out.write(" } catch (IllegalAccessException e) {"); //$NON-NLS-1$
+ out.write(" * "); //$NON-NLS-1$
out.write(NL);
- out.write(" // ignore"); //$NON-NLS-1$
+ out.write(" * @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)"); //$NON-NLS-1$
out.write(NL);
- out.write(" } catch (ClassNotFoundException e) {"); //$NON-NLS-1$
+ out.write(" */"); //$NON-NLS-1$
out.write(NL);
- out.write(" // ignore"); //$NON-NLS-1$
+ out.write(" public JET2Template getTemplate(final String templatePath) {"); //$NON-NLS-1$
out.write(NL);
- out.write(" }"); //$NON-NLS-1$
+ out.write(" if (pathToTemplateOrdinalMap == null) {"); //$NON-NLS-1$
out.write(NL);
- out.write(" return template;"); //$NON-NLS-1$
+ out.write(" initPathToFactoryMap();"); //$NON-NLS-1$
out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
- out.write(" "); //$NON-NLS-1$
- out.write(NL);
- out.write(" "); //$NON-NLS-1$
- out.write(NL);
- out.write(" }"); //$NON-NLS-1$
- out.write(NL);
- out.write(NL);
if(useJava5) {
- out.write(" private Map<String,TemplateFactoryMethod> pathToFactoryMap = null;"); //$NON-NLS-1$
+ out.write(" final Integer ordinal = pathToTemplateOrdinalMap.get(templatePath);"); //$NON-NLS-1$
out.write(NL);
} else {
- out.write(" private Map pathToFactoryMap = null;"); //$NON-NLS-1$
+ out.write(" final Integer ordinal = (Integer)pathToTemplateOrdinalMap.get(templatePath);"); //$NON-NLS-1$
out.write(NL);
}
- out.write(" "); //$NON-NLS-1$
- out.write(NL);
- out.write(" private JET2TemplateLoader delegate = null;"); //$NON-NLS-1$
+ out.write(" switch (ordinal != null ? ordinal.intValue() : -1) {"); //$NON-NLS-1$
out.write(NL);
+ int 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( ordinal );
+ out.write(": // "); //$NON-NLS-1$
+ out.write( entry.getKey() );
out.write(NL);
- out.write(" public "); //$NON-NLS-1$
- out.write( parms.getClassName() );
- out.write("() {"); //$NON-NLS-1$
- out.write(NL);
- out.write(" super();"); //$NON-NLS-1$
- out.write(NL);
- out.write(" }"); //$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(NL);
- out.write(" public JET2Template getTemplate(String templatePath) {"); //$NON-NLS-1$
- out.write(NL);
- out.write(" if(this.pathToFactoryMap == null) {"); //$NON-NLS-1$
- out.write(NL);
- out.write(" initPathToFactoryMap();"); //$NON-NLS-1$
+ out.write(" return delegate != null ? delegate.getTemplate(templatePath) : null;"); //$NON-NLS-1$
out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
- out.write(" TemplateFactoryMethod factory = (TemplateFactoryMethod)this.pathToFactoryMap.get(templatePath);"); //$NON-NLS-1$
- out.write(NL);
- out.write(" return factory == null ? this.delegate == null ? null : this.delegate.getTemplate(templatePath) : factory.newTemplate();"); //$NON-NLS-1$
- out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
out.write(NL);
- out.write(" private void addTemplate(String templatePath, String templateClass) {"); //$NON-NLS-1$
- out.write(NL);
- out.write(" this.pathToFactoryMap.put(templatePath,"); //$NON-NLS-1$
- out.write(NL);
- out.write(" new TemplateFactoryMethod(templatePath, templateClass));"); //$NON-NLS-1$
- out.write(NL);
- out.write(" }"); //$NON-NLS-1$
- out.write(NL);
- out.write(" "); //$NON-NLS-1$
+ out.write(" private static synchronized void initPathToFactoryMap() {"); //$NON-NLS-1$
out.write(NL);
- out.write(" private void initPathToFactoryMap() {"); //$NON-NLS-1$
+ out.write(" if (pathToTemplateOrdinalMap == null) {"); //$NON-NLS-1$
out.write(NL);
-if(useJava5) {
- out.write(" this.pathToFactoryMap = new HashMap<String,TemplateFactoryMethod>("); //$NON-NLS-1$
- out.write( templateMap.size() );
+ if(useJava5) {
+ out.write(" pathToTemplateOrdinalMap = new HashMap<String,Integer>("); //$NON-NLS-1$
+ out.write(templateMap.size());
out.write(");"); //$NON-NLS-1$
out.write(NL);
} else {
- out.write(" this.pathToFactoryMap = new HashMap("); //$NON-NLS-1$
- out.write( templateMap.size() );
+ out.write(" pathToTemplateOrdinalMap = new HashMap("); //$NON-NLS-1$
+ out.write(templateMap.size());
out.write(");"); //$NON-NLS-1$
out.write(NL);
}
-
- List templatePaths = new ArrayList(templateMap.keySet());
- Collections.sort(templatePaths);
- for(Iterator i = templatePaths.iterator(); i.hasNext();){
- String key = (String)i.next();
- String value = (String)templateMap.get(key);
-
- out.write(" addTemplate(\""); //$NON-NLS-1$
- out.write( key );
- out.write("\", \""); //$NON-NLS-1$
- out.write( value );
- out.write("\" ); //$NON-NLS-1$ //$NON-NLS-2$"); //$NON-NLS-1$
+ 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$
+ out.write(NL);
+ 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(" }"); //$NON-NLS-1$
out.write(NL);
out.write(NL);
- out.write(" public void setDelegateLoader(JET2TemplateLoader loader) {"); //$NON-NLS-1$
+ out.write(" /*"); //$NON-NLS-1$
out.write(NL);
- out.write(" this.delegate = loader;"); //$NON-NLS-1$
+ out.write(" * (non-Javadoc)"); //$NON-NLS-1$
out.write(NL);
- out.write(" }"); //$NON-NLS-1$
+ out.write(" * "); //$NON-NLS-1$
out.write(NL);
- out.write(" "); //$NON-NLS-1$
+ out.write(" * @see"); //$NON-NLS-1$
out.write(NL);
- out.write(" public JET2TemplateLoader getDelegateLoader() {"); //$NON-NLS-1$
+ out.write(" * org.eclipse.jet.JET2TemplateLoaderExtension#setDelegateLoader(org.eclipse"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" * .jet.JET2TemplateLoader)"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" */"); //$NON-NLS-1$
out.write(NL);
- out.write(" return this.delegate;"); //$NON-NLS-1$
+ out.write(" public void setDelegateLoader(final JET2TemplateLoader loader) {"); //$NON-NLS-1$
+ out.write(NL);
+ out.write(" this.delegate = loader;"); //$NON-NLS-1$
out.write(NL);
out.write(" }"); //$NON-NLS-1$
out.write(NL);
out.write("}"); //$NON-NLS-1$
out.write(NL);
- out.write(NL);
}
}
diff --git a/plugins/org.eclipse.jet/templates/jet2transform.jet b/plugins/org.eclipse.jet/templates/jet2transform.jet
index 16c239e..f3f1514 100644
--- a/plugins/org.eclipse.jet/templates/jet2transform.jet
+++ b/plugins/org.eclipse.jet/templates/jet2transform.jet
@@ -1,112 +1,106 @@
<%@jet package="org.eclipse.jet.internal.compiler.templates"
class="JET2TransformGenerator"
%>
-<%@jet imports="java.util.ArrayList"%>
-<%@jet imports="java.util.Collections"%>
+<%-- @header
+Copyright (c) 2006, 2009 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
+--%>
<%@jet imports="java.util.Iterator"%>
-<%@jet imports="java.util.List"%>
<%@jet imports="java.util.Map"%>
+<%@jet imports="java.util.SortedMap"%>
+<%@jet imports="java.util.TreeMap"%>
+<%@jet imports="org.eclipse.jet.internal.JavaUtil"%>
<%@jet imports="org.eclipse.jet.internal.compiler.LoaderGenerationParameters"%>
<%
LoaderGenerationParameters parms = (LoaderGenerationParameters)context.getVariable("args"); //$NON-NLS-1$
-Map templateMap = (Map) parms.getTemplateMap();;
-boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)context.getVariable("useJava5")).booleanValue() : false;
+SortedMap templateMap = new TreeMap(parms.getTemplateMap());
+boolean useJava5 = context.hasVariable("useJava5") ? Boolean.valueOf((String)context.getVariable("useJava5")).booleanValue() : false; //$NON-NLS-1$ //$NON-NLS-2$
%>
package <%= parms.getPackageName() %>;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.JET2TemplateLoaderExtension;
-import org.eclipse.jet.JET2Template;
-
-public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2TemplateLoaderExtension {
-
- private static final class TemplateFactoryMethod {
-
- private final String templatePath;
- private final String templateClass;
-
- public TemplateFactoryMethod(String templatePath, String templateClass) {
- this.templatePath = templatePath;
- this.templateClass = templateClass;
-
- }
-
- public String getTemplateClass() {
- return this.templateClass;
- }
- public String getTemplatePath() {
- return this.templatePath;
- }
+public class <%= parms.getClassName() %> implements JET2TemplateLoader,
+ JET2TemplateLoaderExtension {
- public JET2Template newTemplate() {
- JET2Template template = null;
- try {
- template = (JET2Template) Class.forName(this.templateClass).newInstance();
- } catch (InstantiationException e) {
- // ignore
- } catch (IllegalAccessException e) {
- // ignore
- } catch (ClassNotFoundException e) {
- // ignore
- }
- return template;
- }
-
-
- }
+ private JET2TemplateLoader delegate = null;
-<% if(useJava5) { %>
- private Map<String,TemplateFactoryMethod> pathToFactoryMap = null;
+<% if(useJava5){ %>
+ private static Map<String, Integer> pathToTemplateOrdinalMap = null;
<% } else { %>
- private Map pathToFactoryMap = null;
+ private static Map pathToTemplateOrdinalMap = null;
<% } %>
-
- private JET2TemplateLoader delegate = null;
- public <%= parms.getClassName() %>() {
- super();
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
}
- public JET2Template getTemplate(String templatePath) {
- if(this.pathToFactoryMap == null) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)
+ */
+ public JET2Template getTemplate(final String templatePath) {
+ if (pathToTemplateOrdinalMap == null) {
initPathToFactoryMap();
}
- TemplateFactoryMethod factory = (TemplateFactoryMethod)this.pathToFactoryMap.get(templatePath);
- return factory == null ? this.delegate == null ? null : this.delegate.getTemplate(templatePath) : factory.newTemplate();
+<% 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;
+ for(Iterator i=templateMap.entrySet().iterator(); i.hasNext(); ordinal++) {
+ Map.Entry entry = (Map.Entry)i.next(); %>
+ case <%= ordinal %>: // <%= entry.getKey() %>
+ return new <%= entry.getValue() %>();
+<% } %>
+ default:
+ return delegate != null ? delegate.getTemplate(templatePath) : null;
+ }
}
- private void addTemplate(String templatePath, String templateClass) {
- this.pathToFactoryMap.put(templatePath,
- new TemplateFactoryMethod(templatePath, templateClass));
- }
-
- private void initPathToFactoryMap() {
-<%if(useJava5) { %>
- this.pathToFactoryMap = new HashMap<String,TemplateFactoryMethod>(<%= templateMap.size() %>);
+ private static synchronized void initPathToFactoryMap() {
+ if (pathToTemplateOrdinalMap == null) {
+<% if(useJava5) { %>
+ pathToTemplateOrdinalMap = new HashMap<String,Integer>(<%=templateMap.size()%>);
<% } else { %>
- this.pathToFactoryMap = new HashMap(<%= templateMap.size() %>);
+ pathToTemplateOrdinalMap = new HashMap(<%=templateMap.size()%>);
<% } %>
-<%
- List templatePaths = new ArrayList(templateMap.keySet());
- Collections.sort(templatePaths);
- for(Iterator i = templatePaths.iterator(); i.hasNext();){
- String key = (String)i.next();
- String value = (String)templateMap.get(key);
-%>
- addTemplate("<%= key %>", "<%= value %>" ); //$NON-NLS-1$ //$NON-NLS-2$
+<% ordinal = 0;
+ for(Iterator i=templateMap.keySet().iterator(); i.hasNext(); ordinal++) {
+ String templatePath = (String)i.next(); %>
+ pathToTemplateOrdinalMap.put(<%= JavaUtil.asJavaQuotedString(templatePath) %>,
+ new Integer(<%= ordinal %>));
<% } %>
+ }
}
- public void setDelegateLoader(JET2TemplateLoader loader) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jet.JET2TemplateLoaderExtension#setDelegateLoader(org.eclipse
+ * .jet.JET2TemplateLoader)
+ */
+ public void setDelegateLoader(final JET2TemplateLoader loader) {
this.delegate = loader;
}
-
- 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 7cb9a2a..5545305 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
@@ -3,81 +3,64 @@ package org.eclipse.jet.compiled;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2TemplateLoader;
import org.eclipse.jet.JET2TemplateLoaderExtension;
-import org.eclipse.jet.JET2Template;
-
-public class TemplateLoaderClass implements JET2TemplateLoader, JET2TemplateLoaderExtension {
-
- private static final class TemplateFactoryMethod {
-
- private final String templatePath;
- private final String templateClass;
-
- public TemplateFactoryMethod(String templatePath, String templateClass) {
- this.templatePath = templatePath;
- this.templateClass = templateClass;
-
- }
-
- public String getTemplateClass() {
- return this.templateClass;
- }
-
- public String getTemplatePath() {
- return this.templatePath;
- }
- public JET2Template newTemplate() {
- JET2Template template = null;
- try {
- template = (JET2Template) Class.forName(this.templateClass).newInstance();
- } catch (InstantiationException e) {
- // ignore
- } catch (IllegalAccessException e) {
- // ignore
- } catch (ClassNotFoundException e) {
- // ignore
- }
- return template;
- }
-
-
- }
+public class TemplateLoaderClass implements JET2TemplateLoader,
+ JET2TemplateLoaderExtension {
- private Map pathToFactoryMap = null;
-
private JET2TemplateLoader delegate = null;
- public TemplateLoaderClass() {
- super();
+ private static Map pathToTemplateOrdinalMap = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
}
- public JET2Template getTemplate(String templatePath) {
- if(this.pathToFactoryMap == null) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoader#getTemplate(java.lang.String)
+ */
+ public JET2Template getTemplate(final String templatePath) {
+ if (pathToTemplateOrdinalMap == null) {
initPathToFactoryMap();
}
- TemplateFactoryMethod factory = (TemplateFactoryMethod)this.pathToFactoryMap.get(templatePath);
- return factory == null ? this.delegate == null ? null : this.delegate.getTemplate(templatePath) : factory.newTemplate();
+ 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 delegate != null ? delegate.getTemplate(templatePath) : null;
+ }
}
- private void addTemplate(String templatePath, String templateClass) {
- this.pathToFactoryMap.put(templatePath,
- new TemplateFactoryMethod(templatePath, templateClass));
- }
-
- private void initPathToFactoryMap() {
- this.pathToFactoryMap = new HashMap(2);
- addTemplate("simple.v2.input.jet", "org.eclipse.jet.compiled._jet_simplev2input" ); //$NON-NLS-1$ //$NON-NLS-2$
- addTemplate("simple.v2.input2.jet", "org.eclipse.jet.compiled._jet_simplev2input2" ); //$NON-NLS-1$ //$NON-NLS-2$
+ private static synchronized void initPathToFactoryMap() {
+ if (pathToTemplateOrdinalMap == null) {
+ pathToTemplateOrdinalMap = new HashMap(2);
+ pathToTemplateOrdinalMap.put("simple.v2.input.jet",
+ new Integer(0));
+ pathToTemplateOrdinalMap.put("simple.v2.input2.jet",
+ new Integer(1));
+ }
}
- public void setDelegateLoader(JET2TemplateLoader loader) {
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jet.JET2TemplateLoaderExtension#setDelegateLoader(org.eclipse
+ * .jet.JET2TemplateLoader)
+ */
+ public void setDelegateLoader(final JET2TemplateLoader loader) {
this.delegate = loader;
}
-
- 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
new file mode 100644
index 0000000..b41aec8
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/simplifiedCompiler/templates/simple.v2.loader.java5.expected.java
@@ -0,0 +1,66 @@
+package org.eclipse.jet.compiled;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.JET2TemplateLoaderExtension;
+
+public class TemplateLoaderClass implements JET2TemplateLoader,
+ JET2TemplateLoaderExtension {
+
+ private JET2TemplateLoader delegate = null;
+
+ private static Map<String, Integer> pathToTemplateOrdinalMap = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jet.JET2TemplateLoaderExtension#getDelegateLoader()
+ */
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @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 delegate != null ? delegate.getTemplate(templatePath) : null;
+ }
+ }
+
+ private static synchronized void initPathToFactoryMap() {
+ if (pathToTemplateOrdinalMap == null) {
+ pathToTemplateOrdinalMap = new HashMap<String,Integer>(2);
+ pathToTemplateOrdinalMap.put("simple.v2.input.jet",
+ new Integer(0));
+ pathToTemplateOrdinalMap.put("simple.v2.input2.jet",
+ new Integer(1));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jet.JET2TemplateLoaderExtension#setDelegateLoader(org.eclipse
+ * .jet.JET2TemplateLoader)
+ */
+ public void setDelegateLoader(final JET2TemplateLoader loader) {
+ this.delegate = loader;
+ }
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestSimplifiedCompiler.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestSimplifiedCompiler.java
index 575867c..529e818 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestSimplifiedCompiler.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestSimplifiedCompiler.java
@@ -227,6 +227,29 @@ public class TestSimplifiedCompiler extends TestCase {
}
/**
+ * Test method for {@link org.eclipse.jet.internal.compiler.SimplifiedCompiler#finish()}.
+ * @throws Exception
+ */
+ public void testFinishJava5() throws Exception {
+ Map options = new HashMap(JETCompilerOptions.getDefaultCompilerOptions());
+ options.put(JETCompilerOptions.OPTION_USE_JAVA5, "true");
+ IJETCompiler compiler = new SimplifiedCompiler.Builder(JETAST.JET_SPEC_V2, baseLocation, compilerOutput)
+ .templateLoaderFQN("org.eclipse.jet.compiled.TemplateLoaderClass")
+ .options(options)
+ .build();
+
+ final String templatePath1 = "simple.v2.input.jet";
+ compiler.compile(templatePath1);
+ final String templatePath2 = "simple.v2.input2.jet";
+ compiler.compile(templatePath2);
+
+ compiler.finish();
+ assertEquals("org/eclipse/jet/compiled/TemplateLoaderClass.java", compilerOutput.getOutputFilePath());
+ final String expectedJavaCode = FileUtils.getFileContents(baseLocation.resolve("simple.v2.loader.java5.expected.java").toString(), true);
+ assertEquals("code", expectedJavaCode, compilerOutput.getCode());
+ }
+
+ /**
* Test method for {@link org.eclipse.jet.internal.compiler.SimplifiedCompiler#compile(java.lang.String)} in the
* case where an output class is changed in successive compiles of a template
*/

Back to the top