remove redundant type args: get rid of 2 different fixes

This commit is contained in:
Anna.Kozlova
2018-03-09 18:44:26 +01:00
parent 5cf3e46d8a
commit acfb22157b
22 changed files with 22 additions and 51 deletions
@@ -21,7 +21,6 @@ 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.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
@@ -150,7 +149,7 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase {
final PsiReferenceParameterList parameterList = referenceElement.getParameterList();
LOG.assertTrue(parameterList != null);
final ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(parameterList, InspectionsBundle
.message("inspection.redundant.type.problem.descriptor"), new MyMethodReferenceFixAction(), ProblemHighlightType.LIKE_UNUSED_SYMBOL, isOnTheFly);
.message("inspection.redundant.type.problem.descriptor"), ourQuickFixAction, ProblemHighlightType.LIKE_UNUSED_SYMBOL, isOnTheFly);
problems.add(descriptor);
}
}
@@ -200,31 +199,4 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase {
}
}
}
//separate quickfix is needed to invalidate initial method reference
//otherwise it would provide inconsistent substitutors to the next chained calls
private static class MyMethodReferenceFixAction implements LocalQuickFix {
@Override
@NotNull
public String getFamilyName() {
return InspectionsBundle.message("inspection.redundant.type.remove.methodref.quickfix");
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiTypeElement typeElement = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiTypeElement.class);
final PsiMethodReferenceExpression expression = PsiTreeUtil.getParentOfType(typeElement, PsiMethodReferenceExpression.class);
if (expression != null) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(expression.getProject());
final PsiClass aClass = ((PsiClassType)typeElement.getType()).resolve();
if (aClass != null) {
final PsiMethodReferenceExpression copy = (PsiMethodReferenceExpression)expression.copy();
final PsiTypeElement qualifier = copy.getQualifierType();
assert qualifier != null;
qualifier.replace(elementFactory.createReferenceExpression(aClass));
expression.replace(copy);
}
}
}
}
}
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.List;
class Collectors {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.Collections;
import java.util.List;
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.*;
class Foo {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.List;
class Collectors {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments of method reference" "true"
// "Remove type arguments" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.function.Function;
public class TestClassRenamed {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
class Collectors {
{
Integer.getInteger("");
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.function.Function;
class MyTest {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.List;
class Collectors {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.Collections;
import java.util.List;
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.*;
class Foo {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.List;
class Collectors {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "false"
// "Remove type arguments" "false"
import java.util.List;
class Collectors {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments of method reference" "true"
// "Remove type arguments" "true"
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "false"
// "Remove type arguments" "false"
import java.util.Map.Entry;
import java.util.stream.Collectors;
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.function.Function;
public class TestClassRenamed {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "false"
// "Remove type arguments" "false"
import java.util.*;
import java.util.function.Function;
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
class Collectors {
{
Integer.<Str<caret>ing>getInteger("");
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "true"
// "Remove type arguments" "true"
import java.util.function.Function;
class MyTest {
@@ -1,4 +1,4 @@
// "Remove explicit type arguments" "false"
// "Remove type arguments" "false"
class Test {
public void valueOfPasses() {
@@ -217,8 +217,7 @@ inspection.unused.parameter.composer1=Parameter <code>#ref</code> is not used in
inspection.unused.parameter.display.name=Unused method parameters
inspection.unused.parameter.delete.quickfix=Delete unused parameter(s)
inspection.redundant.type.display.name=Redundant type arguments
inspection.redundant.type.remove.quickfix=Remove explicit type arguments
inspection.redundant.type.remove.methodref.quickfix=Remove explicit type arguments of method reference
inspection.redundant.type.remove.quickfix=Remove type arguments
inspection.redundant.type.problem.descriptor=Explicit type arguments can be inferred
inspection.redundant.type.no.generics.problem.descriptor=Type arguments are redundant for the non-generic method call
inspection.redundant.type.no.generics.method.reference.problem.descriptor=Type arguments are redundant for the non-generic method reference