summaryrefslogtreecommitdiffstats
blob: b69d33178c3accdc702f5a95a43e5ade94d151b9 (plain)
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
<%@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.*"%>
<%@jet imports="org.eclipse.jface.text.Position"%>
<%!
    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()]);
    }
    
    private void adjustGeneratedBodyPositions(Map mappingPositions, int generatedBodyOffsetStart) {
	    for (Iterator iterator = mappingPositions.keySet().iterator(); iterator.hasNext();) {
	      Object element = iterator.next();
	      if (!(element instanceof JET2Declaration)) {
	        Position position = (Position) mappingPositions.get(element);
	        position.offset += generatedBodyOffsetStart;
	      }
	    }
	}
%>
<%
	JET2CompilationUnit cu = (JET2CompilationUnit) context.getVariable("cu");
    JET2Declaration allMemberDeclarations[] = getAllJavaDeclarations(cu);
    XMLElement allXMLElements[] = getAllXMLTags(cu);
    TagLibraryReference tlRefs[] = cu.getTagLibraryReferences();
    Map generatedBodyMappingPositions = new HashMap();
    Map mappingPositions = (Map) context.getVariable("org.eclipse.jet.storeJavaMappingPositions");
    org.eclipse.jet.internal.editor.JETEditorHelper.JETEditorMethodBodyCreator generatedBody = new org.eclipse.jet.internal.editor.JETEditorHelper.JETEditorMethodBodyCreator(
        TransformContextExtender.getInstance(context).getLoader(), generatedBodyMappingPositions);
    cu.accept(generatedBody);
%>
package <%= cu.getOutputJavaPackage() %>;

import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
<% if( allXMLElements.length > 0) { %>
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 {
<% if( allXMLElements.length > 0) { %>
<%    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]); //$NON-NLS-1$
%>
			<c:include template="templates/tagDataDeclarations.jet"/>
<%  } %>
<%= generatedBody.getBuffer() %>
	}

}