ambiguous method calls: do not prefer one of static methods when boxing occurs (IDEA-89345)

This commit is contained in:
Anna Kozlova
2012-08-03 11:20:15 +02:00
parent a7de0188ab
commit dd5a9764ce
3 changed files with 105 additions and 2 deletions

View File

@@ -490,7 +490,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
if (MethodSignatureUtil.isSubsignature(method1.getSignature(info1.getSubstitutor()), method2.getSignature(info2.getSubstitutor()))) {
isMoreSpecific = Specifics.SECOND;
}
else if (method1.hasModifierProperty(PsiModifier.STATIC) && method2.hasModifierProperty(PsiModifier.STATIC)) {
else if (method1.hasModifierProperty(PsiModifier.STATIC) && method2.hasModifierProperty(PsiModifier.STATIC) && boxingHappened[0] == 0) {
isMoreSpecific = Specifics.SECOND;
}
}
@@ -498,7 +498,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
if (MethodSignatureUtil.isSubsignature(method2.getSignature(info2.getSubstitutor()), method1.getSignature(info1.getSubstitutor()))) {
isMoreSpecific = Specifics.FIRST;
}
else if (method1.hasModifierProperty(PsiModifier.STATIC) && method2.hasModifierProperty(PsiModifier.STATIC)) {
else if (method1.hasModifierProperty(PsiModifier.STATIC) && method2.hasModifierProperty(PsiModifier.STATIC) && boxingHappened[0] == 0) {
isMoreSpecific = Specifics.FIRST;
}
}

View File

@@ -0,0 +1,47 @@
import java.util.Collections;
import java.util.Iterator;
public class AmbiguousTest extends AbstractTest {
public void testFoo() {
Iterator<Integer> list = Collections.singleton(1).iterator();
assertEquals<error descr="Ambiguous method call: both 'Assert.assertEquals(Object, Object)' and 'Assert.assertEquals(long, long)' match">(1, list.next())</error>;
}
}
abstract class AbstractTest extends Assert {
public static void assertEquals(float expected, float actual) {
Assert.assertEquals(expected, actual, 0.00001);
}
}
class Assert {
protected Assert() { /* compiled code */ }
public static void assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual) { /* compiled code */ }
public static void assertEquals(java.lang.Object expected, java.lang.Object actual) { /* compiled code */ }
public static void assertEquals(java.lang.String message, double expected, double actual, double delta) { /* compiled code */ }
public static void assertEquals(long expected, long actual) { /* compiled code */ }
public static void assertEquals(java.lang.String message, long expected, long actual) { /* compiled code */ }
/**
* @deprecated
*/
@java.lang.Deprecated
public static void assertEquals(double expected, double actual) { /* compiled code */ }
/**
* @deprecated
*/
@java.lang.Deprecated
public static void assertEquals(java.lang.String message, double expected, double actual) { /* compiled code */ }
public static void assertEquals(double expected, double actual, double delta) { /* compiled code */ }
/**
* @deprecated
*/
@java.lang.Deprecated
public static void assertEquals(java.lang.String message, java.lang.Object[] expecteds, java.lang.Object[] actuals) { /* compiled code */ }
/**
* @deprecated
*/
@java.lang.Deprecated
public static void assertEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals) { /* compiled code */ }
}

View File

@@ -0,0 +1,56 @@
/*
* 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 com.intellij.codeInsight.daemon;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.compiler.JavacQuirksInspection;
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
import org.jetbrains.annotations.NonNls;
/**
* This class is for "lightweight" tests only, i.e. those which can run inside default light project set up
* For "heavyweight" tests use AdvHighlightingTest
*/
public class AmbiguousMethodCallTest extends LightDaemonAnalyzerTestCase {
@NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/ambiguousCalls";
private void doTest(boolean checkWarnings, boolean checkInfos, InspectionProfileEntry... tools) throws Exception {
for (InspectionProfileEntry tool : tools) { enableInspectionTool(tool); }
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos);
}
private void doTest(boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos, InspectionProfileEntry... tools) throws Exception {
for (InspectionProfileEntry tool : tools) { enableInspectionTool(tool); }
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkWeakWarnings, checkInfos);
}
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{
new UnusedSymbolLocalInspection(),
new UncheckedWarningLocalInspection(),
new JavacQuirksInspection(),
new RedundantCastInspection()
};
}
public void testBoxingAndStaticMethods() throws Exception {
doTest(false, false);
}
}