mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add explicit type arguments: qualify method expression if needed (IDEA-64458)
This commit is contained in:
+14
-1
@@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -72,11 +73,23 @@ public class AddTypeArgumentsFix extends MethodArgumentFix {
|
||||
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(expression.getProject()).getElementFactory();
|
||||
PsiMethodCallExpression copy = (PsiMethodCallExpression)expression.copy();
|
||||
final PsiReferenceParameterList parameterList = copy.getMethodExpression().getParameterList();
|
||||
final PsiReferenceExpression methodExpression = copy.getMethodExpression();
|
||||
final PsiReferenceParameterList parameterList = methodExpression.getParameterList();
|
||||
LOG.assertTrue(parameterList != null);
|
||||
for (PsiType mapping : mappings) {
|
||||
parameterList.add(factory.createTypeElement(mapping));
|
||||
}
|
||||
if (methodExpression.getQualifierExpression() == null) {
|
||||
final PsiExpression qualifierExpression;
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
LOG.assertTrue(containingClass != null);
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
qualifierExpression = factory.createReferenceExpression(containingClass);
|
||||
} else {
|
||||
qualifierExpression = RefactoringUtil.createThisExpression(method.getManager(), null);
|
||||
}
|
||||
methodExpression.setQualifierExpression(qualifierExpression);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Add explicit type arguments" "true"
|
||||
import java.util.*;
|
||||
class Test {
|
||||
<T> List<T> f() { return new ArrayList<T>(); }
|
||||
void g(List<Integer> a) {}
|
||||
void someMethod() { g(this.<Integer>f()); }
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Add explicit type arguments" "true"
|
||||
import java.util.*;
|
||||
class Test {
|
||||
static <T> List<T> f() { return new ArrayList<T>(); }
|
||||
void g(List<Integer> a) {}
|
||||
void someMethod() { g(Test.<Integer>f()); }
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Add explicit type arguments" "true"
|
||||
import java.util.*;
|
||||
class Test {
|
||||
<T> List<T> f() { return new ArrayList<T>(); }
|
||||
void g(List<Integer> a) {}
|
||||
void someMethod() { g(f<caret>()); }
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Add explicit type arguments" "true"
|
||||
import java.util.*;
|
||||
class Test {
|
||||
static <T> List<T> f() { return new ArrayList<T>(); }
|
||||
void g(List<Integer> a) {}
|
||||
void someMethod() { g(<caret>f()); }
|
||||
}
|
||||
Reference in New Issue
Block a user