# HG changeset patch # User mcimadamore # Date 1224848794 -3600 # Node ID e923a41e84cc2d513708a54f34ff6c9cd85ad703 # Parent 6a9a2f681d2436d95ffbdee80bbece6367382fd8 6758789: Some method resolution diagnostic should be improved Summary: Recent work on diagnostics left out some resolution corner cases Reviewed-by: jjg diff -r 6a9a2f681d24 -r e923a41e84cc langtools/src/share/classes/com/sun/tools/javac/api/Formattable.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/Formattable.java Fri Oct 24 12:46:07 2008 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/Formattable.java Fri Oct 24 12:46:34 2008 +0100 @@ -49,4 +49,23 @@ * @return a string representing the object's kind */ String getKind(); + + static class LocalizedString implements Formattable { + String key; + + public LocalizedString(String key) { + this.key = key; + } + + public String toString(java.util.Locale l, Messages messages) { + return messages.getLocalizedString(l, key); + } + public String getKind() { + return "LocalizedString"; + } + + public String toString() { + return key; + } + } } diff -r 6a9a2f681d24 -r e923a41e84cc langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 24 12:46:07 2008 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 24 12:46:34 2008 +0100 @@ -2378,16 +2378,14 @@ } if (warned && sym.type.tag == FORALL) { - String typeargs = ""; - if (typeargtypes != null && typeargtypes.nonEmpty()) { - typeargs = "<" + Type.toString(typeargtypes) + ">"; - } chk.warnUnchecked(env.tree.pos(), "unchecked.meth.invocation.applied", - sym, - sym.location(), - typeargs, - Type.toString(argtypes)); + kindName(sym), + sym.name, + rs.methodArguments(sym.type.getParameterTypes()), + rs.methodArguments(argtypes), + kindName(sym.location()), + sym.location()); owntype = new MethodType(owntype.getParameterTypes(), types.erasure(owntype.getReturnType()), owntype.getThrownTypes(), diff -r 6a9a2f681d24 -r e923a41e84cc langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Oct 24 12:46:07 2008 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Fri Oct 24 12:46:34 2008 +0100 @@ -30,6 +30,7 @@ import com.sun.tools.javac.code.*; import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.tree.*; +import com.sun.tools.javac.api.Formattable.LocalizedString; import static com.sun.tools.javac.comp.Resolve.MethodResolutionPhase.*; import com.sun.tools.javac.code.Type.*; @@ -1478,6 +1479,12 @@ error.report(log, tree.pos(), type.getEnclosingType(), null, null, null); } + private final LocalizedString noArgs = new LocalizedString("compiler.misc.no.args"); + + public Object methodArguments(List argtypes) { + return argtypes.isEmpty() ? noArgs : argtypes; + } + /** Root class for resolve errors. * Instances of this class indicate "Symbol not found". * Instances of subclass indicate other errors. @@ -1584,8 +1591,8 @@ "cant.apply.symbol" + (explanation != null ? ".1" : ""), kindname, ws.name == names.init ? ws.owner.name : ws.name, - ws.type.getParameterTypes(), - argtypes, + methodArguments(ws.type.getParameterTypes()), + methodArguments(argtypes), kindName(ws.owner), ws.owner.type, explanation); diff -r 6a9a2f681d24 -r e923a41e84cc langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Oct 24 12:46:07 2008 +0100 +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Fri Oct 24 12:46:34 2008 +0100 @@ -745,7 +745,10 @@ compiler.warn.unchecked.cast.to.type=\ [unchecked] unchecked cast to type {0} compiler.warn.unchecked.meth.invocation.applied=\ - [unchecked] unchecked method invocation: {0} in {1} is applied to {2}({3}) + [unchecked] unchecked method invocation: {0} {1} in {4} {5} is applied to given types\n\ + required: {2}\n\ + found: {3} + compiler.warn.unchecked.generic.array.creation=\ [unchecked] unchecked generic array creation of type {0} for varargs parameter @@ -1062,6 +1065,9 @@ package ##### +compiler.misc.no.args=\ + no arguments + compiler.err.override.static=\ {0}; overriding method is static compiler.err.override.meth=\ diff -r 6a9a2f681d24 -r e923a41e84cc langtools/test/tools/javac/6758789/T6758789a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6758789/T6758789a.java Fri Oct 24 12:46:34 2008 +0100 @@ -0,0 +1,40 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6758789 + * @summary 6758789: Some method resolution diagnostic should be improved + * @author Maurizio Cimadamore + * + * @compile/fail/ref=T6758789a.out -XDrawDiagnostics T6758789a.java + */ + +class T6758789a { + void m1() {} + void m2(int i) {} + void test() { + m1(1); + m2(); + } +} diff -r 6a9a2f681d24 -r e923a41e84cc langtools/test/tools/javac/6758789/T6758789a.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6758789/T6758789a.out Fri Oct 24 12:46:34 2008 +0100 @@ -0,0 +1,3 @@ +T6758789a.java:37:9: compiler.err.cant.apply.symbol: kindname.method, m1, compiler.misc.no.args, int, kindname.class, T6758789a, null +T6758789a.java:38:9: compiler.err.cant.apply.symbol: kindname.method, m2, int, compiler.misc.no.args, kindname.class, T6758789a, null +2 errors \ No newline at end of file diff -r 6a9a2f681d24 -r e923a41e84cc langtools/test/tools/javac/6758789/T6758789b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6758789/T6758789b.java Fri Oct 24 12:46:34 2008 +0100 @@ -0,0 +1,41 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6758789 + * @summary 6758789: Some method resolution diagnostic should be improved + * @author Maurizio Cimadamore + * + * @compile/fail/ref=T6758789b.out -Werror -XDrawDiagnostics -Xlint:unchecked T6758789b.java + */ + +class T6758789a { + class Foo {} + + void m(Foo foo) {} + + void test() { + m(new Foo()); + } +} diff -r 6a9a2f681d24 -r e923a41e84cc langtools/test/tools/javac/6758789/T6758789b.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6758789/T6758789b.out Fri Oct 24 12:46:34 2008 +0100 @@ -0,0 +1,3 @@ +T6758789b.java:39:11: compiler.warn.prob.found.req: (- compiler.misc.unchecked.assign), T6758789a.Foo, T6758789a.Foo +T6758789b.java:39:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6758789a.Foo, T6758789a.Foo, kindname.class, T6758789a +2 warnings diff -r 6a9a2f681d24 -r e923a41e84cc langtools/test/tools/javac/generics/inference/6718364/T6718364.out --- a/langtools/test/tools/javac/generics/inference/6718364/T6718364.out Fri Oct 24 12:46:07 2008 +0100 +++ b/langtools/test/tools/javac/generics/inference/6718364/T6718364.out Fri Oct 24 12:46:34 2008 +0100 @@ -1,3 +1,3 @@ T6718364.java:36:32: compiler.warn.prob.found.req: (- compiler.misc.unchecked.assign), T6718364.X, T6718364.X -T6718364.java:36:10: compiler.warn.unchecked.meth.invocation.applied: m(T6718364.X,T), T6718364, , T6718364.X>,T6718364.X +T6718364.java:36:10: compiler.warn.unchecked.meth.invocation.applied: kindname.method, m, T6718364.X,T, T6718364.X>,T6718364.X, kindname.class, T6718364 2 warnings \ No newline at end of file