|
1 /* |
|
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package com.sun.tools.javac.tree; |
|
27 |
|
28 import com.sun.source.doctree.AttributeTree.ValueKind; |
|
29 import com.sun.source.doctree.DocTree.Kind; |
|
30 |
|
31 import com.sun.tools.javac.parser.Tokens.Comment; |
|
32 import com.sun.tools.javac.tree.DCTree.*; |
|
33 import com.sun.tools.javac.util.Context; |
|
34 import com.sun.tools.javac.util.DiagnosticSource; |
|
35 import com.sun.tools.javac.util.JCDiagnostic; |
|
36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
37 import com.sun.tools.javac.util.List; |
|
38 import com.sun.tools.javac.util.Name; |
|
39 import com.sun.tools.javac.util.Position; |
|
40 |
|
41 /** |
|
42 * |
|
43 * <p><b>This is NOT part of any supported API. |
|
44 * If you write code that depends on this, you do so at your own risk. |
|
45 * This code and its internal interfaces are subject to change or |
|
46 * deletion without notice.</b> |
|
47 */ |
|
48 public class DocTreeMaker { |
|
49 |
|
50 /** The context key for the tree factory. */ |
|
51 protected static final Context.Key<DocTreeMaker> treeMakerKey = |
|
52 new Context.Key<DocTreeMaker>(); |
|
53 |
|
54 /** Get the TreeMaker instance. */ |
|
55 public static DocTreeMaker instance(Context context) { |
|
56 DocTreeMaker instance = context.get(treeMakerKey); |
|
57 if (instance == null) |
|
58 instance = new DocTreeMaker(context); |
|
59 return instance; |
|
60 } |
|
61 |
|
62 /** The position at which subsequent trees will be created. |
|
63 */ |
|
64 public int pos = Position.NOPOS; |
|
65 |
|
66 /** Access to diag factory for ErroneousTrees. */ |
|
67 private final JCDiagnostic.Factory diags; |
|
68 |
|
69 /** Create a tree maker with NOPOS as initial position. |
|
70 */ |
|
71 protected DocTreeMaker(Context context) { |
|
72 context.put(treeMakerKey, this); |
|
73 diags = JCDiagnostic.Factory.instance(context); |
|
74 this.pos = Position.NOPOS; |
|
75 } |
|
76 |
|
77 /** Reassign current position. |
|
78 */ |
|
79 public DocTreeMaker at(int pos) { |
|
80 this.pos = pos; |
|
81 return this; |
|
82 } |
|
83 |
|
84 /** Reassign current position. |
|
85 */ |
|
86 public DocTreeMaker at(DiagnosticPosition pos) { |
|
87 this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); |
|
88 return this; |
|
89 } |
|
90 |
|
91 public DCAttribute Attribute(Name name, ValueKind vkind, List<DCTree> value) { |
|
92 DCAttribute tree = new DCAttribute(name, vkind, value); |
|
93 tree.pos = pos; |
|
94 return tree; |
|
95 } |
|
96 |
|
97 public DCAuthor Author(List<DCTree> name) { |
|
98 DCAuthor tree = new DCAuthor(name); |
|
99 tree.pos = pos; |
|
100 return tree; |
|
101 } |
|
102 |
|
103 public DCLiteral Code(DCText text) { |
|
104 DCLiteral tree = new DCLiteral(Kind.CODE, text); |
|
105 tree.pos = pos; |
|
106 return tree; |
|
107 } |
|
108 |
|
109 public DCComment Comment(String text) { |
|
110 DCComment tree = new DCComment(text); |
|
111 tree.pos = pos; |
|
112 return tree; |
|
113 } |
|
114 |
|
115 public DCDeprecated Deprecated(List<DCTree> text) { |
|
116 DCDeprecated tree = new DCDeprecated(text); |
|
117 tree.pos = pos; |
|
118 return tree; |
|
119 } |
|
120 |
|
121 public DCDocComment DocComment(Comment comment, List<DCTree> firstSentence, List<DCTree> body, List<DCTree> tags) { |
|
122 DCDocComment tree = new DCDocComment(comment, firstSentence, body, tags); |
|
123 tree.pos = pos; |
|
124 return tree; |
|
125 } |
|
126 |
|
127 public DCDocRoot DocRoot() { |
|
128 DCDocRoot tree = new DCDocRoot(); |
|
129 tree.pos = pos; |
|
130 return tree; |
|
131 } |
|
132 |
|
133 public DCEndElement EndElement(Name name) { |
|
134 DCEndElement tree = new DCEndElement(name); |
|
135 tree.pos = pos; |
|
136 return tree; |
|
137 } |
|
138 |
|
139 public DCEntity Entity(Name name) { |
|
140 DCEntity tree = new DCEntity(name); |
|
141 tree.pos = pos; |
|
142 return tree; |
|
143 } |
|
144 |
|
145 public DCErroneous Erroneous(String text, DiagnosticSource diagSource, String code, Object... args) { |
|
146 DCErroneous tree = new DCErroneous(text, diags, diagSource, code, args); |
|
147 tree.pos = pos; |
|
148 return tree; |
|
149 } |
|
150 |
|
151 public DCThrows Exception(DCReference name, List<DCTree> description) { |
|
152 DCThrows tree = new DCThrows(Kind.EXCEPTION, name, description); |
|
153 tree.pos = pos; |
|
154 return tree; |
|
155 } |
|
156 |
|
157 public DCIdentifier Identifier(Name name) { |
|
158 DCIdentifier tree = new DCIdentifier(name); |
|
159 tree.pos = pos; |
|
160 return tree; |
|
161 } |
|
162 |
|
163 public DCInheritDoc InheritDoc() { |
|
164 DCInheritDoc tree = new DCInheritDoc(); |
|
165 tree.pos = pos; |
|
166 return tree; |
|
167 } |
|
168 |
|
169 public DCLink Link(DCReference ref, List<DCTree> label) { |
|
170 DCLink tree = new DCLink(Kind.LINK, ref, label); |
|
171 tree.pos = pos; |
|
172 return tree; |
|
173 } |
|
174 |
|
175 public DCLink LinkPlain(DCReference ref, List<DCTree> label) { |
|
176 DCLink tree = new DCLink(Kind.LINK_PLAIN, ref, label); |
|
177 tree.pos = pos; |
|
178 return tree; |
|
179 } |
|
180 |
|
181 public DCLiteral Literal(DCText text) { |
|
182 DCLiteral tree = new DCLiteral(Kind.LITERAL, text); |
|
183 tree.pos = pos; |
|
184 return tree; |
|
185 } |
|
186 |
|
187 public DCParam Param(boolean isTypeParameter, DCIdentifier name, List<DCTree> description) { |
|
188 DCParam tree = new DCParam(isTypeParameter, name, description); |
|
189 tree.pos = pos; |
|
190 return tree; |
|
191 } |
|
192 |
|
193 public DCReference Reference(String signature, |
|
194 JCTree qualExpr, Name member, List<JCTree> paramTypes) { |
|
195 DCReference tree = new DCReference(signature, qualExpr, member, paramTypes); |
|
196 tree.pos = pos; |
|
197 return tree; |
|
198 } |
|
199 |
|
200 public DCReturn Return(List<DCTree> description) { |
|
201 DCReturn tree = new DCReturn(description); |
|
202 tree.pos = pos; |
|
203 return tree; |
|
204 } |
|
205 |
|
206 public DCSee See(List<DCTree> reference) { |
|
207 DCSee tree = new DCSee(reference); |
|
208 tree.pos = pos; |
|
209 return tree; |
|
210 } |
|
211 |
|
212 public DCSerial Serial(List<DCTree> description) { |
|
213 DCSerial tree = new DCSerial(description); |
|
214 tree.pos = pos; |
|
215 return tree; |
|
216 } |
|
217 |
|
218 public DCSerialData SerialData(List<DCTree> description) { |
|
219 DCSerialData tree = new DCSerialData(description); |
|
220 tree.pos = pos; |
|
221 return tree; |
|
222 } |
|
223 |
|
224 public DCSerialField SerialField(DCIdentifier name, DCReference type, List<DCTree> description) { |
|
225 DCSerialField tree = new DCSerialField(name, type, description); |
|
226 tree.pos = pos; |
|
227 return tree; |
|
228 } |
|
229 |
|
230 public DCSince Since(List<DCTree> text) { |
|
231 DCSince tree = new DCSince(text); |
|
232 tree.pos = pos; |
|
233 return tree; |
|
234 } |
|
235 |
|
236 public DCStartElement StartElement(Name name, List<DCTree> attrs, boolean selfClosing) { |
|
237 DCStartElement tree = new DCStartElement(name, attrs, selfClosing); |
|
238 tree.pos = pos; |
|
239 return tree; |
|
240 } |
|
241 |
|
242 public DCText Text(String text) { |
|
243 DCText tree = new DCText(text); |
|
244 tree.pos = pos; |
|
245 return tree; |
|
246 } |
|
247 |
|
248 public DCThrows Throws(DCReference name, List<DCTree> description) { |
|
249 DCThrows tree = new DCThrows(Kind.THROWS, name, description); |
|
250 tree.pos = pos; |
|
251 return tree; |
|
252 } |
|
253 |
|
254 public DCUnknownBlockTag UnknownBlockTag(Name name, List<DCTree> content) { |
|
255 DCUnknownBlockTag tree = new DCUnknownBlockTag(name, content); |
|
256 tree.pos = pos; |
|
257 return tree; |
|
258 } |
|
259 |
|
260 public DCUnknownInlineTag UnknownInlineTag(Name name, List<DCTree> content) { |
|
261 DCUnknownInlineTag tree = new DCUnknownInlineTag(name, content); |
|
262 tree.pos = pos; |
|
263 return tree; |
|
264 } |
|
265 |
|
266 public DCValue Value(DCReference ref) { |
|
267 DCValue tree = new DCValue(ref); |
|
268 tree.pos = pos; |
|
269 return tree; |
|
270 } |
|
271 |
|
272 public DCVersion Version(List<DCTree> text) { |
|
273 DCVersion tree = new DCVersion(text); |
|
274 tree.pos = pos; |
|
275 return tree; |
|
276 } |
|
277 } |