mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
check diamond applicability over static factory underneath (IDEA-159287)
This commit is contained in:
+4
-1
@@ -1539,7 +1539,10 @@ public class HighlightMethodUtil {
|
||||
|
||||
boolean applicable = true;
|
||||
try {
|
||||
applicable = constructor != null && result.isApplicable();
|
||||
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();
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
// ignore
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.RecursionGuard;
|
||||
import com.intellij.openapi.util.RecursionManager;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -180,5 +181,6 @@ public abstract class PsiDiamondType extends PsiType {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract JavaResolveResult getStaticFactory();
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
|
||||
return PsiTreeUtil.getParentOfType(typeElementWithDiamondTypeArgument, PsiNewExpression.class, true, PsiTypeElement.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaResolveResult getStaticFactory() {
|
||||
final PsiNewExpression newExpression = getNewExpression();
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Collectinator<T, A, R> {
|
||||
Collectinator(Collector<T, A, R> collector) {
|
||||
}
|
||||
|
||||
static <K, L, M> Collectinator<K, L, M> create(Collector<K, L, M> c) {
|
||||
return new Collectinator<K, L, M>(c);
|
||||
}
|
||||
|
||||
public static void foo(Comparator<Foo> compareTo) {
|
||||
Collectinator<Foo, ?, Optional<Foo>> foo = new Collectinator< >(Collectors.maxBy(compareTo));
|
||||
Collectinator<Foo, ?, Optional<Foo>> foo1 = Collectinator.create(Collectors.maxBy(compareTo));
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {}
|
||||
+1
-1
@@ -6,7 +6,7 @@ class Test {
|
||||
|
||||
Holder dataHolder = null;
|
||||
Result<String> r3 = new Result<error descr="Cannot infer arguments"><></error>(new Holder<>(dataHolder));
|
||||
Result<String> r4 = Result.create<error descr="'create(K)' in 'Result' cannot be applied to '(Holder<E>)'">(new Holder<>(dataHolder))</error>;
|
||||
Result<String> r4 = Result.create<error descr="'create(K)' in 'Result' cannot be applied to '(Holder)'">(new Holder<>(dataHolder))</error>;
|
||||
|
||||
Result<String> r5 = new Result<error descr="Cannot infer arguments"><></error>(Holder.create(dataHolder));
|
||||
Result<String> r6 = Result.create<error descr="'create(K)' in 'Result' cannot be applied to '(Holder)'">(Holder.create(dataHolder))</error>;
|
||||
|
||||
+4
@@ -65,6 +65,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testEnsureApplicabilityForDiamondCallIsCheckedBasedOnStaticFactoryApplicability() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user