mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RedundantStringOperation: id changed, merger updated (IDEA-CR-34351)
This commit is contained in:
+4
@@ -5,6 +5,10 @@ class Foo {
|
||||
// check merger
|
||||
//noinspection SubstringZero
|
||||
String sOld = s.substring(0x0);
|
||||
//noinspection RedundantStringOperation
|
||||
String sOld2 = s.substring(0x0);
|
||||
//noinspection StringOperationCanBeSimplified
|
||||
String sNew = s.substring(0x0);
|
||||
String s2 = s;
|
||||
String s3 = s.substring(0, 20);
|
||||
/*up until the string length*/
|
||||
|
||||
+4
@@ -5,6 +5,10 @@ class Foo {
|
||||
// check merger
|
||||
//noinspection SubstringZero
|
||||
String sOld = s.substring(0x0);
|
||||
//noinspection RedundantStringOperation
|
||||
String sOld2 = s.substring(0x0);
|
||||
//noinspection StringOperationCanBeSimplified
|
||||
String sNew = s.substring(0x0);
|
||||
String s2 = s.su<caret>bstring(0x0);
|
||||
String s3 = s.substring(0, 20);
|
||||
String s4 = s.substring(0, /*up until the string length*/ s.length());
|
||||
|
||||
+9
-3
@@ -2,18 +2,24 @@
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.testFramework.InspectionTestUtil;
|
||||
import com.siyeh.ig.redundancy.RedundantStringOperationInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RedundantStringOperationInspectionTest extends LightQuickFixParameterizedTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{
|
||||
new RedundantStringOperationInspection()
|
||||
};
|
||||
List<InspectionProfileEntry> tools =
|
||||
InspectionTestUtil.instantiateTools(Collections.singleton(RedundantStringOperationInspection.class));
|
||||
|
||||
return new LocalInspectionTool[]{(LocalInspectionTool)tools.iterator().next()};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2021,7 +2021,7 @@
|
||||
bundle="com.siyeh.InspectionGadgetsBundle" key="string.replaceable.by.string.buffer.display.name"
|
||||
groupBundle="messages.InspectionsBundle" groupKey="group.names.performance.issues" enabledByDefault="false"
|
||||
level="WARNING" implementationClass="com.siyeh.ig.performance.StringReplaceableByStringBufferInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="RedundantStringOperation" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="StringOperationCanBeSimplified" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
key="inspection.redundant.string.operation.display.name" groupBundle="messages.InspectionsBundle" groupKey="group.names.verbose.or.redundant.code.constructs"
|
||||
enabledByDefault="true" level="WARNING" cleanupTool="true" implementationClass="com.siyeh.ig.redundancy.RedundantStringOperationInspection"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="RedundantClassCall" bundle="com.siyeh.InspectionGadgetsBundle"
|
||||
|
||||
+8
-2
@@ -6,7 +6,6 @@ import com.intellij.codeInsight.daemon.impl.quickfix.DeleteElementFix;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -51,6 +50,13 @@ public class RedundantStringOperationInspection extends AbstractBaseJavaLocalIns
|
||||
instanceCall(JAVA_LANG_STRING, "indexOf", "startsWith").parameterCount(2);
|
||||
private static final CallMatcher STRING_LAST_INDEX_OF = instanceCall(JAVA_LANG_STRING, "lastIndexOf").parameterCount(2);
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message("inspection.redundant.string.operation.display.name");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
|
||||
@@ -110,7 +116,7 @@ public class RedundantStringOperationInspection extends AbstractBaseJavaLocalIns
|
||||
if (args.getExpressionCount() == 1) {
|
||||
PsiExpression arg = args.getExpressions()[0];
|
||||
if (TypeUtils.isJavaLangString(arg.getType()) &&
|
||||
(PsiUtil.getLanguageLevel(expression).isAtLeast(LanguageLevel.JDK_1_7) || !STRING_SUBSTRING.matches(arg))) {
|
||||
(PsiUtil.isLanguageLevel7OrHigher(expression) || !STRING_SUBSTRING.matches(arg))) {
|
||||
TextRange range = new TextRange(0, args.getStartOffsetInParent());
|
||||
return myManager.createProblemDescriptor(expression, range,
|
||||
InspectionGadgetsBundle.message("inspection.redundant.string.constructor.message"),
|
||||
|
||||
+3
-2
@@ -8,7 +8,7 @@ public class RedundantStringOperationMerger extends InspectionElementsMerger {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getMergedToolName() {
|
||||
return "RedundantStringOperation";
|
||||
return "StringOperationCanBeSimplified";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -17,7 +17,8 @@ public class RedundantStringOperationMerger extends InspectionElementsMerger {
|
||||
return new String[] {
|
||||
"StringToString", "RedundantStringToString",
|
||||
"SubstringZero", "ConstantStringIntern",
|
||||
"RedundantStringConstructorCall", "StringConstructor"
|
||||
"RedundantStringConstructorCall", "StringConstructor",
|
||||
"RedundantStringOperation"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user