Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantStringOperation/beforeSubstringOneCharInEquals.java
Nikita Eshkeev 565443bca4 [codeInsight] IDEA-219640 Inspection to detect some pointless String.substring
This patch fixes the notes from the review, it contains:

1. fixing the javadoc for ExpressionUtils#isConversionToStringNecessary
2. properly handling JavaTokenType.MINUS in ExpressionUtils#isDifference
3. properly handling complex PsiPolyadicExpression values in ExpressionUtils#isDifference
4. changing ProblemHighlightType to GENERIC_ERROR_OR_WARNING for
inspecitons like these
5. fixing the comments duplication problem when replacing the old string
with a new one for inspections like stringValue.substring(0, 1).equals("_")

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 907524c9026e2d1d7cd6f0bd7b988e478e73298d
2020-04-20 20:10:15 +00:00

20 lines
902 B
Java

// "Fix all 'Redundant String operation' problems in file" "true"
class Foo {
public static void main(String[] args) {
int i = Integer.parseInt(args[2]);
int j = Integer.parseInt(args[4]);
boolean value = args[0].substring(4, 5).equals("_");
if (args[0].sub<caret>string(4, 5).equals("_")) { }
if (!args[0].substring(4, 5).equals("_")) { }
if (!!args[0].substring(4, 5).equals("_")) { }
if (!!!!!args[0].substring(4, 5).equals("_")) { }
if (/* one */args/* two */[/* three */ 0 /* four */].substring(i /* five */ + 1, i + 2).equals("x")) { }
if (!/* one */args/* two */[/* three */ 0 /* four */].substring(i /* five */ + 1, i + 2).equals("x")) { }
if (!/* one */(!!args/* two */[/* three */ 0 /* four */].substring(i /* five */ + 1, i + 2).equals("x"))) { }
if (args[0].substring(i - ((j - 1) - (j + 1)), i - ((j - 2) - (j + 1))).equals("\'")) {}
}
}