44 import javax.lang.model.element.VariableElement;
45 import javax.lang.model.type.TypeMirror;
46 import javax.lang.model.util.Elements;
47 import javax.tools.FileObject;
48 import javax.tools.JavaFileManager.Location;
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;
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;
61 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
62 import com.sun.tools.javac.code.Symbol.PackageSymbol;
63 import com.sun.tools.javac.code.Symbol.VarSymbol;
64 import com.sun.tools.javac.comp.AttrContext;
65 import com.sun.tools.javac.comp.Env;
66 import com.sun.tools.javac.model.JavacElements;
67 import com.sun.tools.javac.model.JavacTypes;
68 import com.sun.tools.javac.util.Names;
69
70 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
71 import jdk.javadoc.internal.tool.ToolEnvironment;
72 import jdk.javadoc.internal.tool.DocEnvImpl;
73
74 import static com.sun.tools.javac.code.Kinds.Kind.*;
75 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
76
77 import static javax.lang.model.element.ElementKind.*;
78
79 /**
80 * A quarantine class to isolate all the workarounds and bridges to
81 * a locality. This class should eventually disappear once all the
82 * standard APIs support the needed interfaces.
83 *
266
267 return null; // not found
268 }
269
270 // TODO: need to re-implement this using j.l.m. correctly!, this has
271 // implications on testInterface, the note here is that javac's supertype
272 // does the right thing returning Parameters in scope.
273 /**
274 * Return the type containing the method that this method overrides.
275 * It may be a <code>TypeElement</code> or a <code>TypeParameterElement</code>.
276 * @param method target
277 * @return a type
278 */
279 public TypeMirror overriddenType(ExecutableElement method) {
280 if (utils.isStatic(method)) {
281 return null;
282 }
283 MethodSymbol sym = (MethodSymbol)method;
284 ClassSymbol origin = (ClassSymbol) sym.owner;
285 for (com.sun.tools.javac.code.Type t = toolEnv.getTypes().supertype(origin.type);
286 t.hasTag(com.sun.tools.javac.code.TypeTag.CLASS);
287 t = toolEnv.getTypes().supertype(t)) {
288 ClassSymbol c = (ClassSymbol) t.tsym;
289 for (com.sun.tools.javac.code.Symbol sym2 : c.members().getSymbolsByName(sym.name)) {
290 if (sym.overrides(sym2, origin, toolEnv.getTypes(), true)) {
291 return t;
292 }
293 }
294 }
295 return null;
296 }
297
298 // TODO: the method jx.l.m.Elements::overrides does not check
299 // the return type, see JDK-8174840 until that is resolved,
300 // use a copy of the same method, with a return type check.
301
302 // Note: the rider.overrides call in this method *must* be consistent
303 // with the call in overrideType(....), the method above.
304 public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement cls) {
305 MethodSymbol rider = (MethodSymbol)e1;
306 MethodSymbol ridee = (MethodSymbol)e2;
307 ClassSymbol origin = (ClassSymbol)cls;
308
309 return rider.name == ridee.name &&
310
|
44 import javax.lang.model.element.VariableElement;
45 import javax.lang.model.type.TypeMirror;
46 import javax.lang.model.util.Elements;
47 import javax.tools.FileObject;
48 import javax.tools.JavaFileManager.Location;
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;
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;
61 import com.sun.tools.javac.code.Symbol.ModuleSymbol;
62 import com.sun.tools.javac.code.Symbol.PackageSymbol;
63 import com.sun.tools.javac.code.Symbol.VarSymbol;
64 import com.sun.tools.javac.code.TypeTag;
65 import com.sun.tools.javac.comp.AttrContext;
66 import com.sun.tools.javac.comp.Env;
67 import com.sun.tools.javac.model.JavacElements;
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;
72 import jdk.javadoc.internal.tool.ToolEnvironment;
73 import jdk.javadoc.internal.tool.DocEnvImpl;
74
75 import static com.sun.tools.javac.code.Kinds.Kind.*;
76 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
77
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 *
267
268 return null; // not found
269 }
270
271 // TODO: need to re-implement this using j.l.m. correctly!, this has
272 // implications on testInterface, the note here is that javac's supertype
273 // does the right thing returning Parameters in scope.
274 /**
275 * Return the type containing the method that this method overrides.
276 * It may be a <code>TypeElement</code> or a <code>TypeParameterElement</code>.
277 * @param method target
278 * @return a type
279 */
280 public TypeMirror overriddenType(ExecutableElement method) {
281 if (utils.isStatic(method)) {
282 return null;
283 }
284 MethodSymbol sym = (MethodSymbol)method;
285 ClassSymbol origin = (ClassSymbol) sym.owner;
286 for (com.sun.tools.javac.code.Type t = toolEnv.getTypes().supertype(origin.type);
287 t.hasTag(TypeTag.CLASS);
288 t = toolEnv.getTypes().supertype(t)) {
289 ClassSymbol c = (ClassSymbol) t.tsym;
290 for (com.sun.tools.javac.code.Symbol sym2 : c.members().getSymbolsByName(sym.name)) {
291 if (sym.overrides(sym2, origin, toolEnv.getTypes(), true)) {
292 // Ignore those methods that may be a simple overridden
293 // and allow the real API method to be found.
294 if (sym2.type.hasTag(TypeTag.METHOD) &&
295 utils.isSimpleOverride((MethodSymbol)sym2)) {
296 continue;
297 }
298 return t;
299 }
300 }
301 }
302 return null;
303 }
304
305 // TODO: the method jx.l.m.Elements::overrides does not check
306 // the return type, see JDK-8174840 until that is resolved,
307 // use a copy of the same method, with a return type check.
308
309 // Note: the rider.overrides call in this method *must* be consistent
310 // with the call in overrideType(....), the method above.
311 public boolean overrides(ExecutableElement e1, ExecutableElement e2, TypeElement cls) {
312 MethodSymbol rider = (MethodSymbol)e1;
313 MethodSymbol ridee = (MethodSymbol)e2;
314 ClassSymbol origin = (ClassSymbol)cls;
315
316 return rider.name == ridee.name &&
317
|