Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.compiler/share/classes/com/sun/source/util/DocTrees.java
41175 views
1
/*
2
* Copyright (c) 2011, 2020, 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.source.util;
27
28
import java.io.IOException;
29
import java.text.BreakIterator;
30
import java.util.List;
31
32
import javax.annotation.processing.ProcessingEnvironment;
33
import javax.lang.model.element.Element;
34
import javax.lang.model.element.PackageElement;
35
import javax.lang.model.type.TypeMirror;
36
import javax.tools.Diagnostic;
37
import javax.tools.FileObject;
38
import javax.tools.JavaCompiler.CompilationTask;
39
40
import com.sun.source.doctree.DocCommentTree;
41
import com.sun.source.doctree.DocTree;
42
import com.sun.source.doctree.EntityTree;
43
import com.sun.source.tree.CompilationUnitTree;
44
45
/**
46
* Provides access to syntax trees for doc comments.
47
*
48
* @since 1.8
49
*/
50
public abstract class DocTrees extends Trees {
51
/**
52
* Constructor for subclasses to call.
53
*/
54
public DocTrees() {}
55
56
/**
57
* Returns a DocTrees object for a given CompilationTask.
58
* @param task the compilation task for which to get the Trees object
59
* @return the DocTrees object
60
* @throws IllegalArgumentException if the task does not support the Trees API.
61
*/
62
public static DocTrees instance(CompilationTask task) {
63
return (DocTrees) Trees.instance(task);
64
}
65
66
/**
67
* Returns a DocTrees object for a given ProcessingEnvironment.
68
* @param env the processing environment for which to get the Trees object
69
* @return the DocTrees object
70
* @throws IllegalArgumentException if the env does not support the Trees API.
71
*/
72
public static DocTrees instance(ProcessingEnvironment env) {
73
if (!env.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment"))
74
throw new IllegalArgumentException();
75
return (DocTrees) getJavacTrees(ProcessingEnvironment.class, env);
76
}
77
78
/**
79
* Returns the break iterator used to compute the first sentence of
80
* documentation comments.
81
* Returns {@code null} if none has been specified.
82
* @return the break iterator
83
*
84
* @since 9
85
*/
86
public abstract BreakIterator getBreakIterator();
87
88
/**
89
* Returns the doc comment tree, if any, for the Tree node identified by a given TreePath.
90
* Returns {@code null} if no doc comment was found.
91
* @param path the path for the tree node
92
* @return the doc comment tree
93
*/
94
public abstract DocCommentTree getDocCommentTree(TreePath path);
95
96
/**
97
* Returns the doc comment tree of the given element.
98
* Returns {@code null} if no doc comment was found.
99
* @param e an element whose documentation is required
100
* @return the doc comment tree
101
*
102
* @since 9
103
*/
104
public abstract DocCommentTree getDocCommentTree(Element e);
105
106
/**
107
* Returns the doc comment tree of the given file. The file must be
108
* an HTML file, in which case the doc comment tree represents the
109
* entire contents of the file.
110
* Returns {@code null} if no doc comment was found.
111
* Future releases may support additional file types.
112
*
113
* @param fileObject the content container
114
* @return the doc comment tree
115
* @since 9
116
*/
117
public abstract DocCommentTree getDocCommentTree(FileObject fileObject);
118
119
/**
120
* Returns the doc comment tree of the given file whose path is
121
* specified relative to the given element. The file must be an HTML
122
* file, in which case the doc comment tree represents the contents
123
* of the <body> tag, and any enclosing tags are ignored.
124
* Returns {@code null} if no doc comment was found.
125
* Future releases may support additional file types.
126
*
127
* @param e an element whose path is used as a reference
128
* @param relativePath the relative path from the Element
129
* @return the doc comment tree
130
* @throws java.io.IOException if an exception occurs
131
*
132
* @since 9
133
*/
134
public abstract DocCommentTree getDocCommentTree(Element e, String relativePath) throws IOException;
135
136
/**
137
* Returns a doc tree path containing the doc comment tree of the given file.
138
* The file must be an HTML file, in which case the doc comment tree represents
139
* the contents of the {@code <body>} tag, and any enclosing tags are ignored.
140
* Any references to source code elements contained in {@code @see} and
141
* {@code {@link}} tags in the doc comment tree will be evaluated in the
142
* context of the given package element.
143
* Returns {@code null} if no doc comment was found.
144
*
145
* @param fileObject a file object encapsulating the HTML content
146
* @param packageElement a package element to associate with the given file object
147
* representing a legacy package.html, null otherwise
148
* @return a doc tree path containing the doc comment parsed from the given file
149
* @throws IllegalArgumentException if the fileObject is not an HTML file
150
*
151
* @since 9
152
*/
153
public abstract DocTreePath getDocTreePath(FileObject fileObject, PackageElement packageElement);
154
155
/**
156
* Returns the language model element referred to by the leaf node of the given
157
* {@link DocTreePath}, or {@code null} if unknown.
158
* @param path the path for the tree node
159
* @return the element
160
*/
161
public abstract Element getElement(DocTreePath path);
162
163
/**
164
* Returns the language model type referred to by the leaf node of the given
165
* {@link DocTreePath}, or {@code null} if unknown. This method usually
166
* returns the same value as {@code getElement(path).asType()} for a
167
* {@code path} argument for which {@link #getElement(DocTreePath)} returns
168
* a non-null value, but may return a type that includes additional
169
* information, such as a parameterized generic type instead of a raw type.
170
*
171
* @param path the path for the tree node
172
* @return the referenced type, or null
173
*
174
* @since 15
175
*/
176
public abstract TypeMirror getType(DocTreePath path);
177
178
/**
179
* Returns the list of {@link DocTree} representing the first sentence of
180
* a comment.
181
*
182
* @param list the DocTree list to interrogate
183
* @return the first sentence
184
*
185
* @since 9
186
*/
187
public abstract List<DocTree> getFirstSentence(List<? extends DocTree> list);
188
189
/**
190
* Returns a utility object for accessing the source positions
191
* of documentation tree nodes.
192
* @return the utility object
193
*/
194
public abstract DocSourcePositions getSourcePositions();
195
196
/**
197
* Prints a message of the specified kind at the location of the
198
* tree within the provided compilation unit
199
*
200
* @param kind the kind of message
201
* @param msg the message, or an empty string if none
202
* @param t the tree to use as a position hint
203
* @param c the doc comment tree to use as a position hint
204
* @param root the compilation unit that contains tree
205
*/
206
public abstract void printMessage(Diagnostic.Kind kind, CharSequence msg,
207
DocTree t, DocCommentTree c, CompilationUnitTree root);
208
209
/**
210
* Sets the break iterator to compute the first sentence of
211
* documentation comments.
212
* @param breakIterator a break iterator or {@code null} to specify the default
213
* sentence breaker
214
*
215
* @since 9
216
*/
217
public abstract void setBreakIterator(BreakIterator breakIterator);
218
219
/**
220
* Returns a utility object for creating {@code DocTree} objects.
221
* @return a utility object for creating {@code DocTree} objects
222
*
223
* @since 9
224
*/
225
public abstract DocTreeFactory getDocTreeFactory();
226
227
/**
228
* Returns a string containing the characters for the entity in a given entity tree,
229
* or {@code null} if the tree does not represent a valid series of characters.
230
*
231
* <p>The interpretation of entities is based on section
232
* <a href="https://www.w3.org/TR/html52/syntax.html#character-references">8.1.4. Character references</a>
233
* in the HTML 5.2 specification.</p>
234
*
235
* @param tree the tree containing the entity
236
* @return a string containing the characters
237
*/
238
public abstract String getCharacters(EntityTree tree);
239
}
240
241