diamonds: simulate resolved constructor with generated static factory (IDEA-195813)

This commit is contained in:
Anna.Kozlova
2018-07-23 19:17:42 +02:00
parent 2cc2fb05eb
commit 16f0977481
3 changed files with 33 additions and 2 deletions

View File

@@ -1712,8 +1712,18 @@ public class HighlightMethodUtil {
try {
final PsiDiamondType diamondType = constructorCall instanceof PsiNewExpression ? PsiDiamondType.getDiamondType((PsiNewExpression)constructorCall) : null;
final JavaResolveResult staticFactory = diamondType != null ? diamondType.getStaticFactory() : null;
applicable = staticFactory instanceof MethodCandidateInfo ? ((MethodCandidateInfo)staticFactory).isApplicable()
: result != null && result.isApplicable();
if (staticFactory instanceof MethodCandidateInfo) {
if (((MethodCandidateInfo)staticFactory).isApplicable()) {
result = (MethodCandidateInfo)staticFactory;
constructor = ((MethodCandidateInfo)staticFactory).getElement();
}
else {
applicable = false;
}
}
else {
applicable = result != null && result.isApplicable();
}
}
catch (IndexNotReadyException e) {
// ignore

View File

@@ -0,0 +1,17 @@
import java.util.function.Supplier;
class Foo {
private final Singleton<B> singletonB = new Singleton<>(() -> f());
static B f() {
return null;
}
}
interface B {
String getData();
}
class Singleton<T> {
public Singleton(Supplier<T> supplier) { }
public Singleton(T instance) { }
}

View File

@@ -101,6 +101,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testOverloadedConstructorsUnresolvedWithoutDiamonds() {
doTest();
}
private void doTest() {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
}