mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
make add cast fix available for vararg methods (IDEA-169541)
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,11 +55,11 @@ public abstract class ArgumentFixerActionFactory {
|
||||
PsiMethod method = (PsiMethod) candidate.getElement();
|
||||
PsiSubstitutor substitutor = candidate.getSubstitutor();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
if (expressions.length != parameters.length) {
|
||||
if (expressions.length != parameters.length && !method.isVarArgs()) {
|
||||
methodCandidates.remove(i);
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < parameters.length; j++) {
|
||||
for (int j = 0; j < Math.min(parameters.length, expressions.length); j++) {
|
||||
PsiParameter parameter = parameters[j];
|
||||
PsiExpression expression = expressions[j];
|
||||
// check if we can cast to this method
|
||||
@@ -84,8 +85,7 @@ public abstract class ArgumentFixerActionFactory {
|
||||
for (CandidateInfo candidate : methodCandidates) {
|
||||
PsiMethod method = (PsiMethod)candidate.getElement();
|
||||
PsiSubstitutor substitutor = candidate.getSubstitutor();
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiType originalParameterType = parameters[i].getType();
|
||||
PsiType originalParameterType = PsiTypesUtil.getParameterType(method.getParameterList().getParameters(), i, true);
|
||||
PsiType parameterType = substitutor.substitute(originalParameterType);
|
||||
if (parameterType instanceof PsiWildcardType) continue;
|
||||
if (!GenericsUtil.isFromExternalTypeLanguage(parameterType)) continue;
|
||||
|
||||
@@ -67,7 +67,11 @@ public class CastMethodArgumentFix extends MethodArgumentFix implements HighPrio
|
||||
parameterType = PsiPrimitiveType.getUnboxedType(parameterType);
|
||||
if (parameterType == null) return false;
|
||||
}
|
||||
return parameterType.isConvertibleFrom(exprType);
|
||||
if (parameterType.isConvertibleFrom(exprType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parameterType instanceof PsiEllipsisType && areTypesConvertible(exprType, ((PsiEllipsisType)parameterType).getComponentType(), context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l, String... s) {}
|
||||
void g() {
|
||||
f((long) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast 1st parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l, String... s) {}
|
||||
void g() {
|
||||
f((long) 0, "", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast 1st parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l, String... s) {}
|
||||
void g() {
|
||||
f((long) 0, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l, String... s) {}
|
||||
void g() {
|
||||
f(<caret>0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast 1st parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l, String... s) {}
|
||||
void g() {
|
||||
f(<caret>0, "", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Cast 1st parameter to 'long'" "true"
|
||||
class a {
|
||||
void f(Long l, String... s) {}
|
||||
void g() {
|
||||
f(<caret>0, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user