8281376: Consider polymorphic methods when looking for overrides

Reviewed-by: hannesw
This commit is contained in:
Pavel Rappo 2022-02-23 16:17:23 +00:00
parent 340a35d835
commit 35076af13a
5 changed files with 226 additions and 5 deletions
src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit
test/langtools/jdk/javadoc/doclet/testOverriddenMethods

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -221,8 +221,7 @@ public class WorkArounds {
if (sym.overrides(sym2, origin, javacTypes, true)) {
// Ignore those methods that may be a simple override
// and allow the real API method to be found.
if (sym2.type.hasTag(TypeTag.METHOD) &&
utils.isSimpleOverride((MethodSymbol)sym2)) {
if (utils.isSimpleOverride((MethodSymbol)sym2)) {
continue;
}
return t;

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
/*
* @test
* @bug 8157000 8192850 8182765 8223607 8261976
* @bug 8157000 8192850 8182765 8223607 8261976 8281376
* @summary test the behavior of --override-methods option
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@ -569,4 +569,93 @@ public class TestOverrideMethods extends JavadocTester {
<dd>something</dd>
</dl>""");
}
@Test
public void testPolymorphicDetail() {
javadoc("-d", "out-polymorphic-detail",
"-sourcepath", testSrc,
"--override-methods=detail",
"pkg8");
checkExit(Exit.OK);
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="P.html#m1()">m1</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="P.html#m2()">m2</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="P.html#m3()">m3</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
}
@Test // results should be the same as that of "detail"
public void testPolymorphicDefault() {
javadoc("-d", "out-polymorphic-default",
"-sourcepath", testSrc,
"pkg8");
checkExit(Exit.OK);
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="P.html#m1()">m1</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="P.html#m2()">m2</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="P.html#m3()">m3</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
}
@Test
public void testPolymorphicSummary() {
javadoc("-d", "out-polymorphic-summary",
"-sourcepath", testSrc,
"--override-methods=summary",
"pkg8");
checkExit(Exit.OK);
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="GP.html#m1()">m1</a></code>&nbsp;in class&nbsp;\
<code><a href="GP.html" title="class in pkg8">GP</a></code></dd>""");
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="GP.html#m2()">m2</a></code>&nbsp;in class&nbsp;\
<code><a href="GP.html" title="class in pkg8">GP</a></code></dd>""");
checkOutput("pkg8/C.html", true,
"""
<dt>Overrides:</dt>
<dd><code><a href="GP.html#m3()">m3</a></code>&nbsp;in class&nbsp;\
<code><a href="GP.html" title="class in pkg8">GP</a></code></dd>""");
checkOutput("pkg8/C.html", false,
"""
<dt>Overrides:</dt>
<dd><code><a href="GP.html#m1()">m1</a></code>&nbsp;in class&nbsp;\
<code><a href="P.html" title="class in pkg8">P</a></code></dd>""");
}
}

@ -0,0 +1,47 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg8;
public class C extends P {
/**
* Child m1().
*
* @param <T> Child m1's type
*/
@Override
public <T> void m1() {}
/**
* Child m2().
*/
@Override
public void m2() {}
/**
* Child m3().
*/
@Override
public void m3() {}
}

@ -0,0 +1,48 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg8;
public class GP {
/**
* Grandparent m1().
*
* @param <T> Grandparent m1's type
*/
public <T> void m1() {}
/**
* Grandparent m2().
*
* @param <T> Grandparent m2's type
*/
public <T> void m2() {}
/**
* Grandparent m3().
*
* @param <T> Grandparent m3's type
*/
public <T> void m3() {}
}

@ -0,0 +1,38 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package pkg8;
public class P extends GP {
// note that while m1() and m2() are parameterized, m3() is not
@Override
public <T> void m1() {}
@Override
public <T> void m2() {}
@Override
public void m3() {}
}