author | jjg |
Mon, 21 Oct 2019 13:25:36 -0700 | |
changeset 58727 | fa1f838b5486 |
parent 54135 | 67f72165dca5 |
permissions | -rw-r--r-- |
35426 | 1 |
/* |
54135 | 2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
35426 | 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 jdk.javadoc.internal.doclets.toolkit; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Arrays; |
|
30 |
import java.util.Collection; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.List; |
|
33 |
import java.util.Map; |
|
34 |
import java.util.SortedSet; |
|
35 |
import java.util.TreeSet; |
|
36 |
||
37 |
import javax.lang.model.element.AnnotationMirror; |
|
38 |
import javax.lang.model.element.Element; |
|
39 |
import javax.lang.model.element.ExecutableElement; |
|
36526 | 40 |
import javax.lang.model.element.ModuleElement; |
35426 | 41 |
import javax.lang.model.element.PackageElement; |
42 |
import javax.lang.model.element.TypeElement; |
|
43 |
import javax.lang.model.element.VariableElement; |
|
44 |
import javax.lang.model.type.TypeMirror; |
|
45 |
import javax.lang.model.util.Elements; |
|
43265
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
46 |
import javax.tools.FileObject; |
40605
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
47 |
import javax.tools.JavaFileManager.Location; |
35426 | 48 |
|
49 |
import com.sun.source.tree.CompilationUnitTree; |
|
50 |
import com.sun.source.util.JavacTask; |
|
51 |
import com.sun.source.util.TreePath; |
|
52 |
import com.sun.tools.doclint.DocLint; |
|
53 |
import com.sun.tools.javac.api.BasicJavacTask; |
|
54 |
import com.sun.tools.javac.code.Attribute; |
|
55 |
import com.sun.tools.javac.code.Flags; |
|
56 |
import com.sun.tools.javac.code.Scope; |
|
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47988
diff
changeset
|
57 |
import com.sun.tools.javac.code.Source.Feature; |
35426 | 58 |
import com.sun.tools.javac.code.Symbol; |
59 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
|
60 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
|
40605
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
61 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
43265
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
62 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
35426 | 63 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
47395
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
64 |
import com.sun.tools.javac.code.TypeTag; |
35426 | 65 |
import com.sun.tools.javac.comp.AttrContext; |
66 |
import com.sun.tools.javac.comp.Env; |
|
36526 | 67 |
import com.sun.tools.javac.model.JavacElements; |
35426 | 68 |
import com.sun.tools.javac.model.JavacTypes; |
69 |
import com.sun.tools.javac.util.Names; |
|
70 |
||
71 |
import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
72 |
import jdk.javadoc.internal.tool.ToolEnvironment; |
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
73 |
import jdk.javadoc.internal.tool.DocEnvImpl; |
35426 | 74 |
|
75 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
|
76 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
|
36526 | 77 |
|
35426 | 78 |
import static javax.lang.model.element.ElementKind.*; |
79 |
||
80 |
/** |
|
81 |
* A quarantine class to isolate all the workarounds and bridges to |
|
82 |
* a locality. This class should eventually disappear once all the |
|
83 |
* standard APIs support the needed interfaces. |
|
84 |
* |
|
85 |
* |
|
86 |
* <p><b>This is NOT part of any supported API. |
|
87 |
* If you write code that depends on this, you do so at your own risk. |
|
88 |
* This code and its internal interfaces are subject to change or |
|
89 |
* deletion without notice.</b> |
|
90 |
*/ |
|
91 |
public class WorkArounds { |
|
92 |
||
45417 | 93 |
public final BaseConfiguration configuration; |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
94 |
public final ToolEnvironment toolEnv; |
35426 | 95 |
public final Utils utils; |
96 |
||
97 |
private DocLint doclint; |
|
98 |
||
45417 | 99 |
public WorkArounds(BaseConfiguration configuration) { |
35426 | 100 |
this.configuration = configuration; |
101 |
this.utils = this.configuration.utils; |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
102 |
this.toolEnv = ((DocEnvImpl)this.configuration.docEnv).toolEnv; |
35426 | 103 |
} |
104 |
||
105 |
Map<CompilationUnitTree, Boolean> shouldCheck = new HashMap<>(); |
|
106 |
// TODO: fix this up correctly |
|
107 |
public void runDocLint(TreePath path) { |
|
108 |
CompilationUnitTree unit = path.getCompilationUnit(); |
|
109 |
if (doclint != null && shouldCheck.computeIfAbsent(unit, doclint::shouldCheck)) { |
|
110 |
doclint.scan(path); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
// TODO: fix this up correctly |
|
54051 | 115 |
public void initDocLint(Collection<String> opts, Collection<String> customTagNames) { |
35426 | 116 |
ArrayList<String> doclintOpts = new ArrayList<>(); |
117 |
boolean msgOptionSeen = false; |
|
118 |
||
119 |
for (String opt : opts) { |
|
120 |
if (opt.startsWith(DocLint.XMSGS_OPTION)) { |
|
121 |
if (opt.equals(DocLint.XMSGS_CUSTOM_PREFIX + "none")) |
|
122 |
return; |
|
123 |
msgOptionSeen = true; |
|
124 |
} |
|
125 |
doclintOpts.add(opt); |
|
126 |
} |
|
127 |
||
128 |
if (!msgOptionSeen) { |
|
129 |
doclintOpts.add(DocLint.XMSGS_OPTION); |
|
130 |
} |
|
131 |
||
132 |
String sep = ""; |
|
133 |
StringBuilder customTags = new StringBuilder(); |
|
134 |
for (String customTag : customTagNames) { |
|
135 |
customTags.append(sep); |
|
136 |
customTags.append(customTag); |
|
137 |
sep = DocLint.SEPARATOR; |
|
138 |
} |
|
139 |
doclintOpts.add(DocLint.XCUSTOM_TAGS_PREFIX + customTags.toString()); |
|
54051 | 140 |
doclintOpts.add(DocLint.XHTML_VERSION_PREFIX + "html5"); |
35426 | 141 |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
142 |
JavacTask t = BasicJavacTask.instance(toolEnv.context); |
35426 | 143 |
doclint = new DocLint(); |
144 |
doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); |
|
145 |
} |
|
146 |
||
147 |
// TODO: fix this up correctly |
|
148 |
public boolean haveDocLint() { |
|
149 |
return (doclint == null); |
|
150 |
} |
|
151 |
||
152 |
/* |
|
153 |
* TODO: This method exists because of a bug in javac which does not |
|
154 |
* handle "@deprecated tag in package-info.java", when this issue |
|
155 |
* is fixed this method and its uses must be jettisoned. |
|
156 |
*/ |
|
157 |
public boolean isDeprecated0(Element e) { |
|
158 |
if (!utils.getDeprecatedTrees(e).isEmpty()) { |
|
159 |
return true; |
|
160 |
} |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
161 |
JavacTypes jctypes = ((DocEnvImpl)configuration.docEnv).toolEnv.typeutils; |
35426 | 162 |
TypeMirror deprecatedType = utils.getDeprecatedType(); |
163 |
for (AnnotationMirror anno : e.getAnnotationMirrors()) { |
|
164 |
if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), deprecatedType)) |
|
165 |
return true; |
|
166 |
} |
|
167 |
return false; |
|
168 |
} |
|
169 |
||
170 |
// TODO: fix jx.l.m add this method. |
|
171 |
public boolean isSynthesized(AnnotationMirror aDesc) { |
|
172 |
return ((Attribute)aDesc).isSynthesized(); |
|
173 |
} |
|
174 |
||
175 |
// TODO: fix the caller |
|
176 |
public Object getConstValue(VariableElement ve) { |
|
177 |
return ((VarSymbol)ve).getConstValue(); |
|
178 |
} |
|
179 |
||
43265
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
180 |
// TODO: DocTrees: Trees.getPath(Element e) is slow a factor 4-5 times. |
35426 | 181 |
public Map<Element, TreePath> getElementToTreePath() { |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
182 |
return toolEnv.elementToTreePath; |
35426 | 183 |
} |
184 |
||
43265
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
185 |
// TODO: we need ElementUtils.getPackage to cope with input strings |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
186 |
// to return the proper unnamedPackage for all supported releases. |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
187 |
PackageElement getUnnamedPackage() { |
48054
702043a4cdeb
8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents:
47988
diff
changeset
|
188 |
return (Feature.MODULES.allowedInSource(toolEnv.source)) |
43265
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
189 |
? toolEnv.syms.unnamedModule.unnamedPackage |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
190 |
: toolEnv.syms.noModule.unnamedPackage; |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
191 |
} |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
192 |
|
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
193 |
// TODO: implement in either jx.l.m API (preferred) or DocletEnvironment. |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
194 |
FileObject getJavaFileObject(PackageElement packageElement) { |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
195 |
return ((PackageSymbol)packageElement).sourcefile; |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
196 |
} |
4ec472ee5135
8169608: Compiler Tree API's Doctrees.getDocTreePath needs to accept a PackageElement
ksrini
parents:
42277
diff
changeset
|
197 |
|
35426 | 198 |
// TODO: needs to ported to jx.l.m. |
199 |
public TypeElement searchClass(TypeElement klass, String className) { |
|
49917
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
200 |
TypeElement te; |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
201 |
|
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
202 |
// search by qualified name in current module first |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
203 |
ModuleElement me = utils.containingModule(klass); |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
204 |
if (me != null) { |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
205 |
te = configuration.docEnv.getElementUtils().getTypeElement(me, className); |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
206 |
if (te != null) { |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
207 |
return te; |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
208 |
} |
35426 | 209 |
} |
210 |
||
211 |
// search inner classes |
|
212 |
for (TypeElement ite : utils.getClasses(klass)) { |
|
213 |
TypeElement innerClass = searchClass(ite, className); |
|
214 |
if (innerClass != null) { |
|
215 |
return innerClass; |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
// check in this package |
|
220 |
te = utils.findClassInPackageElement(utils.containingPackage(klass), className); |
|
221 |
if (te != null) { |
|
222 |
return te; |
|
223 |
} |
|
224 |
||
225 |
ClassSymbol tsym = (ClassSymbol)klass; |
|
226 |
// make sure that this symbol has been completed |
|
227 |
// TODO: do we need this anymore ? |
|
228 |
if (tsym.completer != null) { |
|
229 |
tsym.complete(); |
|
230 |
} |
|
231 |
||
232 |
// search imports |
|
233 |
if (tsym.sourcefile != null) { |
|
234 |
||
235 |
//### This information is available only for source classes. |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
236 |
Env<AttrContext> compenv = toolEnv.getEnv(tsym); |
35426 | 237 |
if (compenv == null) { |
238 |
return null; |
|
239 |
} |
|
240 |
Names names = tsym.name.table.names; |
|
241 |
Scope s = compenv.toplevel.namedImportScope; |
|
242 |
for (Symbol sym : s.getSymbolsByName(names.fromString(className))) { |
|
243 |
if (sym.kind == TYP) { |
|
244 |
return (TypeElement)sym; |
|
245 |
} |
|
246 |
} |
|
247 |
||
248 |
s = compenv.toplevel.starImportScope; |
|
249 |
for (Symbol sym : s.getSymbolsByName(names.fromString(className))) { |
|
250 |
if (sym.kind == TYP) { |
|
251 |
return (TypeElement)sym; |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
||
49917
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
256 |
// finally, search by qualified name in all modules |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
257 |
te = configuration.docEnv.getElementUtils().getTypeElement(className); |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
258 |
if (te != null) { |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
259 |
return te; |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
260 |
} |
1871c5d07caf
8201622: Reduce unnecessary Package.complete() calls in javadoc
jjg
parents:
48054
diff
changeset
|
261 |
|
35426 | 262 |
return null; // not found |
263 |
} |
|
264 |
||
265 |
// TODO: need to re-implement this using j.l.m. correctly!, this has |
|
266 |
// implications on testInterface, the note here is that javac's supertype |
|
267 |
// does the right thing returning Parameters in scope. |
|
268 |
/** |
|
269 |
* Return the type containing the method that this method overrides. |
|
270 |
* It may be a <code>TypeElement</code> or a <code>TypeParameterElement</code>. |
|
271 |
* @param method target |
|
272 |
* @return a type |
|
273 |
*/ |
|
274 |
public TypeMirror overriddenType(ExecutableElement method) { |
|
275 |
if (utils.isStatic(method)) { |
|
276 |
return null; |
|
277 |
} |
|
278 |
MethodSymbol sym = (MethodSymbol)method; |
|
279 |
ClassSymbol origin = (ClassSymbol) sym.owner; |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
280 |
for (com.sun.tools.javac.code.Type t = toolEnv.getTypes().supertype(origin.type); |
47395
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
281 |
t.hasTag(TypeTag.CLASS); |
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
282 |
t = toolEnv.getTypes().supertype(t)) { |
35426 | 283 |
ClassSymbol c = (ClassSymbol) t.tsym; |
284 |
for (com.sun.tools.javac.code.Symbol sym2 : c.members().getSymbolsByName(sym.name)) { |
|
39364
bd6d4a7936b4
8160301: javadoc RootDoclmpl and DocEnv needs to be renamed
ksrini
parents:
36526
diff
changeset
|
285 |
if (sym.overrides(sym2, origin, toolEnv.getTypes(), true)) { |
47395
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
286 |
// Ignore those methods that may be a simple override |
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
287 |
// and allow the real API method to be found. |
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
288 |
if (sym2.type.hasTag(TypeTag.METHOD) && |
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
289 |
utils.isSimpleOverride((MethodSymbol)sym2)) { |
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
290 |
continue; |
2ea4edfdef8e
8157000: Do not generate javadoc for overridden method with no spec change
ksrini
parents:
47216
diff
changeset
|
291 |
} |
35426 | 292 |
return t; |
293 |
} |
|
294 |
} |
|
295 |
} |
|
296 |
return null; |
|
297 |
} |
|
298 |
||
43872
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
299 |
// TODO: the method jx.l.m.Elements::overrides does not check |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
300 |
// the return type, see JDK-8174840 until that is resolved, |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
301 |
// use a copy of the same method, with a return type check. |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
302 |
|
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
303 |
// Note: the rider.overrides call in this method *must* be consistent |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
304 |
// with the call in overrideType(....), the method above. |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
305 |
public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement cls) { |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
306 |
MethodSymbol rider = (MethodSymbol)e1; |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
307 |
MethodSymbol ridee = (MethodSymbol)e2; |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
308 |
ClassSymbol origin = (ClassSymbol)cls; |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
309 |
|
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
310 |
return rider.name == ridee.name && |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
311 |
|
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
312 |
// not reflexive as per JLS |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
313 |
rider != ridee && |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
314 |
|
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
315 |
// we don't care if ridee is static, though that wouldn't |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
316 |
// compile |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
317 |
!rider.isStatic() && |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
318 |
|
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
319 |
// Symbol.overrides assumes the following |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
320 |
ridee.isMemberOf(origin, toolEnv.getTypes()) && |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
321 |
|
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
322 |
// check access, signatures and check return types |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
323 |
rider.overrides(ridee, origin, toolEnv.getTypes(), true); |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
324 |
} |
b5ce3bc28931
8174839: javadoc crashes with a method which does not override a super.
ksrini
parents:
43265
diff
changeset
|
325 |
|
40605
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
326 |
// TODO: jx.l.m ? |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
327 |
public Location getLocationForModule(ModuleElement mdle) { |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
328 |
ModuleSymbol msym = (ModuleSymbol)mdle; |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
329 |
return msym.sourceLocation != null |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
330 |
? msym.sourceLocation |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
331 |
: msym.classLocation; |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
332 |
} |
926c13175b67
8157349: Missing doc-files in javadoc documentation
ksrini
parents:
40508
diff
changeset
|
333 |
|
35426 | 334 |
//------------------Start of Serializable Implementation---------------------// |
58727 | 335 |
private final Map<TypeElement, NewSerializedForm> serializedForms = new HashMap<>(); |
35426 | 336 |
|
58727 | 337 |
private NewSerializedForm getSerializedForm(TypeElement typeElem) { |
338 |
return serializedForms.computeIfAbsent(typeElem, |
|
339 |
te -> new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), te)); |
|
35426 | 340 |
} |
341 |
||
58727 | 342 |
public SortedSet<VariableElement> getSerializableFields(TypeElement typeElem) { |
343 |
return getSerializedForm(typeElem).fields; |
|
35426 | 344 |
} |
345 |
||
58727 | 346 |
public SortedSet<ExecutableElement> getSerializationMethods(TypeElement typeElem) { |
347 |
return getSerializedForm(typeElem).methods; |
|
348 |
} |
|
349 |
||
350 |
public boolean definesSerializableFields(TypeElement typeElem) { |
|
351 |
if (!utils.isSerializable(typeElem) || utils.isExternalizable(typeElem)) { |
|
35426 | 352 |
return false; |
353 |
} else { |
|
58727 | 354 |
return getSerializedForm(typeElem).definesSerializableFields; |
35426 | 355 |
} |
356 |
} |
|
357 |
||
358 |
/* TODO we need a clean port to jx.l.m |
|
359 |
* The serialized form is the specification of a class' serialization state. |
|
360 |
* <p> |
|
361 |
* |
|
362 |
* It consists of the following information: |
|
363 |
* <p> |
|
364 |
* |
|
365 |
* <pre> |
|
366 |
* 1. Whether class is Serializable or Externalizable. |
|
367 |
* 2. Javadoc for serialization methods. |
|
368 |
* a. For Serializable, the optional readObject, writeObject, |
|
369 |
* readResolve and writeReplace. |
|
370 |
* serialData tag describes, in prose, the sequence and type |
|
371 |
* of optional data written by writeObject. |
|
372 |
* b. For Externalizable, writeExternal and readExternal. |
|
373 |
* serialData tag describes, in prose, the sequence and type |
|
374 |
* of optional data written by writeExternal. |
|
375 |
* 3. Javadoc for serialization data layout. |
|
376 |
* a. For Serializable, the name,type and description |
|
377 |
* of each Serializable fields. |
|
378 |
* b. For Externalizable, data layout is described by 2(b). |
|
379 |
* </pre> |
|
380 |
* |
|
381 |
*/ |
|
382 |
static class NewSerializedForm { |
|
383 |
||
384 |
final Utils utils; |
|
385 |
final Elements elements; |
|
386 |
||
387 |
final SortedSet<ExecutableElement> methods; |
|
388 |
||
389 |
/* List of FieldDocImpl - Serializable fields. |
|
390 |
* Singleton list if class defines Serializable fields explicitly. |
|
391 |
* Otherwise, list of default serializable fields. |
|
392 |
* 0 length list for Externalizable. |
|
393 |
*/ |
|
394 |
final SortedSet<VariableElement> fields; |
|
395 |
||
396 |
/* True if class specifies serializable fields explicitly. |
|
397 |
* using special static member, serialPersistentFields. |
|
398 |
*/ |
|
399 |
boolean definesSerializableFields = false; |
|
400 |
||
401 |
// Specially treated field/method names defined by Serialization. |
|
402 |
private static final String SERIALIZABLE_FIELDS = "serialPersistentFields"; |
|
403 |
private static final String READOBJECT = "readObject"; |
|
404 |
private static final String WRITEOBJECT = "writeObject"; |
|
405 |
private static final String READRESOLVE = "readResolve"; |
|
406 |
private static final String WRITEREPLACE = "writeReplace"; |
|
407 |
private static final String READOBJECTNODATA = "readObjectNoData"; |
|
408 |
||
409 |
NewSerializedForm(Utils utils, Elements elements, TypeElement te) { |
|
410 |
this.utils = utils; |
|
411 |
this.elements = elements; |
|
412 |
methods = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
413 |
fields = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
414 |
if (utils.isExternalizable(te)) { |
|
415 |
/* look up required public accessible methods, |
|
416 |
* writeExternal and readExternal. |
|
417 |
*/ |
|
418 |
String[] readExternalParamArr = {"java.io.ObjectInput"}; |
|
419 |
String[] writeExternalParamArr = {"java.io.ObjectOutput"}; |
|
420 |
||
421 |
ExecutableElement md = findMethod(te, "readExternal", Arrays.asList(readExternalParamArr)); |
|
422 |
if (md != null) { |
|
423 |
methods.add(md); |
|
424 |
} |
|
425 |
md = findMethod((ClassSymbol) te, "writeExternal", Arrays.asList(writeExternalParamArr)); |
|
426 |
if (md != null) { |
|
427 |
methods.add(md); |
|
428 |
} |
|
429 |
} else if (utils.isSerializable(te)) { |
|
430 |
VarSymbol dsf = getDefinedSerializableFields((ClassSymbol) te); |
|
431 |
if (dsf != null) { |
|
432 |
/* Define serializable fields with array of ObjectStreamField. |
|
433 |
* Each ObjectStreamField should be documented by a |
|
434 |
* serialField tag. |
|
435 |
*/ |
|
436 |
definesSerializableFields = true; |
|
437 |
fields.add((VariableElement) dsf); |
|
438 |
} else { |
|
439 |
||
440 |
/* Calculate default Serializable fields as all |
|
441 |
* non-transient, non-static fields. |
|
442 |
* Fields should be documented by serial tag. |
|
443 |
*/ |
|
444 |
computeDefaultSerializableFields((ClassSymbol) te); |
|
445 |
} |
|
446 |
||
447 |
/* Check for optional customized readObject, writeObject, |
|
448 |
* readResolve and writeReplace, which can all contain |
|
449 |
* the serialData tag. */ |
|
450 |
addMethodIfExist((ClassSymbol) te, READOBJECT); |
|
451 |
addMethodIfExist((ClassSymbol) te, WRITEOBJECT); |
|
452 |
addMethodIfExist((ClassSymbol) te, READRESOLVE); |
|
453 |
addMethodIfExist((ClassSymbol) te, WRITEREPLACE); |
|
454 |
addMethodIfExist((ClassSymbol) te, READOBJECTNODATA); |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
private VarSymbol getDefinedSerializableFields(ClassSymbol def) { |
|
459 |
Names names = def.name.table.names; |
|
460 |
||
461 |
/* SERIALIZABLE_FIELDS can be private, |
|
462 |
*/ |
|
463 |
for (Symbol sym : def.members().getSymbolsByName(names.fromString(SERIALIZABLE_FIELDS))) { |
|
464 |
if (sym.kind == VAR) { |
|
465 |
VarSymbol f = (VarSymbol) sym; |
|
466 |
if ((f.flags() & Flags.STATIC) != 0 |
|
467 |
&& (f.flags() & Flags.PRIVATE) != 0) { |
|
468 |
return f; |
|
469 |
} |
|
470 |
} |
|
471 |
} |
|
472 |
return null; |
|
473 |
} |
|
474 |
||
475 |
/* |
|
476 |
* Catalog Serializable method if it exists in current ClassSymbol. |
|
477 |
* Do not look for method in superclasses. |
|
478 |
* |
|
479 |
* Serialization requires these methods to be non-static. |
|
480 |
* |
|
481 |
* @param method should be an unqualified Serializable method |
|
482 |
* name either READOBJECT, WRITEOBJECT, READRESOLVE |
|
483 |
* or WRITEREPLACE. |
|
484 |
* @param visibility the visibility flag for the given method. |
|
485 |
*/ |
|
486 |
private void addMethodIfExist(ClassSymbol def, String methodName) { |
|
487 |
Names names = def.name.table.names; |
|
488 |
||
489 |
for (Symbol sym : def.members().getSymbolsByName(names.fromString(methodName))) { |
|
490 |
if (sym.kind == MTH) { |
|
491 |
MethodSymbol md = (MethodSymbol) sym; |
|
492 |
if ((md.flags() & Flags.STATIC) == 0) { |
|
493 |
/* |
|
494 |
* WARNING: not robust if unqualifiedMethodName is overloaded |
|
495 |
* method. Signature checking could make more robust. |
|
496 |
* READOBJECT takes a single parameter, java.io.ObjectInputStream. |
|
497 |
* WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream. |
|
498 |
*/ |
|
499 |
methods.add(md); |
|
500 |
} |
|
501 |
} |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
/* |
|
506 |
* Compute default Serializable fields from all members of ClassSymbol. |
|
507 |
* |
|
508 |
* must walk over all members of ClassSymbol. |
|
509 |
*/ |
|
510 |
private void computeDefaultSerializableFields(ClassSymbol te) { |
|
511 |
for (Symbol sym : te.members().getSymbols(NON_RECURSIVE)) { |
|
512 |
if (sym != null && sym.kind == VAR) { |
|
513 |
VarSymbol f = (VarSymbol) sym; |
|
514 |
if ((f.flags() & Flags.STATIC) == 0 |
|
515 |
&& (f.flags() & Flags.TRANSIENT) == 0) { |
|
516 |
//### No modifier filtering applied here. |
|
517 |
//### Add to beginning. |
|
518 |
//### Preserve order used by old 'javadoc'. |
|
519 |
fields.add(f); |
|
520 |
} |
|
521 |
} |
|
522 |
} |
|
523 |
} |
|
524 |
||
525 |
/** |
|
526 |
* Find a method in this class scope. Search order: this class, interfaces, superclasses, |
|
527 |
* outerclasses. Note that this is not necessarily what the compiler would do! |
|
528 |
* |
|
529 |
* @param methodName the unqualified name to search for. |
|
530 |
* @param paramTypes the array of Strings for method parameter types. |
|
531 |
* @return the first MethodDocImpl which matches, null if not found. |
|
532 |
*/ |
|
533 |
public ExecutableElement findMethod(TypeElement te, String methodName, |
|
534 |
List<String> paramTypes) { |
|
535 |
List<? extends Element> allMembers = this.elements.getAllMembers(te); |
|
536 |
loop: |
|
537 |
for (Element e : allMembers) { |
|
538 |
if (e.getKind() != METHOD) { |
|
539 |
continue; |
|
540 |
} |
|
541 |
ExecutableElement ee = (ExecutableElement) e; |
|
542 |
if (!ee.getSimpleName().contentEquals(methodName)) { |
|
543 |
continue; |
|
544 |
} |
|
545 |
List<? extends VariableElement> parameters = ee.getParameters(); |
|
546 |
if (paramTypes.size() != parameters.size()) { |
|
547 |
continue; |
|
548 |
} |
|
549 |
for (int i = 0; i < parameters.size(); i++) { |
|
550 |
VariableElement ve = parameters.get(i); |
|
551 |
if (!ve.asType().toString().equals(paramTypes.get(i))) { |
|
552 |
break loop; |
|
553 |
} |
|
554 |
} |
|
555 |
return ee; |
|
556 |
} |
|
557 |
TypeElement encl = utils.getEnclosingTypeElement(te); |
|
558 |
if (encl == null) { |
|
559 |
return null; |
|
560 |
} |
|
561 |
return findMethod(encl, methodName, paramTypes); |
|
562 |
} |
|
563 |
} |
|
564 |
||
36526 | 565 |
// TODO: we need to eliminate this, as it is hacky. |
566 |
/** |
|
567 |
* Returns a representation of the package truncated to two levels. |
|
568 |
* For instance if the given package represents foo.bar.baz will return |
|
569 |
* a representation of foo.bar |
|
570 |
* @param pkg the PackageElement |
|
571 |
* @return an abbreviated PackageElement |
|
572 |
*/ |
|
573 |
public PackageElement getAbbreviatedPackageElement(PackageElement pkg) { |
|
574 |
String parsedPackageName = utils.parsePackageName(pkg); |
|
575 |
ModuleElement encl = (ModuleElement) pkg.getEnclosingElement(); |
|
576 |
PackageElement abbrevPkg = encl == null |
|
577 |
? utils.elementUtils.getPackageElement(parsedPackageName) |
|
578 |
: ((JavacElements) utils.elementUtils).getPackageElement(encl, parsedPackageName); |
|
579 |
return abbrevPkg; |
|
580 |
} |
|
35426 | 581 |
} |