Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.jet/templates')
-rw-r--r--plugins/org.eclipse.jet/templates/jet2java.javajet94
-rw-r--r--plugins/org.eclipse.jet/templates/jet2java.jet81
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.jet (renamed from plugins/org.eclipse.jet/templates/jet2transform.javajet)11
-rw-r--r--plugins/org.eclipse.jet/templates/main.jet2
-rw-r--r--plugins/org.eclipse.jet/templates/tagDataDeclarations.jet30
-rw-r--r--plugins/org.eclipse.jet/templates/writeJavaExpression.jet7
-rw-r--r--plugins/org.eclipse.jet/templates/writeTextElement.jet10
-rw-r--r--plugins/org.eclipse.jet/templates/xmlEnd.javajet15
-rw-r--r--plugins/org.eclipse.jet/templates/xmlEnd.jet13
-rw-r--r--plugins/org.eclipse.jet/templates/xmlStart.javajet21
-rw-r--r--plugins/org.eclipse.jet/templates/xmlStart.jet18
11 files changed, 168 insertions, 134 deletions
diff --git a/plugins/org.eclipse.jet/templates/jet2java.javajet b/plugins/org.eclipse.jet/templates/jet2java.javajet
deleted file mode 100644
index 1c29187..0000000
--- a/plugins/org.eclipse.jet/templates/jet2java.javajet
+++ /dev/null
@@ -1,94 +0,0 @@
-<%@jet package="org.eclipse.jet.internal.compiler.templates"
- class="JET2JavaGenerator"
- imports="org.eclipse.jet.internal.compiler.* org.eclipse.jet.compiler.* org.eclipse.jet.internal.JavaUtil org.eclipse.jet.taglib.TagLibraryReference java.util.Iterator"
- %>
-<%
- JET2CompilationUnit cu = (JET2CompilationUnit)argument;
-
- final StringBuffer declarations = new StringBuffer();
- cu.accept(new DefaultJET2ASTVisitor() {
- public void visit(JET2Declaration declaration) {
- declarations.append(declaration.getJavaContent());
- }
- });
-
- final StringBuffer tagNamespaceVariables = new StringBuffer();
- TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
- for(int i = 0; i < tlRefs.length; i++ ) {
- ;
- tagNamespaceVariables.append("public static final String _jetns_")
- .append(tlRefs[i].getPrefix())
- .append(" = \"")
- .append(tlRefs[i].getTagLibraryId())
- .append("\";")
- .append("//$NON-NLS-1$")
- .append(NL);
-
- }
-
- final StringBuffer tagDataDeclarations = new StringBuffer();
- cu.accept(new DefaultJET2ASTVisitor() {
- private void writeDecl(XMLElement element) {
- tagDataDeclarations.append("final TagInfo ")
- .append(MethodBodyCreator.tagInfoVariableName(element))
- .append(" = new TagInfo( ")
- .append('"').append(element.getName()).append("\", ")
- .append(element.getLine()).append(", ")
- .append(element.getColumn()).append(", ")
- ;
- tagDataDeclarations.append(" new String[] {");
- for (Iterator i = element.getAttributes().keySet().iterator(); i.hasNext();) {
- String attrName = (String) i.next();
- tagDataDeclarations.append('"').append(attrName).append("\", ");
- }
- tagDataDeclarations.append("}, ");
- tagDataDeclarations.append(" new String[] {");
- for (Iterator i = element.getAttributes().values().iterator(); i.hasNext();) {
- String attrValue = (String) i.next();
- tagDataDeclarations.append(JavaUtil.asJavaQuotedString(attrValue.toCharArray())).append(", ");
- }
- tagDataDeclarations.append("});").append(NL);
- }
-
- public void visit(XMLBodyElement element) {
- writeDecl(element);
- }
-
- public void visit(XMLEmptyElement element) {
- writeDecl(element);
- }
- });
- MethodBodyCreator generatedBody = new MethodBodyCreator();
- cu.accept(generatedBody);
-%>
-package <%= cu.getOutputJavaPackage() %>;
-
-import org.eclipse.jet.JET2Context;
-import org.eclipse.jet.JET2Template;
-import org.eclipse.jet.JET2Writer;
-import org.eclipse.jet.taglib.RuntimeTagElement;
-import org.eclipse.jet.taglib.TagInfo;
-<% for(Iterator i=cu.getImports().iterator();i.hasNext();) {
- String importName = (String)i.next();%>
-import <%=importName%>;
-<% } %>
-
-public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
-
- <%= tagNamespaceVariables %>
-
- <%= declarations %>
-
- public <%= cu.getOutputJavaClassName() %>() {
- super();
- }
-
- public void generate(JET2Context context, JET2Writer out) {
-
- <%= tagDataDeclarations %>
-
- <%= generatedBody.getBuffer() %>
- }
-
-}
- \ No newline at end of file
diff --git a/plugins/org.eclipse.jet/templates/jet2java.jet b/plugins/org.eclipse.jet/templates/jet2java.jet
new file mode 100644
index 0000000..f0ac60e
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/jet2java.jet
@@ -0,0 +1,81 @@
+<%@jet package="org.eclipse.jet.internal.compiler.templates"
+ class="JET2JavaGenerator"
+ %>
+<%@jet imports="org.eclipse.jet.internal.compiler.*"%>
+<%@jet imports="org.eclipse.jet.compiler.*"%>
+<%@jet imports="org.eclipse.jet.transform.TransformContextExtender"%>
+<%@jet imports="org.eclipse.jet.taglib.TagLibraryReference"%>
+<%@jet imports="java.util.ArrayList"%>
+<%@jet imports="java.util.List"%>
+<%@jet imports="java.util.Iterator"%>
+<%!
+ private XMLElement[] getAllXMLTags(JET2CompilationUnit cu) {
+ final List result = new ArrayList();
+ cu.accept(new DefaultJET2ASTVisitor() {
+ public void visit(XMLBodyElement element) {
+ result.add(element);
+ }
+
+ public void visit(XMLEmptyElement element) {
+ result.add(element);
+ }
+ });
+ return (XMLElement[])result.toArray(new XMLElement[result.size()]);
+ }
+
+ private JET2Declaration[] getAllJavaDeclarations(JET2CompilationUnit cu) {
+ final List result = new ArrayList();
+ cu.accept(new DefaultJET2ASTVisitor() {
+ public void visit(JET2Declaration declaration) {
+ result.add(declaration);
+ }
+ });
+ return (JET2Declaration[])result.toArray(new JET2Declaration[result.size()]);
+ }
+%>
+<%
+ JET2CompilationUnit cu = (JET2CompilationUnit)context.getVariable("cu");
+
+ final JET2Declaration[] allMemberDeclarations = getAllJavaDeclarations(cu);
+ final XMLElement[] allXMLElements = getAllXMLTags(cu);
+
+ final StringBuffer tagNamespaceVariables = new StringBuffer();
+ final TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
+
+ MethodBodyCreator generatedBody = new MethodBodyCreator(TransformContextExtender.getInstance(context).getLoader());
+ cu.accept(generatedBody);
+%>
+package <%= cu.getOutputJavaPackage() %>;
+
+import org.eclipse.jet.JET2Context;
+import org.eclipse.jet.JET2Template;
+import org.eclipse.jet.JET2Writer;
+import org.eclipse.jet.taglib.RuntimeTagElement;
+import org.eclipse.jet.taglib.TagInfo;
+<% for(Iterator i=cu.getImports().iterator();i.hasNext();) {
+ String importName = (String)i.next();%>
+import <%=importName%>;
+<% } %>
+
+public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
+<% for(int i = 0; i < tlRefs.length; i++ ) { %>
+ public static final String _jetns_<%= tlRefs[i].getPrefix() %> = "<%= tlRefs[i].getTagLibraryId() %>"; //$NON-NLS-1$
+<% } %>
+<% for(int i = 0; i < allMemberDeclarations.length; i++) { %>
+
+<%= allMemberDeclarations[i].getJavaContent() %>
+<% } %>
+
+ public <%= cu.getOutputJavaClassName() %>() {
+ super();
+ }
+
+ public void generate(final JET2Context context, JET2Writer out) {
+<% for(int i = 0; i < allXMLElements.length; i++) {
+ context.setVariable("element", allXMLElements[i]); %>
+ <c:include template="templates/tagDataDeclarations.jet"/>
+<% } %>
+<%= generatedBody.getBuffer() %>
+ }
+
+}
diff --git a/plugins/org.eclipse.jet/templates/jet2transform.javajet b/plugins/org.eclipse.jet/templates/jet2transform.jet
index 77bdd59..4362b29 100644
--- a/plugins/org.eclipse.jet/templates/jet2transform.javajet
+++ b/plugins/org.eclipse.jet/templates/jet2transform.jet
@@ -1,9 +1,12 @@
<%@jet package="org.eclipse.jet.internal.compiler.templates"
- class="JET2TransformGenerator"
- imports="java.util.Map java.util.Iterator org.eclipse.jet.internal.compiler.LoaderGenerationParameters"
+ 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)argument;
+LoaderGenerationParameters parms = (LoaderGenerationParameters)context.getVariable("args");
Map templateMap = (Map) parms.getTemplateMap();;
%>
package <%= parms.getPackageName() %>;
@@ -35,7 +38,7 @@ public class <%= parms.getClassName() %> implements JET2TemplateLoader, JET2Temp
<% for(Iterator i = templateMap.entrySet().iterator(); i.hasNext();){
Map.Entry entry = (Map.Entry)i.next();
%>
- pathToFactoryMap.put("<%= entry.getKey() %>",
+ pathToFactoryMap.put("<%= entry.getKey() %>", //$NON-NLS-1$
new TemplateFactoryMethod() {
public JET2Template newTemplate() {
return new <%= entry.getValue() %>();
diff --git a/plugins/org.eclipse.jet/templates/main.jet b/plugins/org.eclipse.jet/templates/main.jet
new file mode 100644
index 0000000..9c22453
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/main.jet
@@ -0,0 +1,2 @@
+<%@jet class="DummyMain"%>
+<c:log>This transform in not intended to be run.</c:log>
diff --git a/plugins/org.eclipse.jet/templates/tagDataDeclarations.jet b/plugins/org.eclipse.jet/templates/tagDataDeclarations.jet
new file mode 100644
index 0000000..2e58db2
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/tagDataDeclarations.jet
@@ -0,0 +1,30 @@
+<%@jet class="TagDataDeclGenerator"%>
+<%@jet imports="java.util.Iterator"%>
+<%@jet imports="org.eclipse.jet.taglib.JET2TagException"%>
+<%@jet imports="org.eclipse.jet.compiler.XMLElement"%>
+<%@jet imports="org.eclipse.jet.internal.compiler.MethodBodyCreator"%>
+<%
+ XMLElement element;
+ try {
+ element = (XMLElement)context.getVariable("element");
+ } catch( JET2TagException e) {
+ out.write(e.toString());
+ return;
+ }
+
+ String varName = MethodBodyCreator.tagInfoVariableName(element);
+%>
+ final TagInfo <%= varName %> = new TagInfo("<%=element.getName()%>", //$NON-NLS-1$
+ <%= element.getLine() %>, <%= element.getColumn() %>,
+ new String[] {
+<% for (Iterator i = element.getAttributes().keySet().iterator(); i.hasNext();) {
+ String attrName = (String) i.next(); %>
+ "<%= attrName %>", //$NON-NLS-1$
+<% } %>
+ },
+ new String[] {
+<% for (Iterator i = element.getAttributes().values().iterator(); i.hasNext();) {
+ String attrValue = (String) i.next(); %>
+ "<%= attrValue %>", //$NON-NLS-1$
+<% } %>
+ } );
diff --git a/plugins/org.eclipse.jet/templates/writeJavaExpression.jet b/plugins/org.eclipse.jet/templates/writeJavaExpression.jet
new file mode 100644
index 0000000..54b1571
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/writeJavaExpression.jet
@@ -0,0 +1,7 @@
+<%@jet class="WriteJavaExpressionTemplate" %>
+<%@jet imports="org.eclipse.jet.compiler.JET2Expression"%>
+<%
+final String indent = (String)context.getVariable("indent"); //$NON-NLS-1$
+final JET2Expression expr = (JET2Expression)context.getVariable("element"); //$NON-NLS-1$
+%>
+<%= indent %>out.write(<%= expr.getJavaContent() %>);
diff --git a/plugins/org.eclipse.jet/templates/writeTextElement.jet b/plugins/org.eclipse.jet/templates/writeTextElement.jet
new file mode 100644
index 0000000..6ed7e53
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/writeTextElement.jet
@@ -0,0 +1,10 @@
+<%@jet class="WriteTextElementTemplate" %>
+<%@jet imports="org.eclipse.jet.compiler.TextElement"%>
+<%@jet imports="org.eclipse.jet.internal.JavaUtil"%>
+<%
+final String indent = (String)context.getVariable("indent"); //$NON-NLS-1$
+final TextElement text = (TextElement)context.getVariable("element"); //$NON-NLS-1$
+%>
+<% if(text.getText().length > 0) { %>
+<%= indent %>out.write( <%= JavaUtil.asJavaQuotedString(text.getText()) %> ); //$NON-NLS-1$
+<% } %>
diff --git a/plugins/org.eclipse.jet/templates/xmlEnd.javajet b/plugins/org.eclipse.jet/templates/xmlEnd.javajet
deleted file mode 100644
index e1a2d17..0000000
--- a/plugins/org.eclipse.jet/templates/xmlEnd.javajet
+++ /dev/null
@@ -1,15 +0,0 @@
-<%@jet package="org.eclipse.jet.internal.compiler.templates"
- class="XMLEndGenerator"
- imports="org.eclipse.jet.internal.compiler.*"
- %>
-<%
- GenXMLElement element = (GenXMLElement) argument;
-%>
-<% if(element.hasBody()) { %>
- <%= element.getTagVariable() %>.handleBodyContent(out);
- }
-<% if(element.requiresNewWriter()) { %>
- out = <%= element.getTagVariable() %>_saved_out;
-<% } %>
-<% } %>
- <%= element.getTagVariable() %>.doEnd();
diff --git a/plugins/org.eclipse.jet/templates/xmlEnd.jet b/plugins/org.eclipse.jet/templates/xmlEnd.jet
new file mode 100644
index 0000000..b1c5626
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/xmlEnd.jet
@@ -0,0 +1,13 @@
+<%@jet class="XMLEndGenerator" %>
+<%@jet imports="org.eclipse.jet.internal.compiler.GenXMLElement"%>
+<%
+ GenXMLElement element = (GenXMLElement) context.getVariable("element"); //$NON-NLS-1$
+%>
+<% if(element.hasBody()) { %>
+<c:get select="$indent"/> <%= element.getTagVariable() %>.handleBodyContent(out);
+<c:get select="$indent"/>}
+<% if(element.requiresNewWriter()) { %>
+<c:get select="$indent"/>out = <%= element.getTagVariable() %>_saved_out;
+<% } %>
+<% } %>
+<c:get select="$indent"/><%= element.getTagVariable() %>.doEnd();
diff --git a/plugins/org.eclipse.jet/templates/xmlStart.javajet b/plugins/org.eclipse.jet/templates/xmlStart.javajet
deleted file mode 100644
index 81fc10e..0000000
--- a/plugins/org.eclipse.jet/templates/xmlStart.javajet
+++ /dev/null
@@ -1,21 +0,0 @@
-<%@jet package="org.eclipse.jet.internal.compiler.templates"
- class="XMLStartGenerator"
- imports="org.eclipse.jet.internal.compiler.*"
- %>
-<%
- GenXMLElement element = (GenXMLElement) argument;
-%>
- RuntimeTagElement <%= element.getTagVariable() %> = context.getTagFactory().createRuntimeTag(_jetns_<%= element.getNSPrefix() %>, "<%= element.getTagNCName() %>", "<%= element.getName() %>", <%= element.getTagInfoVariable() %>);
- <%= element.getTagVariable() %>.setRuntimeParent(<%= element.getParentTagVariable() %>);
- <%= element.getTagVariable() %>.setTagInfo(<%= element.getTagInfoVariable() %>);
- <%= element.getTagVariable() %>.doStart(context, out);
-<% if(element.hasBody()) { %>
-<% if(element.requiresNewWriter()) { %>
- JET2Writer <%= element.getTagVariable() %>_saved_out = out;
-<% } %>
- while (<%= element.getTagVariable() %>.okToProcessBody()) {
-<% if(element.requiresNewWriter()) { %>
- out = out.newNestedContentWriter();
-<% } %>
-
-<% } %>
diff --git a/plugins/org.eclipse.jet/templates/xmlStart.jet b/plugins/org.eclipse.jet/templates/xmlStart.jet
new file mode 100644
index 0000000..c0fe1ba
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/xmlStart.jet
@@ -0,0 +1,18 @@
+<%@jet class="XMLStartGenerator" %>
+<%@jet imports="org.eclipse.jet.internal.compiler.GenXMLElement"%>
+<%
+ GenXMLElement element = (GenXMLElement) context.getVariable("element"); //$NON-NLS-1$
+%>
+<c:get select="$indent"/>RuntimeTagElement <%= element.getTagVariable() %> = context.getTagFactory().createRuntimeTag(_jetns_<%= element.getNSPrefix() %>, "<%= element.getTagNCName() %>", "<%= element.getName() %>", <%= element.getTagInfoVariable() %>);
+<c:get select="$indent"/><%= element.getTagVariable() %>.setRuntimeParent(<%= element.getParentTagVariable() %>);
+<c:get select="$indent"/><%= element.getTagVariable() %>.setTagInfo(<%= element.getTagInfoVariable() %>);
+<c:get select="$indent"/><%= element.getTagVariable() %>.doStart(context, out);
+<% if(element.hasBody()) { %>
+<% if(element.requiresNewWriter()) { %>
+<c:get select="$indent"/>JET2Writer <%= element.getTagVariable() %>_saved_out = out;
+<% } %>
+<c:get select="$indent"/>while (<%= element.getTagVariable() %>.okToProcessBody()) {
+<% if(element.requiresNewWriter()) { %>
+<c:get select="$indent"/> out = out.newNestedContentWriter();
+<% } %>
+<% } %>

Back to the top