mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't try to infer from top if overloaded flag is on (IDEA-156937)
This commit is contained in:
@@ -558,19 +558,20 @@ public class ExpectedTypesProvider {
|
||||
|
||||
@Override public void visitExpressionList(@NotNull PsiExpressionList list) {
|
||||
PsiResolveHelper helper = JavaPsiFacade.getInstance(list.getProject()).getResolveHelper();
|
||||
if (list.getParent() instanceof PsiMethodCallExpression) {
|
||||
PsiMethodCallExpression methodCall = (PsiMethodCallExpression)list.getParent();
|
||||
PsiElement parent = list.getParent();
|
||||
if (parent instanceof PsiMethodCallExpression) {
|
||||
PsiMethodCallExpression methodCall = (PsiMethodCallExpression)parent;
|
||||
CandidateInfo[] candidates = helper.getReferencedMethodCandidates(methodCall, false, true);
|
||||
Collections.addAll(myResult, getExpectedArgumentTypesForMethodCall(candidates, list, myExpr, myForCompletion));
|
||||
}
|
||||
else if (list.getParent() instanceof PsiEnumConstant) {
|
||||
getExpectedArgumentsTypesForEnumConstant((PsiEnumConstant)list.getParent(), list);
|
||||
else if (parent instanceof PsiEnumConstant) {
|
||||
getExpectedArgumentsTypesForEnumConstant((PsiEnumConstant)parent, list);
|
||||
}
|
||||
else if (list.getParent() instanceof PsiNewExpression) {
|
||||
getExpectedArgumentsTypesForNewExpression((PsiNewExpression)list.getParent(), list);
|
||||
else if (parent instanceof PsiNewExpression) {
|
||||
getExpectedArgumentsTypesForNewExpression((PsiNewExpression)parent, list);
|
||||
}
|
||||
else if (list.getParent() instanceof PsiAnonymousClass) {
|
||||
getExpectedArgumentsTypesForNewExpression((PsiNewExpression)list.getParent().getParent(), list);
|
||||
else if (parent instanceof PsiAnonymousClass) {
|
||||
getExpectedArgumentsTypesForNewExpression((PsiNewExpression)parent.getParent(), list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class InferenceSessionContainer {
|
||||
if (parent instanceof PsiCall) {
|
||||
final PsiExpressionList argumentList = ((PsiCall)parent).getArgumentList();
|
||||
final MethodCandidateInfo.CurrentCandidateProperties properties = MethodCandidateInfo.getCurrentMethod(argumentList);
|
||||
if (properties != null && !properties.isApplicabilityCheck()) {
|
||||
if (properties != null && !properties.isApplicabilityCheck() && !MethodCandidateInfo.isOverloadCheck()) {
|
||||
final PsiCall topLevelCall = PsiResolveHelper.ourGraphGuard.doPreventingRecursion(parent, false,
|
||||
new Computable<PsiCall>() {
|
||||
@Override
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class Foo<T> {
|
||||
|
||||
|
||||
{
|
||||
bar(() -> Result.create(new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String s) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}, new Object())
|
||||
);
|
||||
}
|
||||
|
||||
private static <T> void bar(Supplier<T> provider ){}
|
||||
|
||||
static class Result<K> {
|
||||
public static <T> Result<T> create( T value, Collection<?> dependencies) {
|
||||
return new Result<T>();
|
||||
}
|
||||
|
||||
public static <T> Result<T> create( T value, Object... dependencies) {
|
||||
return new Result<T>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+28
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -83,6 +84,33 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
|
||||
doTestAllMethodCallExpressions();
|
||||
}
|
||||
|
||||
public void testCachingOfResultsDuringCandidatesIteration() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
final Collection<PsiMethodCallExpression> methodCallExpressions = PsiTreeUtil.findChildrenOfType(getFile(), PsiMethodCallExpression.class);
|
||||
|
||||
final PsiResolveHelper helper = JavaPsiFacade.getInstance(getProject()).getResolveHelper();
|
||||
for (PsiMethodCallExpression expression : methodCallExpressions) {
|
||||
CandidateInfo[] candidates = helper.getReferencedMethodCandidates(expression, false, true);
|
||||
PsiExpressionList argumentList = expression.getArgumentList();
|
||||
PsiExpression[] args = argumentList.getExpressions();
|
||||
for (JavaResolveResult result : candidates) {
|
||||
if (result instanceof MethodCandidateInfo) {
|
||||
final MethodCandidateInfo info = (MethodCandidateInfo)result;
|
||||
MethodCandidateInfo.ourOverloadGuard
|
||||
.doPreventingRecursion(argumentList, false, () -> info.inferTypeArguments(DefaultParameterTypeInferencePolicy.INSTANCE, args, true));
|
||||
}
|
||||
}
|
||||
|
||||
PsiMethodCallExpression parentCall = PsiTreeUtil.getParentOfType(expression, PsiMethodCallExpression.class, true);
|
||||
if (parentCall != null) {
|
||||
JavaResolveResult result = parentCall.getMethodExpression().advancedResolve(false);
|
||||
if (result instanceof MethodCandidateInfo) {
|
||||
assertNull(((MethodCandidateInfo)result).getInferenceErrorMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testNonCachingFolding() throws Exception {
|
||||
final String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
|
||||
configureByFile(filePath);
|
||||
|
||||
Reference in New Issue
Block a user