mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
type migration: collapse to diamond if possible (IDEA-66116)
This commit is contained in:
@@ -162,11 +162,6 @@ public class TypeMigrationLabeler {
|
||||
};
|
||||
}
|
||||
|
||||
for (final TypeMigrationUsageInfo expr : myNewExpressionTypeChange.keySet()) {
|
||||
|
||||
usages[j++] = expr;
|
||||
}
|
||||
|
||||
for (final Pair<TypeMigrationUsageInfo, PsiType> p : declarations) {
|
||||
final TypeMigrationUsageInfo element = p.getFirst();
|
||||
usages[j++] = element;
|
||||
@@ -175,6 +170,10 @@ public class TypeMigrationLabeler {
|
||||
for (TypeMigrationUsageInfo info : myClassTypeArgumentsChange.keySet()) {
|
||||
usages[j++] = info;
|
||||
}
|
||||
|
||||
for (final TypeMigrationUsageInfo expr : myNewExpressionTypeChange.keySet()) {
|
||||
usages[j++] = expr;
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
|
||||
|
||||
+13
-4
@@ -18,8 +18,10 @@ package com.intellij.refactoring.typeMigration;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiDiamondTypeUtil;
|
||||
import com.intellij.psi.impl.source.tree.ChildRole;
|
||||
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;
|
||||
|
||||
@@ -137,7 +139,14 @@ public class TypeMigrationReplacementUtil {
|
||||
final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
|
||||
final PsiType componentType = changeType.getDeepComponentType();
|
||||
if (classReference != null) {
|
||||
replaceTypeWithClassReferenceOrKeyword(project, componentType, classReference);
|
||||
final PsiElement psiElement = replaceTypeWithClassReferenceOrKeyword(project, componentType, classReference);
|
||||
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(psiElement, PsiNewExpression.class);
|
||||
if (newExpression != null && PsiDiamondTypeUtil.canCollapseToDiamond(newExpression, newExpression, changeType)) {
|
||||
final PsiJavaCodeReferenceElement anonymousClassReference = newExpression.getClassOrAnonymousClassReference();
|
||||
if (anonymousClassReference != null) {
|
||||
PsiDiamondTypeUtil.replaceExplicitWithDiamond(anonymousClassReference.getParameterList());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PsiElement typeKeyword = getTypeKeyword(expression);
|
||||
@@ -152,12 +161,12 @@ public class TypeMigrationReplacementUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static void replaceTypeWithClassReferenceOrKeyword(Project project, PsiType componentType, PsiElement typePlace) {
|
||||
private static PsiElement replaceTypeWithClassReferenceOrKeyword(Project project, PsiType componentType, PsiElement typePlace) {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
|
||||
if (componentType instanceof PsiClassType) {
|
||||
typePlace.replace(factory.createReferenceElementByType((PsiClassType)componentType));
|
||||
return typePlace.replace(factory.createReferenceElementByType((PsiClassType)componentType));
|
||||
} else {
|
||||
typePlace.replace(getTypeKeyword(((PsiNewExpression)factory.createExpressionFromText("new " + componentType.getPresentableText() + "[0]", typePlace))));
|
||||
return typePlace.replace(getTypeKeyword(((PsiNewExpression)factory.createExpressionFromText("new " + componentType.getPresentableText() + "[0]", typePlace))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user