mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
generify fix for unchecked assignments (IDEA-152658)
This commit is contained in:
@@ -42,6 +42,7 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspectionTool {
|
||||
@@ -68,8 +69,8 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
return uncheckedCb;
|
||||
}
|
||||
|
||||
public static LocalQuickFix[] getChangeVariableTypeFixes(@NotNull PsiVariable parameter, PsiType itemType) {
|
||||
if (itemType instanceof PsiMethodReferenceType) return LocalQuickFix.EMPTY_ARRAY;
|
||||
public static LocalQuickFix[] getChangeVariableTypeFixes(@NotNull PsiVariable parameter, PsiType itemType, LocalQuickFix[] generifyFixes) {
|
||||
if (itemType instanceof PsiMethodReferenceType) return generifyFixes;
|
||||
final List<LocalQuickFix> result = new ArrayList<LocalQuickFix>();
|
||||
LOG.assertTrue(parameter.isValid());
|
||||
if (itemType != null) {
|
||||
@@ -81,6 +82,10 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (generifyFixes.length > 0) {
|
||||
Collections.addAll(result, generifyFixes);
|
||||
}
|
||||
return result.toArray(new LocalQuickFix[result.size()]);
|
||||
}
|
||||
|
||||
@@ -283,7 +288,7 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
if (initializer == null || initializer instanceof PsiArrayInitializerExpression) return;
|
||||
final PsiType initializerType = initializer.getType();
|
||||
checkRawToGenericsAssignment(initializer, initializer, variable.getType(), initializerType, true,
|
||||
myOnTheFly ? getChangeVariableTypeFixes(variable, initializerType) : LocalQuickFix.EMPTY_ARRAY);
|
||||
myOnTheFly ? getChangeVariableTypeFixes(variable, initializerType, myGenerifyFixes) : LocalQuickFix.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -295,7 +300,8 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
final PsiExpression iteratedValue = statement.getIteratedValue();
|
||||
if (iteratedValue == null) return;
|
||||
final PsiType itemType = JavaGenericsUtil.getCollectionItemType(iteratedValue);
|
||||
checkRawToGenericsAssignment(parameter, iteratedValue, parameterType, itemType, true, myOnTheFly ? getChangeVariableTypeFixes(parameter, itemType) : LocalQuickFix.EMPTY_ARRAY);
|
||||
checkRawToGenericsAssignment(parameter, iteratedValue, parameterType, itemType, true, myOnTheFly ? getChangeVariableTypeFixes(parameter, itemType,
|
||||
myGenerifyFixes) : LocalQuickFix.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -316,7 +322,7 @@ public class UncheckedWarningLocalInspectionBase extends BaseJavaBatchLocalInspe
|
||||
leftVar = (PsiVariable)element;
|
||||
}
|
||||
}
|
||||
checkRawToGenericsAssignment(rExpr, rExpr, lType, rType, true, myOnTheFly && leftVar != null ? getChangeVariableTypeFixes(leftVar, rType) : LocalQuickFix.EMPTY_ARRAY);
|
||||
checkRawToGenericsAssignment(rExpr, rExpr, lType, rType, true, myOnTheFly && leftVar != null ? getChangeVariableTypeFixes(leftVar, rType, myGenerifyFixes) : LocalQuickFix.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Try to generify 'before2.java'" "true"
|
||||
import java.util.ArrayList;
|
||||
class Use {
|
||||
void f() {
|
||||
ArrayList<String> s = new ArrayLi<caret>st();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user