mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
smart completion: diamonds: forbid non applicable diamonds based on the completion position (IDEA-87053)
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
@@ -154,14 +155,15 @@ public class JavaInheritorsGetter extends CompletionProvider<CompletionParameter
|
||||
}
|
||||
|
||||
private static boolean areInferredTypesApplicable(@NotNull PsiType[] types, PsiElement originalPosition) {
|
||||
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiNewExpression.class);
|
||||
if (newExpression != null) {
|
||||
final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiMethodCallExpression.class);
|
||||
if (methodCallExpression != null &&
|
||||
ArrayUtil.find(methodCallExpression.getArgumentList().getExpressions(), newExpression) > -1) {
|
||||
final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiMethodCallExpression.class);
|
||||
if (methodCallExpression != null) {
|
||||
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiNewExpression.class);
|
||||
if (newExpression != null && ArrayUtil.find(methodCallExpression.getArgumentList().getExpressions(), newExpression) > -1 ||
|
||||
Comparing.equal(originalPosition.getParent(), methodCallExpression.getArgumentList())) {
|
||||
final JavaResolveResult resolveResult = methodCallExpression.resolveMethodGenerics();
|
||||
PsiMethod method = (PsiMethod)resolveResult.getElement();
|
||||
return method == null || PsiUtil.getApplicabilityLevel(method, resolveResult.getSubstitutor(), types, PsiUtil.getLanguageLevel(originalPosition))
|
||||
final PsiMethod method = (PsiMethod)resolveResult.getElement();
|
||||
return method == null ||
|
||||
PsiUtil.getApplicabilityLevel(method, resolveResult.getSubstitutor(), types, PsiUtil.getLanguageLevel(originalPosition))
|
||||
!= MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TestCompletion {
|
||||
public static void test() {
|
||||
A<ArrayList<String>> ref = new A<>();
|
||||
ref.set(new ArrayList<String>(<caret>) );
|
||||
}
|
||||
}
|
||||
|
||||
class A<V> {
|
||||
A() {
|
||||
}
|
||||
|
||||
void set(V v){}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TestCompletion {
|
||||
public static void test() {
|
||||
A<ArrayList<String>> ref = new A<>();
|
||||
ref.set(new <caret> );
|
||||
}
|
||||
}
|
||||
|
||||
class A<V> {
|
||||
A() {
|
||||
}
|
||||
|
||||
void set(V v){}
|
||||
}
|
||||
+4
@@ -46,6 +46,10 @@ public class SmartType17CompletionTest extends LightFixtureCompletionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDiamondNotCollapsedNotApplicable() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDiamondNotCollapsedInCaseOfAnonymousClasses() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user