From acfb22157ba5b80386e22ea17958c4d462f6abee Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Fri, 9 Mar 2018 17:15:34 +0100 Subject: [PATCH] remove redundant type args: get rid of 2 different fixes --- .../RedundantTypeArgsInspection.java | 30 +------------------ .../redundantTypeArgs/afterAssignment.java | 2 +- .../redundantTypeArgs/afterEnumConstant.java | 2 +- .../redundantTypeArgs/afterExpectedType.java | 2 +- .../afterInsideNestedCall.java | 2 +- .../afterMethodReference.java | 2 +- ...odReferenceWithRedundantTypeArguments.java | 2 +- .../afterNonGenericCall.java | 2 +- .../afterNonGenericMethodReference.java | 2 +- .../redundantTypeArgs/beforeAssignment.java | 2 +- .../redundantTypeArgs/beforeEnumConstant.java | 2 +- .../redundantTypeArgs/beforeExpectedType.java | 2 +- .../beforeInsideNestedCall.java | 2 +- .../beforeInsideNestedCallInferredObject.java | 2 +- .../beforeMethodReference.java | 2 +- .../beforeMethodReference1.java | 2 +- ...odReferenceWithRedundantTypeArguments.java | 2 +- .../beforeNestedCallWithMethodRef.java | 2 +- .../beforeNonGenericCall.java | 2 +- .../beforeNonGenericMethodReference.java | 2 +- .../redundantTypeArgs/beforeOverloads.java | 2 +- .../src/messages/InspectionsBundle.properties | 3 +- 22 files changed, 22 insertions(+), 51 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java index 9b7c1e21512e..51e264b2a21c 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RedundantTypeArgsInspection.java @@ -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); - } - } - } - } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterAssignment.java index 34287b1f0d5f..dd2f28ba2f20 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterAssignment.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterAssignment.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.List; class Collectors { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterEnumConstant.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterEnumConstant.java index 4020c54b6b15..f4f12909b7b5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterEnumConstant.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterEnumConstant.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.Collections; import java.util.List; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterExpectedType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterExpectedType.java index 747f078c95ac..d34aba1108a6 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterExpectedType.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterExpectedType.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.*; class Foo { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterInsideNestedCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterInsideNestedCall.java index 37a0dce17205..77ce5c22ee56 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterInsideNestedCall.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterInsideNestedCall.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.List; class Collectors { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReference.java index 78160594cae2..bf16eae602ec 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReference.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReference.java @@ -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; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReferenceWithRedundantTypeArguments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReferenceWithRedundantTypeArguments.java index 6290528001f9..8032589d59ae 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReferenceWithRedundantTypeArguments.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterMethodReferenceWithRedundantTypeArguments.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.function.Function; public class TestClassRenamed { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericCall.java index ce104088d95e..0ddc74aac798 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericCall.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericCall.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" class Collectors { { Integer.getInteger(""); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericMethodReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericMethodReference.java index 64bce75bb2be..273596b3d570 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericMethodReference.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/afterNonGenericMethodReference.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.function.Function; class MyTest { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeAssignment.java index bf1448c20366..8026d29592c0 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeAssignment.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeAssignment.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.List; class Collectors { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeEnumConstant.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeEnumConstant.java index 9035bf417fc7..72cb2db931af 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeEnumConstant.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeEnumConstant.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.Collections; import java.util.List; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeExpectedType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeExpectedType.java index ce5132ba922b..3be9ff77a98b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeExpectedType.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeExpectedType.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.*; class Foo { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCall.java index 3e6d3784a691..8774c5e8e915 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCall.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCall.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.List; class Collectors { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCallInferredObject.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCallInferredObject.java index 161564710d93..15f19abe3d29 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCallInferredObject.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeInsideNestedCallInferredObject.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "false" +// "Remove type arguments" "false" import java.util.List; class Collectors { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference.java index caa2ac07d86f..bcf529d7c4f5 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference.java @@ -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; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference1.java index 64f84c583906..373e0543b5e9 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReference1.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "false" +// "Remove type arguments" "false" import java.util.Map.Entry; import java.util.stream.Collectors; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReferenceWithRedundantTypeArguments.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReferenceWithRedundantTypeArguments.java index 9521b87ca4ac..c375ef24172b 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReferenceWithRedundantTypeArguments.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeMethodReferenceWithRedundantTypeArguments.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.function.Function; public class TestClassRenamed { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNestedCallWithMethodRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNestedCallWithMethodRef.java index 35e8c7666fb4..deb5b7e60e7f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNestedCallWithMethodRef.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNestedCallWithMethodRef.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "false" +// "Remove type arguments" "false" import java.util.*; import java.util.function.Function; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericCall.java index 27130b8d0721..51cf267ded48 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericCall.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericCall.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" class Collectors { { Integer.ing>getInteger(""); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericMethodReference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericMethodReference.java index 556b5f3ce6b0..dae2d121367c 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericMethodReference.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeNonGenericMethodReference.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "true" +// "Remove type arguments" "true" import java.util.function.Function; class MyTest { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeOverloads.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeOverloads.java index 33601521654f..328772178e36 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeOverloads.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantTypeArgs/beforeOverloads.java @@ -1,4 +1,4 @@ -// "Remove explicit type arguments" "false" +// "Remove type arguments" "false" class Test { public void valueOfPasses() { diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties index ffb611a6f730..0df5c276974b 100644 --- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties +++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties @@ -217,8 +217,7 @@ inspection.unused.parameter.composer1=Parameter #ref 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