From 1d7e2f638944692bfddd7a244d4ebc334bdea3fe Mon Sep 17 00:00:00 2001 From: Pavel Dolgov Date: Mon, 15 Aug 2016 21:21:32 +0300 Subject: [PATCH] Java inspection: Renamed the inspection "Make Type Generic" to a noun-based name. (IDEA-157727) --- ...ava => RawTypeCanBeGenericInspection.java} | 8 +++--- ...Test.java => RawTypeCanBeGenericTest.java} | 25 +++++++++++++------ .../src/messages/InspectionsBundle.properties | 5 ++-- .../MakeTypeGeneric.html | 7 ------ .../RawTypeCanBeGeneric.html | 9 +++++++ resources/src/META-INF/IdeaPlugin.xml | 6 ++--- 6 files changed, 36 insertions(+), 24 deletions(-) rename java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/{MakeTypeGenericInspection.java => RawTypeCanBeGenericInspection.java} (95%) rename java/java-tests/testSrc/com/intellij/codeInspection/{MakeTypeGenericTest.java => RawTypeCanBeGenericTest.java} (71%) delete mode 100644 resources-en/src/inspectionDescriptions/MakeTypeGeneric.html create mode 100644 resources-en/src/inspectionDescriptions/RawTypeCanBeGeneric.html diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/MakeTypeGenericInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RawTypeCanBeGenericInspection.java similarity index 95% rename from java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/MakeTypeGenericInspection.java rename to java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RawTypeCanBeGenericInspection.java index 60c8a24e3503..bd2202129b37 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/MakeTypeGenericInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/miscGenerics/RawTypeCanBeGenericInspection.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable; /** * @author dsl */ -public class MakeTypeGenericInspection extends BaseJavaBatchLocalInspectionTool { +public class RawTypeCanBeGenericInspection extends BaseJavaBatchLocalInspectionTool { @NotNull @Override @@ -41,9 +41,9 @@ public class MakeTypeGenericInspection extends BaseJavaBatchLocalInspectionTool if (variableTypeElement != null) { final PsiType type = getSuggestedType(variable); if (type != null) { - final String typeText = type.getCanonicalText(); + final String typeText = type.getPresentableText(); final String message = - InspectionsBundle.message("inspection.raw.variable.type.make.generic.text", variable.getName(), typeText); + InspectionsBundle.message("inspection.raw.variable.type.can.be.generic.quickfix", variable.getName(), typeText); final PsiElement beforeInitializer = PsiTreeUtil.skipSiblingsBackward(variable.getInitializer(), PsiWhiteSpace.class, PsiComment.class); final ProblemDescriptor descriptor = @@ -100,7 +100,7 @@ public class MakeTypeGenericInspection extends BaseJavaBatchLocalInspectionTool @NotNull @Override public String getFamilyName() { - return InspectionsBundle.message("inspection.raw.variable.type.make.generic.family"); + return InspectionsBundle.message("inspection.raw.variable.type.can.be.generic.family.quickfix"); } @Override diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/MakeTypeGenericTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/RawTypeCanBeGenericTest.java similarity index 71% rename from java/java-tests/testSrc/com/intellij/codeInspection/MakeTypeGenericTest.java rename to java/java-tests/testSrc/com/intellij/codeInspection/RawTypeCanBeGenericTest.java index e012a72e22b9..5358d2ead9dd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/MakeTypeGenericTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RawTypeCanBeGenericTest.java @@ -17,15 +17,15 @@ package com.intellij.codeInspection; import com.intellij.JavaTestUtil; import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.codeInspection.miscGenerics.MakeTypeGenericInspection; +import com.intellij.codeInspection.miscGenerics.RawTypeCanBeGenericInspection; import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.testFramework.IdeaTestUtil; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import java.util.List; -public class MakeTypeGenericTest extends LightCodeInsightFixtureTestCase { - private MakeTypeGenericInspection myInspection = new MakeTypeGenericInspection(); +public class RawTypeCanBeGenericTest extends LightCodeInsightFixtureTestCase { + private RawTypeCanBeGenericInspection myInspection = new RawTypeCanBeGenericInspection(); @Override protected String getBasePath() { @@ -50,23 +50,23 @@ public class MakeTypeGenericTest extends LightCodeInsightFixtureTestCase { } public void testField() { - doTest("Change type of TT to java.util.Comparator"); + doTest(getMessage("TT", "Comparator")); } public void testLocalVariable() { - doTest("Change type of list to java.util.List"); + doTest(getMessage("list", "List")); } public void testAtEquals() { - doTest("Change type of list to java.util.List"); + doTest(getMessage("list", "List")); } public void testAtInitializer() { - assertIntentionNotAvailable("Change type of list to java.util.List"); + assertIntentionNotAvailable(getMessagePrefix()); } public void testImplementedRaw() { - assertIntentionNotAvailable("Change type of"); + assertIntentionNotAvailable(getMessagePrefix()); } private void doTest(String intentionName) { @@ -81,4 +81,13 @@ public class MakeTypeGenericTest extends LightCodeInsightFixtureTestCase { final List intentionActions = myFixture.filterAvailableIntentions(intentionName); assertEmpty(intentionName + " is not expected", intentionActions); } + + private static String getMessage(String variable, String type) { + return InspectionsBundle.message("inspection.raw.variable.type.can.be.generic.quickfix", variable, type); + } + + private static String getMessagePrefix() { + String message = InspectionsBundle.message("inspection.raw.variable.type.can.be.generic.quickfix", "@", "@"); + return message.substring(0, message.indexOf("@")); + } } diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties index 29c112bbb7f5..d7b03a58a3c8 100644 --- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties +++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties @@ -215,8 +215,9 @@ inspection.suspicious.collections.method.calls.display.name=Suspicious collectio inspection.suspicious.collections.method.calls.problem.descriptor=''{0}'' may not contain objects of type ''{1}'' inspection.suspicious.collections.method.calls.problem.descriptor1=Suspicious call to ''{0}'' -inspection.raw.variable.type.make.generic.family=Make Type Generic -inspection.raw.variable.type.make.generic.text=Change type of {0} to {1} +inspection.raw.variable.type.can.be.generic.name=Raw type can be generic +inspection.raw.variable.type.can.be.generic.quickfix=Change type of {0} to {1} +inspection.raw.variable.type.can.be.generic.family.quickfix=Add generic parameters to the type inspection.reference.invalid=element no longer exists inspection.reference.default.package=default package diff --git a/resources-en/src/inspectionDescriptions/MakeTypeGeneric.html b/resources-en/src/inspectionDescriptions/MakeTypeGeneric.html deleted file mode 100644 index 0c2c900e406a..000000000000 --- a/resources-en/src/inspectionDescriptions/MakeTypeGeneric.html +++ /dev/null @@ -1,7 +0,0 @@ - - -This inspection considers variable declaration with initializer and adjusts variable type -if it was declared with raw type whereas initializer has fully parameterized generic type. - - - diff --git a/resources-en/src/inspectionDescriptions/RawTypeCanBeGeneric.html b/resources-en/src/inspectionDescriptions/RawTypeCanBeGeneric.html new file mode 100644 index 000000000000..442c582b2249 --- /dev/null +++ b/resources-en/src/inspectionDescriptions/RawTypeCanBeGeneric.html @@ -0,0 +1,9 @@ + + +This inspection reports variable declarations with initializer where the variable type is declared with +raw type whereas initializer has fully parameterized generic type, e.g. +List list = new ArrayList<String>() +

The quick fix adds generic parameters to the variable type. The result would be like the following: +

List<String> list = new ArrayList<String>()
+ + diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index 50202de43019..b78b5503056c 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -637,10 +637,10 @@ key="inspection.suspicious.collections.method.calls.display.name" groupKey="group.names.probable.bugs" enabledByDefault="true" level="WARNING" implementationClass="com.intellij.codeInspection.miscGenerics.SuspiciousCollectionsMethodCallsInspection"/> - + implementationClass="com.intellij.codeInspection.miscGenerics.RawTypeCanBeGenericInspection"/>