Skip to content

Commit

Permalink
8281376: Consider polymorphic methods when looking for overrides
Browse files Browse the repository at this point in the history
Reviewed-by: hannesw
  • Loading branch information
pavelrappo committed Feb 23, 2022
1 parent 340a35d commit 35076af
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -221,8 +221,7 @@ public TypeMirror overriddenType(ExecutableElement method) {
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -569,4 +569,93 @@ n interface in pkg7">@A</a> java.lang.CharSequence&gt;&nbsp;p1,
<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>""");
}
}
Original file line number Diff line number Diff line change
@@ -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() {}
}
Original file line number Diff line number Diff line change
@@ -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() {}
}
Original file line number Diff line number Diff line change
@@ -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() {}
}

1 comment on commit 35076af

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.