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:
Anna Kozlova
2017-06-26 16:11:56 +03:00
parent ed4a26a905
commit 70170d6f19
2 changed files with 18 additions and 2 deletions
@@ -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;
@@ -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"));