mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
type migration: recreate type if invalid in variables migration as it was before
This commit is contained in:
@@ -366,8 +366,15 @@ public class TypeMigrationLabeler {
|
||||
LOG.assertTrue(migrationTypeAndVariables != null);
|
||||
final PsiVariable[] variables = PsiTreeUtil.getChildrenOfType(typeElement.getParent().getParent(), PsiVariable.class);
|
||||
if (variables != null && variables.length == migrationTypeAndVariables.getValue().size()) {
|
||||
typeElement
|
||||
.replace(JavaPsiFacade.getElementFactory(variables[0].getProject()).createTypeElement(migrationTypeAndVariables.getKey()));
|
||||
try {
|
||||
PsiType migrationType = migrationTypeAndVariables.getKey();
|
||||
final Project project = variables[0].getProject();
|
||||
migrationType = TypeMigrationReplacementUtil.revalidateType(migrationType, project);
|
||||
typeElement.replace(JavaPsiFacade.getElementFactory(project).createTypeElement(migrationType));
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -25,6 +25,7 @@ import com.intellij.psi.impl.source.tree.CompositeElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -114,11 +115,16 @@ public class TypeMigrationReplacementUtil {
|
||||
return expression;
|
||||
}
|
||||
|
||||
static PsiType revalidateType(@NotNull PsiType migrationType, @NotNull Project project) {
|
||||
if (!migrationType.isValid()) {
|
||||
migrationType = JavaPsiFacade.getElementFactory(project).createTypeByFQClassName(migrationType.getCanonicalText());
|
||||
}
|
||||
return migrationType;
|
||||
}
|
||||
|
||||
static void migrateMemberOrVariableType(final PsiElement element, final Project project, PsiType migratedType) {
|
||||
try {
|
||||
if (!migratedType.isValid()) {
|
||||
migratedType = JavaPsiFacade.getElementFactory(project).createTypeByFQClassName(migratedType.getCanonicalText());
|
||||
}
|
||||
migratedType = revalidateType(migratedType, project);
|
||||
final PsiTypeElement typeElement = JavaPsiFacade.getInstance(project).getElementFactory().createTypeElement(migratedType);
|
||||
if (element instanceof PsiMethod) {
|
||||
final PsiTypeElement returnTypeElement = ((PsiMethod)element).getReturnTypeElement();
|
||||
|
||||
Reference in New Issue
Block a user