Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.jet/templates/v2/jet2java.jet')
-rw-r--r--plugins/org.eclipse.jet/templates/v2/jet2java.jet68
1 files changed, 60 insertions, 8 deletions
diff --git a/plugins/org.eclipse.jet/templates/v2/jet2java.jet b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
index 167243b..03c3932 100644
--- a/plugins/org.eclipse.jet/templates/v2/jet2java.jet
+++ b/plugins/org.eclipse.jet/templates/v2/jet2java.jet
@@ -11,8 +11,10 @@
<%@jet imports="java.util.Iterator"%>
<%@jet imports="org.eclipse.jet.internal.JavaUtil"%>
<%
+ final boolean hcrFriendly = context.hasVariable("hcrFriendly") //$NON-NLS-1$
+ ? ((Boolean)context.getVariable("hcrFriendly")).booleanValue() : false; //$NON-NLS-1$
JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
- TagUsageVisitor tuv = new TagUsageVisitor();
+ final TagUsageVisitor tuv = new TagUsageVisitor();
cu.accept(tuv);
TagLibraryReference[] tlrefs = tuv.getUsedTagLibraryReferences(cu);
Arrays.sort(tlrefs, new Comparator() {
@@ -66,9 +68,11 @@ import <%= (String)i.next() %>;
});
%>
public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
-<% for(int i = 0; i < tlrefs.length; i++ ) { %>
+<% if(!hcrFriendly) {
+ for(int i = 0; i < tlrefs.length; i++ ) { %>
private static final String _jetns_<%= tlrefs[i].getPrefix() %> = "<%= tlrefs[i].getTagLibraryId() %>"; //$NON-NLS-1$
-<% } %>
+<% }
+ } %>
<% cu.accept(new V2CodeGenVisitor(context,out) {
public boolean visit(JavaDeclaration decl) {
@@ -87,7 +91,7 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
private static final String <%=nlConstantName%> = System.getProperty("line.separator"); //$NON-NLS-1$
<% } %>
-<% if(tuv.hasTags()) { %>
+<% if(tuv.hasTags() && !hcrFriendly) { %>
<% cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
public boolean visit(XMLBodyElement e) {
@@ -116,8 +120,56 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
<% }
}); %>
<% } %>
+<% if(tuv.hasTags() && hcrFriendly) { %>
+
+ private TagInfo[] _init_tagInfo() {
+<% if(tuv.hasAttributelessTags()) { %>
+ final String[] EMPTY_STRING_ARRAY = new String[0];
+<% } %>
+ return new TagInfo[] {
+<% cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
+ public boolean visit(XMLBodyElement e) {
+ doElementVisit(e);
+ return true;
+ }
+ public boolean visit(XMLEmptyElement e) {
+ doElementVisit(e);
+ return true;
+ }
+ public void doElementVisit(XMLElement e) {
+%>
+ new TagInfo("<%=e.getName()%>", //$NON-NLS-1$
+ <%= e.getLine() %>, <%= e.getColumn() %>,
+<% if(e.getAttributes().size() > 0) { %>
+ new String[] {
+<% for (Iterator i = e.getAttributes().keySet().iterator(); i.hasNext();) { %>
+ "<%= (String) i.next() %>", //$NON-NLS-1$
+<% } %>
+ },
+ new String[] {
+<% for (Iterator i = e.getAttributes().values().iterator(); i.hasNext();) {
+ String attrValue = (String) i.next(); %>
+ "<%= JavaUtil.escapeJavaString(attrValue.toCharArray()) %>", //$NON-NLS-1$
+<% } %>
+ } ),
+<% } else { %>
+ EMPTY_STRING_ARRAY, EMPTY_STRING_ARRAY ),
+<% } %>
+<% }
+ }); %>
+ };
+ }
+<% } %>
public void generate(final JET2Context context, final JET2Writer __out) {
+<% if(hcrFriendly) {
+ for(int i = 0; i < tlrefs.length; i++ ) { %>
+ final String _jetns_<%= tlrefs[i].getPrefix() %> = "<%= tlrefs[i].getTagLibraryId() %>"; //$NON-NLS-1$
+<% }
+ if(tuv.hasTags()) { %>
+ final TagInfo[] _td_ = _init_tagInfo();
+<% }
+ } %>
JET2Writer out = __out;
<% cu.accept(new V2CodeGenVisitor(context,out, " ") { //$NON-NLS-1$
public boolean visit(TextElement text) {
@@ -146,9 +198,9 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
}
public boolean visit(XMLBodyElement e) {
%>
- RuntimeTagElement <%= tagVar(e) %> = context.getTagFactory().createRuntimeTag(_jetns_<%= e.getNSPrefix() %>, "<%= e.getTagNCName() %>", "<%= e.getName() %>", _td_<%= tagInfoVar(e) %>); //$NON-NLS-1$ //$NON-NLS-2$
+ RuntimeTagElement <%= tagVar(e) %> = context.getTagFactory().createRuntimeTag(_jetns_<%= e.getNSPrefix() %>, "<%= e.getTagNCName() %>", "<%= e.getName() %>", _td_<%= hcrFriendly ? tuv.ordinalExpr(e) : tagInfoVar(e) %>); //$NON-NLS-1$ //$NON-NLS-2$
<%= tagVar(e) %>.setRuntimeParent(<%= parentTagVar(e) %>);
- <%= tagVar(e) %>.setTagInfo(_td_<%= tagInfoVar(e) %>);
+ <%= tagVar(e) %>.setTagInfo(_td_<%= hcrFriendly ? tuv.ordinalExpr(e) : tagInfoVar(e) %>);
<%= tagVar(e) %>.doStart(context, out);
<% if(requiresOwnWriter(e)) { %>
JET2Writer <%= tagVar(e) %>_saved_out = out;
@@ -175,9 +227,9 @@ public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
}
public boolean visit(XMLEmptyElement e) {
%>
- RuntimeTagElement <%= tagVar(e) %> = context.getTagFactory().createRuntimeTag(_jetns_<%= e.getNSPrefix() %>, "<%= e.getTagNCName() %>", "<%= e.getName() %>", _td_<%= tagInfoVar(e) %>); //$NON-NLS-1$ //$NON-NLS-2$
+ RuntimeTagElement <%= tagVar(e) %> = context.getTagFactory().createRuntimeTag(_jetns_<%= e.getNSPrefix() %>, "<%= e.getTagNCName() %>", "<%= e.getName() %>", _td_<%= hcrFriendly ? tuv.ordinalExpr(e) : tagInfoVar(e) %>); //$NON-NLS-1$ //$NON-NLS-2$
<%= tagVar(e) %>.setRuntimeParent(<%= parentTagVar(e) %>);
- <%= tagVar(e) %>.setTagInfo(_td_<%= tagInfoVar(e) %>);
+ <%= tagVar(e) %>.setTagInfo(_td_<%= hcrFriendly ? tuv.ordinalExpr(e) : tagInfoVar(e) %>);
<%= tagVar(e) %>.doStart(context, out);
<%= tagVar(e) %>.doEnd();
<%

Back to the top