Skip to main content
summaryrefslogtreecommitdiffstats
blob: 167243bd1f264d6d673da172f6adcb3969e90842 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<%@jet package="org.eclipse.jet.internal.compiler.templates.v2" 
               class="JET2JavaGeneratorNew" 
               %>
<%@jet imports="org.eclipse.jet.core.parser.ast.*"%>
<%@jet imports="org.eclipse.jet.internal.compiler.V2CodeGenVisitor"%>
<%@jet imports="org.eclipse.jet.internal.compiler.HasNewlinesUtil"%>
<%@jet imports="org.eclipse.jet.internal.compiler.TagUsageVisitor"%>
<%@jet imports="org.eclipse.jet.taglib.TagLibraryReference"%>
<%@jet imports="java.util.Arrays"%>
<%@jet imports="java.util.Comparator"%>
<%@jet imports="java.util.Iterator"%>
<%@jet imports="org.eclipse.jet.internal.JavaUtil"%>
<%
    JETCompilationUnit cu = (JETCompilationUnit)context.getVariable("cu"); //$NON-NLS-1$
    TagUsageVisitor tuv = new TagUsageVisitor();
    cu.accept(tuv);
    TagLibraryReference[] tlrefs = tuv.getUsedTagLibraryReferences(cu);
    Arrays.sort(tlrefs, new Comparator() {
       public int compare(Object o1, Object o2) {
          return ((TagLibraryReference)o1).getTagLibraryId().compareTo(((TagLibraryReference)o2).getTagLibraryId());
       }
    });
    final String nlConstantName = "NL"; //$NON-NLS-1$
%>
<%cu.accept(new V2CodeGenVisitor(context,out, "") { //$NON-NLS-1$ 
    public boolean visit(Comment comment) {
        final String text = comment.getCommentText();
        final String leadIn = " * "; //$NON-NLS-1$
        if(isHeaderComment(text)) {
%>
/*
<% out.write(formatComment(text, leadIn)) ;%>
 */
<%
        }
        return true;
    }
});
%>
package <%= cu.getOutputJavaPackage() %>;

import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
<% if(tuv.hasTags()) { %>
import org.eclipse.jet.taglib.RuntimeTagElement;
import org.eclipse.jet.taglib.TagInfo;
<% } %>
<% for(Iterator i=cu.getImports().iterator();i.hasNext();) { %>
import <%= (String)i.next() %>;
<% } %>

<%cu.accept(new V2CodeGenVisitor(context,out, "") { //$NON-NLS-1$ 
    public boolean visit(Comment comment) {
        final String text = comment.getCommentText();
        final String leadIn = " * "; //$NON-NLS-1$
        if(isClassComment(text)) {
%>
/**
<% out.write(formatComment(text, leadIn)) ;%>
 */
<%
        }
        return true;
    }
});
%>
public class <%= cu.getOutputJavaClassName() %> implements JET2Template {
<%    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) {
%>
    <% writeAndRecord(decl); %>

<%
        return true;
      }
   });
%>
    public <%= cu.getOutputJavaClassName() %>() {
        super();
    }
<% if(HasNewlinesUtil.test(cu)) { %>

    private static final String <%=nlConstantName%> = System.getProperty("line.separator"); //$NON-NLS-1$
<% } %>
<% if(tuv.hasTags()) { %>
    
<% 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) {
%>
    private static final TagInfo _td_<%= tagInfoVar(e) %> = new TagInfo("<%=e.getName()%>", //$NON-NLS-1$
            <%= e.getLine() %>, <%= e.getColumn() %>,
            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$
<%          } %>
            } );
<%    } 
   }); %>
<% } %>

    public void generate(final JET2Context context, final JET2Writer __out) {
        JET2Writer out = __out;
<% cu.accept(new V2CodeGenVisitor(context,out, "    ") { //$NON-NLS-1$
    public boolean visit(TextElement text) {
        if(text.getText().length > 0) {
            String[] strings = textConstants(text, nlConstantName);
            for(int i = 0; i < strings.length; i++) {
%>
        out.write(<%=strings[i]%>); <% if(strings[i].startsWith("\"")) { //$NON-NLS-1$ %> //$NON-NLS-1$<%}%>        
<%
            }
        }
        return true;
      }
      public boolean visit(JavaScriptlet scriptlet) {
%>
        <% writeAndRecord(scriptlet); %>

<%
          return true;
      }
      public boolean visit(JavaExpression expr) {
%>
        out.write(<% writeAndRecord(expr); %>);
<%
          return true;
  }
      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$
        <%= tagVar(e) %>.setRuntimeParent(<%= parentTagVar(e) %>);
        <%= tagVar(e) %>.setTagInfo(_td_<%= tagInfoVar(e) %>);
        <%= tagVar(e) %>.doStart(context, out);
<% if(requiresOwnWriter(e)) { %>
        JET2Writer <%= tagVar(e) %>_saved_out = out;
<% } %>
        while (<%= tagVar(e) %>.okToProcessBody()) {
<% if(requiresOwnWriter(e)) { %>
            out = out.newNestedContentWriter();
<% } %>
<%
          in();
          return true;
      }
      public void endVisit(XMLBodyElement e) {
          out();
%>
            <%= tagVar(e) %>.handleBodyContent(out);
        }
<% if(requiresOwnWriter(e)) { %>
        out = <%= tagVar(e) %>_saved_out;
<%  } %>
        <%= tagVar(e) %>.doEnd();
<%
 
      }
      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$
        <%= tagVar(e) %>.setRuntimeParent(<%= parentTagVar(e) %>);
        <%= tagVar(e) %>.setTagInfo(_td_<%= tagInfoVar(e) %>);
        <%= tagVar(e) %>.doStart(context, out);
        <%= tagVar(e) %>.doEnd();
<%
          return true;
      }
  %>
 <%
      public boolean visit(Comment comment) {
        final String text = comment.getCommentText();
        final String leadIn = "        //";  //$NON-NLS-1$
        if(isNormalComment(text)) {
			out.write(formatComment(text, leadIn)) ;
         }
          return true;
      }
  %>
<%
   });
%>
    }
}

Back to the top