summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-09-07 23:32:50 (EDT)
committerpelder2006-09-07 23:32:50 (EDT)
commit4b45eb7aed17c94b7f4b516b24fa5641b223974e (patch)
tree4b1f6a58f52ffdb9e01820142870dc80ce83a2f6
parent319355c3fd9fc93bc7d744e9c786dde39b0a8188 (diff)
downloadorg.eclipse.jet-4b45eb7aed17c94b7f4b516b24fa5641b223974e.zip
org.eclipse.jet-4b45eb7aed17c94b7f4b516b24fa5641b223974e.tar.gz
org.eclipse.jet-4b45eb7aed17c94b7f4b516b24fa5641b223974e.tar.bz2
[156635] Generate a smaller JET Transformation class.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/templates/JET2TransformGenerator.java12
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.jet55
2 files changed, 50 insertions, 17 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 e869afc..31e958a 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
@@ -21,19 +21,19 @@ Map templateMap = (Map) parms.getTemplateMap();;
out.write( parms.getPackageName() );
out.write( ";\r\n\r\nimport java.util.HashMap;\r\nimport java.util.Map;\r\n\r\nimport org.eclipse.jet.JET2TemplateLoader;\r\nimport org.eclipse.jet.JET2TemplateLoaderExtension;\r\nimport org.eclipse.jet.JET2Template;\r\n\r\npublic class " ); //$NON-NLS-1$
out.write( parms.getClassName() );
- out.write( " implements JET2TemplateLoader, JET2TemplateLoaderExtension {\r\n\r\n\tprivate interface TemplateFactoryMethod {\r\n\t\tpublic abstract JET2Template newTemplate();\r\n\t}\r\n\r\n\tprivate Map pathToFactoryMap = null;\r\n\t\r\n\tprivate JET2TemplateLoader delegate = null;\r\n\r\n\tpublic " ); //$NON-NLS-1$
+ out.write( " implements JET2TemplateLoader, JET2TemplateLoaderExtension {\r\n\r\n\tprivate static final class TemplateFactoryMethod {\r\n\r\n\t\tprivate final String templatePath;\r\n\t\tprivate final String templateClass;\r\n\r\n\t\tpublic TemplateFactoryMethod(String templatePath, String templateClass) {\r\n\t\t\tthis.templatePath = templatePath;\r\n\t\t\tthis.templateClass = templateClass;\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tpublic String getTemplateClass() {\r\n\t\t\treturn templateClass;\r\n\t\t}\r\n\r\n\t\tpublic String getTemplatePath() {\r\n\t\t\treturn templatePath;\r\n\t\t}\r\n\r\n\t\tpublic JET2Template newTemplate() {\r\n\t\t\tJET2Template template = null;\r\n\t\t\ttry {\r\n\t\t\t\ttemplate = (JET2Template) Class.forName(templateClass).newInstance();\r\n\t\t\t} catch (InstantiationException e) {\r\n\t\t\t} catch (IllegalAccessException e) {\r\n\t\t\t} catch (ClassNotFoundException e) {\r\n\t\t\t}\r\n\t\t\treturn template;\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t}\r\n\r\n\tprivate Map pathToFactoryMap = null;\r\n\t\r\n\tprivate JET2TemplateLoader delegate = null;\r\n\r\n\tpublic " ); //$NON-NLS-1$
out.write( parms.getClassName() );
- out.write( "() {\r\n\t\tsuper();\r\n\t}\r\n\r\n\tpublic JET2Template getTemplate(String templatePath) {\r\n\t if(pathToFactoryMap == null) {\r\n\t pathToFactoryMap = new HashMap(" ); //$NON-NLS-1$
+ out.write( "() {\r\n\t\tsuper();\r\n\t}\r\n\r\n\tpublic JET2Template getTemplate(String templatePath) {\r\n\t if(pathToFactoryMap == null) {\r\n \t initPathToFactoryMap();\r\n }\r\n TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);\r\n\t\treturn factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();\r\n\t}\r\n\r\n\tprivate void addTemplate(String templatePath, String templateClass) {\r\n\t\tpathToFactoryMap.put(templatePath, //$NON-NLS-1$\r\n\t\t new TemplateFactoryMethod(templatePath, templateClass));\r\n\t}\r\n\t\r\n private void initPathToFactoryMap() {\r\n\t pathToFactoryMap = new HashMap(" ); //$NON-NLS-1$
out.write( templateMap.size() );
out.write( ");\r\n" ); //$NON-NLS-1$
for(Iterator i = templateMap.entrySet().iterator(); i.hasNext();){
Map.Entry entry = (Map.Entry)i.next();
- out.write( "\t\t pathToFactoryMap.put(\"" ); //$NON-NLS-1$
+ out.write( "\t\t addTemplate(\"" ); //$NON-NLS-1$
out.write( entry.getKey() );
- out.write( "\", //$NON-NLS-1$\r\n\t\t new TemplateFactoryMethod() {\r\n\t\t public JET2Template newTemplate() {\r\n return new " ); //$NON-NLS-1$
+ out.write( "\", \"" ); //$NON-NLS-1$
out.write( entry.getValue() );
- out.write( "();\r\n\t\t }\r\n\t\t });\r\n" ); //$NON-NLS-1$
- } out.write( " }\r\n TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);\r\n\t\treturn factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();\r\n\t}\r\n\r\n public void setDelegateLoader(JET2TemplateLoader loader) {\r\n this.delegate = loader;\r\n }\r\n \r\n public JET2TemplateLoader getDelegateLoader() {\r\n return delegate;\r\n }\r\n}\r\n\r\n" ); //$NON-NLS-1$
+ out.write( "\" ); //$NON-NLS-1$ //$NON-NLS-2$\r\n" ); //$NON-NLS-1$
+ } out.write( "\t}\r\n\r\n public void setDelegateLoader(JET2TemplateLoader loader) {\r\n this.delegate = loader;\r\n }\r\n \r\n public JET2TemplateLoader getDelegateLoader() {\r\n return delegate;\r\n }\r\n}\r\n\r\n" ); //$NON-NLS-1$
}
diff --git a/plugins/org.eclipse.jet/templates/jet2transform.jet b/plugins/org.eclipse.jet/templates/jet2transform.jet
index ea9a31e..b52e10b 100644
--- a/plugins/org.eclipse.jet/templates/jet2transform.jet
+++ b/plugins/org.eclipse.jet/templates/jet2transform.jet
@@ -19,8 +19,37 @@ import org.eclipse.jet.JET2Template;
public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2TemplateLoaderExtension {
- private interface TemplateFactoryMethod {
- public abstract JET2Template newTemplate();
+ 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 templateClass;
+ }
+
+ public String getTemplatePath() {
+ return templatePath;
+ }
+
+ public JET2Template newTemplate() {
+ JET2Template template = null;
+ try {
+ template = (JET2Template) Class.forName(templateClass).newInstance();
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ } catch (ClassNotFoundException e) {
+ }
+ return template;
+ }
+
+
}
private Map pathToFactoryMap = null;
@@ -33,20 +62,24 @@ public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2Temp
public JET2Template getTemplate(String templatePath) {
if(pathToFactoryMap == null) {
+ initPathToFactoryMap();
+ }
+ TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
+ return factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();
+ }
+
+ private void addTemplate(String templatePath, String templateClass) {
+ pathToFactoryMap.put(templatePath, //$NON-NLS-1$
+ new TemplateFactoryMethod(templatePath, templateClass));
+ }
+
+ private void initPathToFactoryMap() {
pathToFactoryMap = new HashMap(<%= templateMap.size() %>);
<% for(Iterator i = templateMap.entrySet().iterator(); i.hasNext();){
Map.Entry entry = (Map.Entry)i.next();
%>
- pathToFactoryMap.put("<%= entry.getKey() %>", //$NON-NLS-1$
- new TemplateFactoryMethod() {
- public JET2Template newTemplate() {
- return new <%= entry.getValue() %>();
- }
- });
+ addTemplate("<%= entry.getKey() %>", "<%= entry.getValue() %>" ); //$NON-NLS-1$ //$NON-NLS-2$
<% } %>
- }
- TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
- return factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();
}
public void setDelegateLoader(JET2TemplateLoader loader) {