Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-02-24 19:04:37 +0000
committerpelder2006-02-24 19:04:37 +0000
commit79d9bb81ecd0f91b46087d61dac630f0d1bd6ddb (patch)
treebfc015c550698ce797976cd8dfd79df6b0222903 /plugins/org.eclipse.jet/templates
downloadorg.eclipse.jet-79d9bb81ecd0f91b46087d61dac630f0d1bd6ddb.tar.gz
org.eclipse.jet-79d9bb81ecd0f91b46087d61dac630f0d1bd6ddb.tar.xz
org.eclipse.jet-79d9bb81ecd0f91b46087d61dac630f0d1bd6ddb.zip
Initial commit
Diffstat (limited to 'plugins/org.eclipse.jet/templates')
-rw-r--r--plugins/org.eclipse.jet/templates/jet2java.javajet92
-rw-r--r--plugins/org.eclipse.jet/templates/jet2transform.javajet47
-rw-r--r--plugins/org.eclipse.jet/templates/xmlEnd.javajet15
-rw-r--r--plugins/org.eclipse.jet/templates/xmlStart.javajet21
4 files changed, 175 insertions, 0 deletions
diff --git a/plugins/org.eclipse.jet/templates/jet2java.javajet b/plugins/org.eclipse.jet/templates/jet2java.javajet
new file mode 100644
index 0000000..703129d
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/jet2java.javajet
@@ -0,0 +1,92 @@
+<%@jet package="org.eclipse.jet.internal.compiler.templates"
+ class="JET2JavaGenerator"
+ imports="org.eclipse.jet.internal.compiler.* org.eclipse.jet.compiler.* 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();
+ cu.accept(new DefaultJET2ASTVisitor() {
+ public void visit(JET2Directive directive) {
+ if("taglib".equals(directive.getName())) {
+ tagNamespaceVariables.append("public static final String _jetns_")
+ .append(directive.getAttributes().get("prefix"))
+ .append(" = \"")
+ .append(directive.getAttributes().get("id"))
+ .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.getStart()).append(", ")
+ .append(element.getEnd()).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(MethodBodyCreator.encodeJavaString(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;
+
+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/jet2transform.javajet b/plugins/org.eclipse.jet/templates/jet2transform.javajet
new file mode 100644
index 0000000..c29f539
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/jet2transform.javajet
@@ -0,0 +1,47 @@
+<%@jet package="org.eclipse.jet.internal.compiler.templates"
+ class="JET2TransformGenerator"
+ imports="java.util.Map java.util.Iterator"
+ %>
+<%
+Map templateMap = (Map) argument;
+%>
+package org.eclipse.jet.compiled;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jet.JET2TemplateLoader;
+import org.eclipse.jet.JET2Template;
+
+public class _jet_transformation implements JET2TemplateLoader {
+
+ private interface TemplateFactoryMethod {
+ public abstract JET2Template newTemplate();
+ }
+
+ private Map pathToFactoryMap = null;
+
+ public _jet_transformation() {
+ 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() %>",
+ new TemplateFactoryMethod() {
+ public JET2Template newTemplate() {
+ return new <%= entry.getValue() %>();
+ }
+ });
+<% } %>
+ }
+ TemplateFactoryMethod factory = (TemplateFactoryMethod)pathToFactoryMap.get(templatePath);
+ return factory == null ? null : factory.newTemplate();
+ }
+
+}
+
diff --git a/plugins/org.eclipse.jet/templates/xmlEnd.javajet b/plugins/org.eclipse.jet/templates/xmlEnd.javajet
new file mode 100644
index 0000000..e1a2d17
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/xmlEnd.javajet
@@ -0,0 +1,15 @@
+<%@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/xmlStart.javajet b/plugins/org.eclipse.jet/templates/xmlStart.javajet
new file mode 100644
index 0000000..81fc10e
--- /dev/null
+++ b/plugins/org.eclipse.jet/templates/xmlStart.javajet
@@ -0,0 +1,21 @@
+<%@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();
+<% } %>
+
+<% } %>

Back to the top