mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
Revert: overload resolution: don't prefer concrete over abstract if the signatures are not override-equivalent (2bedb80d81)
This commit is contained in:
+15
-24
@@ -626,32 +626,23 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
|
||||
if (applicable12 && !applicable21) return Specifics.SECOND;
|
||||
if (applicable21 && !applicable12) return Specifics.FIRST;
|
||||
|
||||
if (MethodSignatureUtil.areOverrideEquivalent(method1, method2)) {
|
||||
//from 15.12.2.5 Choosing the Most Specific Method: concrete = nonabstract or default
|
||||
final boolean concrete1 = !method1.hasModifierProperty(PsiModifier.ABSTRACT) || method1.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
final boolean concrete2 = !method2.hasModifierProperty(PsiModifier.ABSTRACT) || method2.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
if (concrete2 && !concrete1) {
|
||||
//from 15.12.2.5 Choosing the Most Specific Method: concrete = nonabstract or default
|
||||
final boolean abstract1 = method1.hasModifierProperty(PsiModifier.ABSTRACT) || method1.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
final boolean abstract2 = method2.hasModifierProperty(PsiModifier.ABSTRACT) || method2.hasModifierProperty(PsiModifier.DEFAULT);
|
||||
if (abstract1 && !abstract2) {
|
||||
return Specifics.SECOND;
|
||||
}
|
||||
if (abstract2 && !abstract1) {
|
||||
return Specifics.FIRST;
|
||||
}
|
||||
|
||||
if (abstract1 && abstract2 && MethodSignatureUtil.areOverrideEquivalent(method1, method2)) {
|
||||
final PsiType returnType1 = method1.getReturnType();
|
||||
final PsiType returnType2 = method2.getReturnType();
|
||||
if (returnType1 != null && returnType2 != null && returnType1.isAssignableFrom(returnType2)) {
|
||||
return Specifics.SECOND;
|
||||
}
|
||||
|
||||
if (concrete1 && !concrete2) {
|
||||
return Specifics.FIRST;
|
||||
}
|
||||
|
||||
if (!concrete1 && !concrete2) {
|
||||
final PsiType returnType1 = method1.getReturnType();
|
||||
final PsiType returnType2 = method2.getReturnType();
|
||||
if (returnType1 != null && returnType2 != null) {
|
||||
boolean assignableFrom12 = returnType1.isAssignableFrom(returnType2);
|
||||
boolean assignableFrom21 = returnType2.isAssignableFrom(returnType1);
|
||||
if (assignableFrom12 && !assignableFrom21) {
|
||||
return Specifics.SECOND;
|
||||
}
|
||||
//then the most specific method is chosen arbitrarily among the subset of the maximally specific methods
|
||||
//that have the most specific return type
|
||||
return Specifics.FIRST;
|
||||
}
|
||||
}
|
||||
return Specifics.FIRST;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
abstract class Ambiguity {
|
||||
|
||||
public abstract <T> T executeServerOperation(ThrowableComputable<T, IOException> computable);
|
||||
public <T> T executeServerOperation(final Computable<T> computable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean foo(Ambiguity a, String s){
|
||||
return a.<error descr="Ambiguous method call: both 'Ambiguity.executeServerOperation(ThrowableComputable<Boolean, IOException>)' and 'Ambiguity.executeServerOperation(Computable<Boolean>)' match">executeServerOperation</error>(() -> bool(s, a));
|
||||
}
|
||||
|
||||
protected abstract boolean bool(String s, Ambiguity a);
|
||||
}
|
||||
|
||||
interface ThrowableComputable<T, E extends Throwable> {
|
||||
T compute() throws E;
|
||||
}
|
||||
interface Computable <T> {
|
||||
|
||||
T compute();
|
||||
}
|
||||
+1
-1
@@ -39,7 +39,7 @@ class Test2 {
|
||||
public static void main(IJ s, J<String> j) {
|
||||
s.f("");
|
||||
|
||||
j.j<error descr="Ambiguous method call: both 'J.j(String)' and 'J.j(String)' match">("")</error>;
|
||||
<error descr="Static method may be invoked on containing interface class only">j.j("");</error>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.defUse.DefUseInspection;
|
||||
import com.intellij.idea.Bombed;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
@@ -26,8 +25,6 @@ import com.intellij.testFramework.IdeaTestUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* This class intended for "heavily-loaded" tests only, e.g. those need to setup separate project directory structure to run.
|
||||
* For "lightweight" tests please use {@linkplain LightAdvHighlightingJdk7Test}.
|
||||
@@ -226,7 +223,6 @@ public class AdvHighlightingJdk7Test extends DaemonAnalyzerTestCase {
|
||||
doTestAmbiguous();
|
||||
}
|
||||
|
||||
@Bombed(day = 1, month = Calendar.JUNE, user = "anna")
|
||||
public void testAmbiguousIDEA57569() throws Exception {
|
||||
doTestAmbiguous();
|
||||
}
|
||||
|
||||
-4
@@ -229,10 +229,6 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testNonComparableFunctionalInterfacesWithConcreteShouldNotWin() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user