mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
type migration: fix AIOOBE for method with generic varargs migration (EA-87127)
This commit is contained in:
+14
-2
@@ -118,8 +118,7 @@ public class RootTypeConversionRule extends TypeConversionRule {
|
||||
}
|
||||
|
||||
final PsiType migrationType = methodTypeParamsSubstitutor.substitute(type);
|
||||
if (!originalType.equals(migrationType) &&
|
||||
!TypeConversionUtil.areTypesAssignmentCompatible(migrationType, actualParams[i])) {
|
||||
if (!originalType.equals(migrationType) && !areParametersAssignable(migrationType, i, actualParams)) {
|
||||
labeler.migrateExpressionType(actualParams[i], migrationType, context, false, true);
|
||||
}
|
||||
}
|
||||
@@ -139,6 +138,19 @@ public class RootTypeConversionRule extends TypeConversionRule {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean areParametersAssignable(PsiType migrationType, int paramId, PsiExpression[] actualParams) {
|
||||
if (migrationType instanceof PsiEllipsisType) {
|
||||
for (int i = paramId; i < actualParams.length; i++) {
|
||||
if (!TypeConversionUtil.areTypesAssignmentCompatible(migrationType, actualParams[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return TypeConversionUtil.areTypesAssignmentCompatible(migrationType, actualParams[paramId]);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyStaticMethodConversionDescriptor extends TypeConversionDescriptorBase {
|
||||
private final @NotNull String myTargetClassQName;
|
||||
|
||||
|
||||
@@ -862,6 +862,10 @@ public class TypeMigrationTest extends TypeMigrationTestBase {
|
||||
doTestMethodType("migrationMethod", PsiType.VOID);
|
||||
}
|
||||
|
||||
public void testGenericEllipsis() {
|
||||
doTestFieldType("migrationField", myJavaFacade.getElementFactory().createTypeFromText("Test<Short>", null));
|
||||
}
|
||||
|
||||
private void doTestReturnType(final String methodName, final String migrationType) {
|
||||
start(new RulesProvider() {
|
||||
@Override
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
Types:
|
||||
PsiField:migrationField : Test<java.lang.Short>
|
||||
PsiMethodCallExpression:migrationField.method() : void
|
||||
PsiReferenceExpression:migrationField : Test<java.lang.Short>
|
||||
|
||||
Conversions:
|
||||
migrationField.method() -> $
|
||||
|
||||
New expression type changes:
|
||||
Fails:
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test<X> {
|
||||
private static Test<Short> migrationField;
|
||||
|
||||
private static void m() {
|
||||
migrationField.method();
|
||||
}
|
||||
|
||||
void method(X... xes) {
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Test<X> {
|
||||
private static Test<Integer> migrationField;
|
||||
|
||||
private static void m() {
|
||||
migrationField.method();
|
||||
}
|
||||
|
||||
void method(X... xes) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user