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