ambiguous method calls: conflict resolver, tests

(IDEA-24768)
warn in jdk7 about static methods classes with same erased signature
This commit is contained in:
anna
2012-04-09 12:43:31 +02:00
parent 6cfb2cafce
commit 38c8ea8d02
4 changed files with 55 additions and 3 deletions
@@ -507,7 +507,8 @@ public class GenericsHighlightUtil {
}
else if (superMethod.isConstructor()) return null;
if (checkMethod.hasModifierProperty(PsiModifier.STATIC) && !checkEqualsSuper) {
final boolean atLeast17 = JavaVersionService.getInstance().isAtLeast(checkMethod, JavaSdkVersion.JDK_1_7);
if (checkMethod.hasModifierProperty(PsiModifier.STATIC) && !checkEqualsSuper && !atLeast17) {
return null;
}
@@ -515,7 +516,6 @@ public class GenericsHighlightUtil {
final PsiType retErasure2 = TypeConversionUtil.erasure(superMethod.getReturnType());
boolean differentReturnTypeErasure = !Comparing.equal(retErasure1, retErasure2);
final boolean atLeast17 = JavaVersionService.getInstance().isAtLeast(checkMethod, JavaSdkVersion.JDK_1_7);
if (checkEqualsSuper && atLeast17) {
if (retErasure1 != null && retErasure2 != null) {
differentReturnTypeErasure = !TypeConversionUtil.isAssignable(retErasure1, retErasure2);
@@ -555,7 +555,10 @@ public class GenericsHighlightUtil {
private static HighlightInfo getSameErasureMessage(final boolean sameClass, final PsiMethod method, final PsiMethod superMethod,
TextRange textRange) {
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" : "generics.methods.have.same.erasure.override";
@NonNls final String key = sameClass ? "generics.methods.have.same.erasure" :
method.hasModifierProperty(PsiModifier.STATIC) ?
"generics.methods.have.same.erasure.hide" :
"generics.methods.have.same.erasure.override";
String description = JavaErrorMessages.message(key, HighlightMethodUtil.createClashMethodMessage(method, superMethod, !sameClass));
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, textRange, description);
}
@@ -54,6 +54,7 @@ generics.cannot.be.inherited.with.different.type.arguments=''{0}'' cannot be inh
generics.select.static.class.from.parameterized.type=Cannot select static class ''{0}'' from parameterized type
generics.methods.have.same.erasure={0}; both methods have same erasure
generics.methods.have.same.erasure.override={0}; both methods have same erasure, yet neither overrides the other
generics.methods.have.same.erasure.hide={0}; both methods have same erasure, yet neither hides the other
generics.type.parameter.cannot.be.instantiated=Type parameter ''{0}'' cannot be instantiated directly
wildcard.type.cannot.be.instantiated=Wildcard type ''{0}'' cannot be instantiated directly
generics.wildcard.not.expected=No wildcard expected
@@ -0,0 +1,43 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package pck;
import java.util.ArrayList;
import java.util.List;
class IdeaBug {
public static void main(String[] args) {
ClassA.copyOf(new ArrayList<String>());
}
private static class ClassA<E> extends ClassB<E> {
<error descr="'copyOf(Iterable<? extends E>)' in 'pck.IdeaBug.ClassA' clashes with 'copyOf(Iterable<? extends E>)' in 'pck.IdeaBug.ClassB'; both methods have same erasure, yet neither hides the other">public static <E extends Comparable<? super E>> ClassA<E> copyOf(
Iterable<? extends E> elements)</error> {
System.out.println("Hello from ClassA");
return null;
}
}
private static class ClassB<E> {
public static <E> ClassA<E> copyOf(Iterable<? extends E> elements) {
System.out.println("Hello from ClassB");
return null;
}
}
}
@@ -172,4 +172,9 @@ public class AdvHighlightingJdk7Test extends DaemonAnalyzerTestCase {
public void testAmbiguousIDEA25097() throws Exception {
doTestAmbiguous();
}
public void testAmbiguousIDEA24768() throws Exception {
doTestAmbiguous();
}
}