mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
type migration: fix some warnings
This commit is contained in:
+17
-20
@@ -19,7 +19,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.OverridenUsageInfo;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.OverriddenUsageInfo;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -34,7 +34,7 @@ class MigrateGetterNameSetting {
|
||||
|
||||
private final AtomicReference<Boolean> myGlobalValue = new AtomicReference<>();
|
||||
|
||||
void askUserIfNeed(final OverridenUsageInfo info, final String newMethodName, final PsiType migrationReturnType) {
|
||||
void askUserIfNeed(final OverriddenUsageInfo info, final String newMethodName, final PsiType migrationReturnType) {
|
||||
final Boolean globalValue = myGlobalValue.get();
|
||||
if (globalValue == null) {
|
||||
final String currentName = ((PsiMethod)info.getElement()).getName();
|
||||
@@ -42,26 +42,23 @@ class MigrateGetterNameSetting {
|
||||
currentName,
|
||||
newMethodName,
|
||||
migrationReturnType.getCanonicalText());
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Boolean globalValue = myGlobalValue.get();
|
||||
if (globalValue == null) {
|
||||
final int code = showChooserDialog(messageText);
|
||||
if (code == 0) {
|
||||
myGlobalValue.set(true);
|
||||
info.setMigrateMethodName(newMethodName);
|
||||
}
|
||||
else if (code == 1) {
|
||||
info.setMigrateMethodName(newMethodName);
|
||||
}
|
||||
else if (code == 2) {
|
||||
myGlobalValue.set(false);
|
||||
}
|
||||
}
|
||||
else if (globalValue.equals(Boolean.TRUE)) {
|
||||
UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
|
||||
final Boolean globalValue1 = myGlobalValue.get();
|
||||
if (globalValue1 == null) {
|
||||
final int code = showChooserDialog(messageText);
|
||||
if (code == 0) {
|
||||
myGlobalValue.set(true);
|
||||
info.setMigrateMethodName(newMethodName);
|
||||
}
|
||||
else if (code == 1) {
|
||||
info.setMigrateMethodName(newMethodName);
|
||||
}
|
||||
else if (code == 2) {
|
||||
myGlobalValue.set(false);
|
||||
}
|
||||
}
|
||||
else if (globalValue1.equals(Boolean.TRUE)) {
|
||||
info.setMigrateMethodName(newMethodName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
-9
@@ -46,15 +46,6 @@ public class TypeConversionDescriptorBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return substitutor of converted method parameters
|
||||
* or null if expression is not method call expression
|
||||
*/
|
||||
@Nullable
|
||||
public PsiSubstitutor getConvertedMethodParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PsiExpression replace(PsiExpression expression, @NotNull TypeEvaluator evaluator) throws IncorrectOperationException {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@@ -348,14 +348,14 @@ public class TypeEvaluator {
|
||||
}
|
||||
|
||||
public String getReport() {
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
final String[] t = new String[myTypeMap.size()];
|
||||
int k = 0;
|
||||
|
||||
for (final TypeMigrationUsageInfo info : myTypeMap.keySet()) {
|
||||
final LinkedList<PsiType> types = myTypeMap.get(info);
|
||||
final StringBuffer b = new StringBuffer();
|
||||
final StringBuilder b = new StringBuilder();
|
||||
|
||||
if (types != null) {
|
||||
b.append(info.getElement()).append(" : ");
|
||||
|
||||
+11
-12
@@ -38,7 +38,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.typeCook.deductive.PsiExtendedTypeVisitor;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.OverridenUsageInfo;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.OverriddenUsageInfo;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.OverriderUsageInfo;
|
||||
import com.intellij.refactoring.typeMigration.usageInfo.TypeMigrationUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
@@ -88,7 +88,7 @@ public class TypeMigrationLabeler {
|
||||
private final Set<TypeMigrationUsageInfo> myProcessedRoots = new HashSet<>();
|
||||
|
||||
public TypeMigrationLabeler(final TypeMigrationRules rules, PsiType rootType) {
|
||||
this(rules, Functions.<PsiElement, PsiType>constant(rootType));
|
||||
this(rules, Functions.constant(rootType));
|
||||
}
|
||||
|
||||
public TypeMigrationLabeler(final TypeMigrationRules rules, Function<PsiElement, PsiType> migrationRootTypeFunction) {
|
||||
@@ -339,8 +339,8 @@ public class TypeMigrationLabeler {
|
||||
}
|
||||
else {
|
||||
TypeMigrationReplacementUtil.migrateMemberOrVariableType(element, project, getTypeEvaluator().getType(usageInfo));
|
||||
if (usageInfo instanceof OverridenUsageInfo) {
|
||||
final String migrationName = ((OverridenUsageInfo)usageInfo).getMigrateMethodName();
|
||||
if (usageInfo instanceof OverriddenUsageInfo) {
|
||||
final String migrationName = ((OverriddenUsageInfo)usageInfo).getMigrateMethodName();
|
||||
if (migrationName != null) {
|
||||
ApplicationManager.getApplication().invokeLater(() -> new RenameProcessor(project, element, migrationName, false, false).run());
|
||||
}
|
||||
@@ -662,12 +662,12 @@ public class TypeMigrationLabeler {
|
||||
for (int i = -1; i < methods.length; i++) {
|
||||
final TypeMigrationUsageInfo m;
|
||||
if (i < 0) {
|
||||
final OverridenUsageInfo overridenUsageInfo = new OverridenUsageInfo(method);
|
||||
m = overridenUsageInfo;
|
||||
final OverriddenUsageInfo overriddenUsageInfo = new OverriddenUsageInfo(method);
|
||||
m = overriddenUsageInfo;
|
||||
final String newMethodName = isMethodNameCanBeChanged(method);
|
||||
if (newMethodName != null) {
|
||||
final MigrateGetterNameSetting migrateGetterNameSetting = myRules.getConversionSettings(MigrateGetterNameSetting.class);
|
||||
migrateGetterNameSetting.askUserIfNeed(overridenUsageInfo, newMethodName, myTypeEvaluator.getType(myCurrentRoot));
|
||||
migrateGetterNameSetting.askUserIfNeed(overriddenUsageInfo, newMethodName, myTypeEvaluator.getType(myCurrentRoot));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -687,13 +687,13 @@ public class TypeMigrationLabeler {
|
||||
final PsiMethod[] methods = OverridingMethodsSearch.search(method).toArray(PsiMethod.EMPTY_ARRAY);
|
||||
|
||||
final OverriderUsageInfo[] overriders = new OverriderUsageInfo[methods.length];
|
||||
final OverridenUsageInfo overridenUsageInfo = new OverridenUsageInfo(method.getParameterList().getParameters()[index]);
|
||||
final OverriddenUsageInfo overriddenUsageInfo = new OverriddenUsageInfo(method.getParameterList().getParameters()[index]);
|
||||
for (int i = -1; i < methods.length; i++) {
|
||||
final PsiMethod m = i < 0 ? method : methods[i];
|
||||
final PsiParameter p = m.getParameterList().getParameters()[index];
|
||||
final TypeMigrationUsageInfo paramUsageInfo;
|
||||
if (i < 0) {
|
||||
paramUsageInfo = overridenUsageInfo;
|
||||
paramUsageInfo = overriddenUsageInfo;
|
||||
}
|
||||
else {
|
||||
overriders[i] = new OverriderUsageInfo(p, method);
|
||||
@@ -924,7 +924,7 @@ public class TypeMigrationLabeler {
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(validReferences, (o1, o2) -> o1.getElement().getTextOffset() - o2.getElement().getTextOffset());
|
||||
Collections.sort(validReferences, Comparator.comparingInt(o -> o.getElement().getTextOffset()));
|
||||
|
||||
return validReferences.toArray(new PsiReference[validReferences.size()]);
|
||||
}
|
||||
@@ -1040,8 +1040,7 @@ public class TypeMigrationLabeler {
|
||||
}
|
||||
|
||||
private void iterate() {
|
||||
final LinkedList<Pair<TypeMigrationUsageInfo, PsiType>> roots =
|
||||
(LinkedList<Pair<TypeMigrationUsageInfo, PsiType>>)myMigrationRoots.clone();
|
||||
final List<Pair<TypeMigrationUsageInfo, PsiType>> roots = new ArrayList<>(myMigrationRoots);
|
||||
|
||||
myMigrationRoots = new LinkedList<>();
|
||||
|
||||
|
||||
+2
-3
@@ -45,11 +45,10 @@ import java.util.*;
|
||||
import static com.intellij.util.ObjectUtils.assertNotNull;
|
||||
|
||||
public class TypeMigrationProcessor extends BaseRefactoringProcessor {
|
||||
private final static Logger LOG = Logger.getInstance(TypeMigrationProcessor.class);
|
||||
private final static int MAX_ROOT_IN_PREVIEW_PRESENTATION = 3;
|
||||
|
||||
private PsiElement[] myRoot;
|
||||
private Function<PsiElement, PsiType> myRootTypes;
|
||||
private final Function<PsiElement, PsiType> myRootTypes;
|
||||
private final TypeMigrationRules myRules;
|
||||
private TypeMigrationLabeler myLabeler;
|
||||
|
||||
@@ -74,7 +73,7 @@ public class TypeMigrationProcessor extends BaseRefactoringProcessor {
|
||||
final PsiElement root,
|
||||
final PsiType migrationType,
|
||||
final boolean optimizeImports) {
|
||||
runHighlightingTypeMigration(project, editor, rules, new PsiElement[] {root}, Functions.<PsiElement, PsiType>constant(migrationType), optimizeImports);
|
||||
runHighlightingTypeMigration(project, editor, rules, new PsiElement[] {root}, Functions.constant(migrationType), optimizeImports);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -202,7 +202,7 @@ class TypeMigrationStatementProcessor extends JavaRecursiveElementVisitor {
|
||||
final PsiType valueType = myTypeEvaluator.evaluateType(value);
|
||||
if (returnType != null && valueType != null) {
|
||||
if (!myLabeler.addMigrationRoot(method, valueType, myStatement, TypeConversionUtil.isAssignable(returnType, valueType) && !isGetter(value, method), true, true)
|
||||
&& TypeMigrationLabeler.typeContainsTypeParameters(returnType, Collections.<PsiTypeParameter>emptySet())) {
|
||||
&& TypeMigrationLabeler.typeContainsTypeParameters(returnType, Collections.emptySet())) {
|
||||
value.accept(this);
|
||||
}
|
||||
}
|
||||
@@ -638,7 +638,7 @@ class TypeMigrationStatementProcessor extends JavaRecursiveElementVisitor {
|
||||
PsiType type = myTypeEvaluator.evaluateType(expr);
|
||||
type = type instanceof PsiEllipsisType ? ((PsiEllipsisType)type).toArrayType() : type;
|
||||
myType = GenericsUtil.getVariableTypeByExpressionType(type);
|
||||
myChanged = (myOriginType == null || myType == null) ? false : !myType.equals(myOriginType);
|
||||
myChanged = !(myOriginType == null || myType == null) && !myType.equals(myOriginType);
|
||||
}
|
||||
|
||||
public TypeView(PsiVariable var, PsiSubstitutor varSubstitutor, PsiSubstitutor evalSubstitutor) {
|
||||
@@ -649,7 +649,7 @@ class TypeMigrationStatementProcessor extends JavaRecursiveElementVisitor {
|
||||
if (evalSubstitutor != null) realMap.putAll(evalSubstitutor.getSubstitutionMap());
|
||||
|
||||
myType = PsiSubstitutorImpl.createSubstitutor(realMap).substitute(myTypeEvaluator.getType(var));
|
||||
myChanged = (myOriginType == null || myType == null) ? false : !myType.equals(myOriginType);
|
||||
myChanged = !(myOriginType == null || myType == null) && !myType.equals(myOriginType);
|
||||
}
|
||||
|
||||
public PsiType getType() {
|
||||
|
||||
-6
@@ -34,12 +34,6 @@ public class ChangeTypeSignatureAction extends BaseRefactoringAction {
|
||||
}
|
||||
|
||||
public boolean isEnabledOnElements(@NotNull PsiElement[] elements) {
|
||||
Project currProject = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
|
||||
|
||||
if (currProject == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (elements.length > 1) return false;
|
||||
|
||||
for (PsiElement element : elements) {
|
||||
|
||||
+2
-2
@@ -65,7 +65,7 @@ public class RootTypeConversionRule extends TypeConversionRule {
|
||||
if (Comparing.equal(functionalInterfaceType, to) && method.isEquivalentTo(LambdaUtil.getFunctionalInterfaceMethod(from))) {
|
||||
return new TypeConversionDescriptorBase() {
|
||||
@Override
|
||||
public PsiExpression replace(PsiExpression expression, TypeEvaluator evaluator) throws IncorrectOperationException {
|
||||
public PsiExpression replace(PsiExpression expression, @NotNull TypeEvaluator evaluator) throws IncorrectOperationException {
|
||||
final PsiMethodReferenceExpression methodReferenceExpression = (PsiMethodReferenceExpression)expression;
|
||||
final PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
@@ -147,7 +147,7 @@ public class RootTypeConversionRule extends TypeConversionRule {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiExpression replace(PsiExpression expression, TypeEvaluator evaluator) throws IncorrectOperationException {
|
||||
public PsiExpression replace(PsiExpression expression, @NotNull TypeEvaluator evaluator) throws IncorrectOperationException {
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
|
||||
final PsiExpression qualifierExpression = methodCallExpression.getMethodExpression().getQualifierExpression();
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(expression.getProject());
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ public class FailedConversionsDialog extends DialogWrapper {
|
||||
panel.add(new JLabel(RefactoringBundle.message("the.following.problems.were.found")), BorderLayout.NORTH);
|
||||
panel.add(scrollPane, BorderLayout.CENTER);
|
||||
|
||||
@NonNls StringBuffer buf = new StringBuffer();
|
||||
@NonNls StringBuilder buf = new StringBuilder();
|
||||
for (String description : myConflictDescriptions) {
|
||||
buf.append(description);
|
||||
buf.append("<br><br>");
|
||||
|
||||
@@ -121,8 +121,4 @@ public class MigrationNode extends AbstractTreeNode<TypeMigrationUsageInfo> impl
|
||||
public MigrationNode getDuplicate() {
|
||||
return myDuplicatedNode;
|
||||
}
|
||||
|
||||
public boolean hasDuplicate() {
|
||||
return myDuplicatedNode != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,15 +187,14 @@ public class MigrationPanel extends JPanel implements Disposable {
|
||||
if (userObject instanceof MigrationRootNode) {
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
|
||||
final HashSet<VirtualFile> files = new HashSet<>();
|
||||
final TypeMigrationUsageInfo[] usages = ApplicationManager.getApplication().runReadAction(new Computable<TypeMigrationUsageInfo[]>() {
|
||||
@Override
|
||||
public TypeMigrationUsageInfo[] compute() {
|
||||
final TypeMigrationUsageInfo[] usages = ApplicationManager.getApplication().runReadAction(
|
||||
(Computable<TypeMigrationUsageInfo[]>)() -> {
|
||||
final Collection<? extends AbstractTreeNode> children = ((MigrationRootNode)userObject).getChildren();
|
||||
for (AbstractTreeNode child : children) {
|
||||
expandTree((MigrationNode)child);
|
||||
}
|
||||
final TypeMigrationUsageInfo[] usages = myLabeler.getMigratedUsages();
|
||||
for (TypeMigrationUsageInfo usage : usages) {
|
||||
final TypeMigrationUsageInfo[] usages1 = myLabeler.getMigratedUsages();
|
||||
for (TypeMigrationUsageInfo usage : usages1) {
|
||||
if (!usage.isExcluded()) {
|
||||
final PsiElement element = usage.getElement();
|
||||
if (element != null) {
|
||||
@@ -203,9 +202,8 @@ public class MigrationPanel extends JPanel implements Disposable {
|
||||
}
|
||||
}
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
});
|
||||
return usages1;
|
||||
});
|
||||
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
@@ -306,7 +304,7 @@ public class MigrationPanel extends JPanel implements Disposable {
|
||||
}
|
||||
|
||||
public Object getData(@NonNls final String dataId) {
|
||||
if (DataConstants.PSI_ELEMENT.equals(dataId)) {
|
||||
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
|
||||
final DefaultMutableTreeNode[] selectedNodes = getSelectedNodes(DefaultMutableTreeNode.class, null);
|
||||
return selectedNodes.length == 1 && selectedNodes[0].getUserObject() instanceof MigrationNode
|
||||
? ((MigrationNode)selectedNodes[0].getUserObject()).getInfo().getElement() : null;
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.*;
|
||||
public class MigrationRootNode extends AbstractTreeNode<TypeMigrationLabeler> implements DuplicateNodeRenderer.DuplicatableNode {
|
||||
private final TypeMigrationLabeler myLabeler;
|
||||
private List<MigrationNode> myCachedChildren;
|
||||
private final PsiElement myRoots[];
|
||||
private final PsiElement[] myRoots;
|
||||
private final boolean myPreviewUsages;
|
||||
|
||||
protected MigrationRootNode(Project project,
|
||||
|
||||
+2
-2
@@ -22,10 +22,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author anna
|
||||
* Date: 27-Mar-2008
|
||||
*/
|
||||
public class OverridenUsageInfo extends TypeMigrationUsageInfo {
|
||||
public class OverriddenUsageInfo extends TypeMigrationUsageInfo {
|
||||
private volatile String myMigrateMethodName;
|
||||
|
||||
public OverridenUsageInfo(@NotNull PsiElement element) {
|
||||
public OverriddenUsageInfo(@NotNull PsiElement element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user