EA-41114 - AIOOBE: StaticImportMethodFix.getExpectedType

This commit is contained in:
anna
2012-11-21 13:52:05 +01:00
parent 82c1cbfcd1
commit 73b6d506d2
3 changed files with 59 additions and 2 deletions

View File

@@ -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;
}
}
}
}

View File

@@ -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 "";
}
}

View File

@@ -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 "";
}
}