diff --git a/java/java-analysis-impl/resources/messages/InspectionGadgetsBundle.properties b/java/java-analysis-impl/resources/messages/InspectionGadgetsBundle.properties
index acd7b1aa78e1..9223807aa9bb 100644
--- a/java/java-analysis-impl/resources/messages/InspectionGadgetsBundle.properties
+++ b/java/java-analysis-impl/resources/messages/InspectionGadgetsBundle.properties
@@ -2175,6 +2175,7 @@ inspection.redundant.string.new.array.message=#ref is redundant #lo
inspection.redundant.string.replace.with.arg.fix.name=Replace with argument
inspection.redundant.string.replace.with.empty.fix.name=Replace with empty string
inspection.redundant.string.option.do.not.report.string.constructors=Do not report String constructor calls
+inspection.redundant.string.option.do.not.report.single.argument.substring=Do not report redundant single argument substring() calls
inspection.x.call.can.be.replaced.with.y=#ref() call can be replaced with ''{0}()''
inspection.type.may.be.weakened.display.name=Type may be weakened
diff --git a/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java b/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java
index 4a4f2e53ced7..01efa9dbf2ce 100644
--- a/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java
+++ b/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java
@@ -85,12 +85,15 @@ public final class RedundantStringOperationInspection extends AbstractBaseJavaLo
exactInstanceCall(JAVA_LANG_STRING, "strip", "stripLeading", "stripTrailing").parameterCount(0);
public boolean ignoreStringConstructor = false;
+ public boolean ignoreSingleArgSubstring = true;
@Override
public @NotNull OptPane getOptionsPane() {
return pane(
checkbox("ignoreStringConstructor",
- InspectionGadgetsBundle.message("inspection.redundant.string.option.do.not.report.string.constructors")));
+ InspectionGadgetsBundle.message("inspection.redundant.string.option.do.not.report.string.constructors")),
+ checkbox("ignoreSingleArgSubstring",
+ InspectionGadgetsBundle.message("inspection.redundant.string.option.do.not.report.single.argument.substring")));
}
@NotNull
@@ -572,7 +575,8 @@ public final class RedundantStringOperationInspection extends AbstractBaseJavaLo
PsiExpression[] args = call.getArgumentList().getExpressions();
PsiExpression stringExpression = call.getMethodExpression().getQualifierExpression();
if (args.length == 1) {
- if (ExpressionUtils.isZero(args[0]) ||
+ if (myInspection.ignoreSingleArgSubstring ||
+ ExpressionUtils.isZero(args[0]) ||
isLengthOf(args[0], stringExpression) ||
!(PsiUtil.deparenthesizeExpression(stringExpression) instanceof PsiReferenceExpression)) {
return null;
diff --git a/java/java-impl/src/inspectionDescriptions/StringOperationCanBeSimplified.html b/java/java-impl/src/inspectionDescriptions/StringOperationCanBeSimplified.html
index 6dec8ca018af..6c951324fa46 100644
--- a/java/java-impl/src/inspectionDescriptions/StringOperationCanBeSimplified.html
+++ b/java/java-impl/src/inspectionDescriptions/StringOperationCanBeSimplified.html
@@ -24,6 +24,16 @@ that can be replaced with a simpler expression.
This will avoid changing the outcome of String comparisons with == or != after applying
the quick-fix in code that uses new String() calls to guarantee a different object identity.
+ Use the Do not report single argument substring() calls option below to not report code like the following. +
+
+ stringBuilder.append(string.substring(5));
+
+which can be replaced with the following. +
+ stringBuilder.append(string, 5, string.length());
+
New in 2018.1