Java inspection: Renamed the inspection "Make Type Generic" to a noun-based name. (IDEA-157727)

This commit is contained in:
Pavel Dolgov
2016-08-15 21:31:01 +03:00
parent b2df33aebd
commit 1d7e2f6389
6 changed files with 36 additions and 24 deletions
@@ -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
@@ -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<java.lang.String>");
doTest(getMessage("TT", "Comparator<String>"));
}
public void testLocalVariable() {
doTest("Change type of list to java.util.List<java.lang.String>");
doTest(getMessage("list", "List<String>"));
}
public void testAtEquals() {
doTest("Change type of list to java.util.List<java.lang.String>");
doTest(getMessage("list", "List<String>"));
}
public void testAtInitializer() {
assertIntentionNotAvailable("Change type of list to java.util.List<java.lang.String>");
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<IntentionAction> 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("@"));
}
}
@@ -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
@@ -1,7 +0,0 @@
<html>
<body>
This inspection considers variable declaration with initializer and adjusts variable type
if it was declared with <b>raw</b> type whereas initializer has fully parameterized <b>generic</b> type.
</body>
</html>
@@ -0,0 +1,9 @@
<html>
<body>
This inspection reports variable declarations with initializer where the variable type is declared with
<b>raw</b> type whereas initializer has fully parameterized <b>generic</b> type, e.g.
<code>List&nbsp;list&nbsp;=&nbsp;new ArrayList&lt;String&gt;()</code>
<p> The quick fix adds generic parameters to the variable type. The result would be like the following:
<pre><code>List&lt;String&gt; list = new ArrayList&lt;String&gt;()</code></pre>
</body>
</html>
+3 -3
View File
@@ -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"/>
<localInspection groupPath="Java" language="JAVA" shortName="MakeTypeGeneric" bundle="messages.InspectionsBundle"
key="inspection.suspicious.collections.method.calls.display.name" groupKey="group.names.code.style.issues"
<localInspection groupPath="Java" language="JAVA" shortName="RawTypeCanBeGeneric" bundle="messages.InspectionsBundle"
key="inspection.raw.variable.type.can.be.generic.name" groupKey="group.names.code.style.issues"
enabledByDefault="true" level="INFORMATION"
implementationClass="com.intellij.codeInspection.miscGenerics.MakeTypeGenericInspection"/>
implementationClass="com.intellij.codeInspection.miscGenerics.RawTypeCanBeGenericInspection"/>
<localInspection groupPath="Java" language="JAVA" shortName="LocalCanBeFinal" bundle="messages.InspectionsBundle" key="inspection.local.can.be.final.display.name"
groupKey="group.names.code.style.issues" enabledByDefault="false" level="WARNING"
implementationClass="com.intellij.codeInspection.localCanBeFinal.LocalCanBeFinal"/>