mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
disable add explicit type params when no args can be inferred
e.g. IDEA-174969: no args for raw types
This commit is contained in:
+5
-2
@@ -43,11 +43,14 @@ public class AddExplicitTypeArgumentsIntention extends BaseElementAtCaretIntenti
|
||||
if (methodExpression == null) return false;
|
||||
PsiElement parent = methodExpression.getParent();
|
||||
if (parent instanceof PsiMethodCallExpression && ((PsiMethodCallExpression)parent).getTypeArguments().length == 0) {
|
||||
JavaResolveResult result = ((PsiMethodCallExpression)parent).resolveMethodGenerics();
|
||||
PsiMethodCallExpression callExpression = (PsiMethodCallExpression)parent;
|
||||
JavaResolveResult result = callExpression.resolveMethodGenerics();
|
||||
if (result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).isApplicable()) {
|
||||
PsiElement method = result.getElement();
|
||||
setText(getFamilyName());
|
||||
return method instanceof PsiMethod && !((PsiMethod)method).isConstructor() && ((PsiMethod)method).hasTypeParameters();
|
||||
return method instanceof PsiMethod && !((PsiMethod)method).isConstructor() &&
|
||||
((PsiMethod)method).hasTypeParameters() &&
|
||||
AddTypeArgumentsFix.addTypeArguments(callExpression, null) != null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
+13
@@ -76,6 +76,19 @@ public class AddExplicitTypeArgumentsIntentionTest extends JavaCodeInsightFixtur
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testNotAvailableWhenRawTypeInferred() throws Exception {
|
||||
myFixture.configureByText("a.java", "import java.util.List;\n" +
|
||||
"class Foo {\n" +
|
||||
" <T> List<T> getList() {return null;}\n" +
|
||||
" {\n" +
|
||||
" List l;\n" +
|
||||
" l = get<caret>List();\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
final IntentionAction intentionAction = myFixture.getAvailableIntention(CodeInsightBundle.message("intention.add.explicit.type.arguments.family"));
|
||||
assertNull(intentionAction);
|
||||
}
|
||||
|
||||
private void doTest(String beforeText, String afterText) {
|
||||
myFixture.configureByText("a.java", beforeText);
|
||||
final IntentionAction intentionAction = myFixture.findSingleIntention(CodeInsightBundle.message("intention.add.explicit.type.arguments.family"));
|
||||
|
||||
Reference in New Issue
Block a user