Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.jet/templates/jet2transform.jet')
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.jet61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/org.eclipse.jet/templates/jet2transform.jet b/plugins/org.eclipse.jet/templates/jet2transform.jet
new file mode 100644
index 0000000..4362b29
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/jet2transform.jet
@@ -0,0 +1,61 @@
+<%@jet package="org.eclipse.jet.internal.compiler.templates"
+ class="JET2TransformGenerator"
+ %>
+<%@jet imports="java.util.Iterator"%>
+<%@jet imports="java.util.Map"%>
+<%@jet imports="org.eclipse.jet.BodyContentWriter"%>
+<%@jet imports="org.eclipse.jet.internal.compiler.LoaderGenerationParameters"%>
+<%
+LoaderGenerationParameters parms = (LoaderGenerationParameters)context.getVariable("args");
+Map templateMap = (Map) parms.getTemplateMap();;
+%>
+package <%= parms.getPackageName() %>;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.JET2TemplateLoaderExtension;
+import org.eclipse.jet.JET2Template;
+
+public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2TemplateLoaderExtension {
+
+ private interface TemplateFactoryMethod {
+ public abstract JET2Template newTemplate();
+ }
+
+ private Map pathToFactoryMap = null;
+
+ private JET2TemplateLoader delegate = null;
+
+ public <%= parms.getClassName() %>() {
+ super();
+ }
+
+ public JET2Template getTemplate(String templatePath) {
+ if(pathToFactoryMap == null) {
+ 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() %>();
+ }
+ });
+<% } %>
+ }
+ TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
+ return factory == null ? delegate == null ? null : delegate.getTemplate(templatePath) : factory.newTemplate();
+ }
+
+ public void setDelegateLoader(JET2TemplateLoader loader) {
+ this.delegate = loader;
+ }
+
+ public JET2TemplateLoader getDelegateLoader() {
+ return delegate;
+ }
+}
+

Back to the top