mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
EA-41114 - AIOOBE: StaticImportMethodFix.getExpectedType
This commit is contained in:
@@ -125,9 +125,22 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
final JavaResolveResult resolveResult = ((PsiCallExpression)pParent).resolveMethodGenerics();
|
||||
final PsiElement psiElement = resolveResult.getElement();
|
||||
if (psiElement instanceof PsiMethod) {
|
||||
final PsiParameter[] parameters = ((PsiMethod)psiElement).getParameterList().getParameters();
|
||||
final PsiMethod psiMethod = (PsiMethod)psiElement;
|
||||
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
|
||||
final int idx = ArrayUtilRt.find(((PsiExpressionList)parent).getExpressions(), PsiResolveHelperImpl.skipParenthesizedExprUp(methodCall));
|
||||
return idx > -1 ? resolveResult.getSubstitutor().substitute(parameters[idx].getType()) : null;
|
||||
if (idx > -1) {
|
||||
PsiType parameterType = parameters[Math.min(idx, parameters.length - 1)].getType();
|
||||
if (idx >= parameters.length - 1) {
|
||||
final PsiParameter lastParameter = parameters[parameters.length - 1];
|
||||
if (lastParameter.isVarArgs()) {
|
||||
parameterType = ((PsiEllipsisType)lastParameter.getType()).getComponentType();
|
||||
}
|
||||
}
|
||||
return resolveResult.getSubstitutor().substitute(parameterType);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// "Static Import Method 'foo.B.aaaaaaa'" "true"
|
||||
package foo;
|
||||
|
||||
import static foo.B.aaaaaaa;
|
||||
|
||||
public class X {
|
||||
{
|
||||
foo(1, 2, aaaaaaa(""));
|
||||
}
|
||||
|
||||
void foo(Integer... p) {}
|
||||
}
|
||||
|
||||
class B {
|
||||
public static Integer aaaaaaa(String s) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
class B1 {
|
||||
public static String aaaaaaa(String s) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Static Import Method 'foo.B.aaaaaaa'" "true"
|
||||
package foo;
|
||||
|
||||
public class X {
|
||||
{
|
||||
foo(1, 2, <caret>aaaaaaa(""));
|
||||
}
|
||||
|
||||
void foo(Integer... p) {}
|
||||
}
|
||||
|
||||
class B {
|
||||
public static Integer aaaaaaa(String s) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
class B1 {
|
||||
public static String aaaaaaa(String s) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user