This patch replaces the excessive extraction of a qualifier via `ExpressionUtils.getEffectiveQualifier` with a simple `call.getMethodExpression().getQualifierExpression`
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 4a4f1c6b218c63691fa2bd4610e9901874d3c712
This patch removes the detection of redundant calls to `StringBuilder#toString` from the `RedundantStringOperationInspection` since there is a more general inspection called `UnnecessaryToStringCallInspection` which handles all the redundant `Object#toString` calls. All the related tests were moved to the test data of `UnnecessaryToStringCallInspectionTest`
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 1fe7723fa4369b797120c5bbc6a6b24947c84a94
This patch fixes the syntax error in testData
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 90aae74914c4143dcb1ebff9e7d0c585f373718b
This patch simplifies the `RedundantStringOperationInspection#isOperandOfStringType` method by checking if the type of the passed operand is java.lang.String. The check is the same for any passed operand since they are of the `PsiExpression` type and hence poses the `PsiExpression#getType` method.
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: bcd489d41d1272877a1bbf6032ef837a228a18e1
This patch alters the `getRedundantStringBuilderToStringProblem` method with more sophisticated algorithm to detect unnecessary freestanding `StringBuilder#toString` calls. If the call is a part of a polyadic expression it checks if there is at least one string operand (either a constant literal or a local variable or a constant variable or a method call) and based on that information it detects redundant `StringBuilder#toString` calls.
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: e09ea8b8829ad9e28e8ff1bcfad34cf6b191aa6b
This patch enhances RedundantStringOperationInspection with detecting either unnecessary naked calls StringBuilder.toString or redundant toString in StringBuilder.toString.substring.
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 3cd7e964c0acc73fb1ac38061ef31264035f82dc
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
This patch fixes the notes from the review, it includes:
- restoring annotation.naming.convention.display.name
- using com.intellij.openapi.util.Pair instead of custom private objects
- using EquivalenceChecker.expressionsMatch in order to extract
difference between two PsiBinaryExpression
- using BoolUtils.findNegation to properly deduce the sign of the equals
clause
- restoring comments while replacing substring with charAt
- properly handling special characters (e.g. '\\', '\n', '\"', etc.) in
equals clause when it is converted to charAt + "=="
- eliminating the imperative form of a message for the inspection of
substring + equals
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: be1dfd53a6af10979485cd172af39653faafb744
IDEA didn't use to report pointless String.substring invocations for
cases when only one character in the string is extracted. In such cases
it makes more sense to use the String#charAt method because it is
allocation free.
IDEA didn't use to suggest to refactor for the code when String.substring
selects a single character and is followed by the equals method(e.g.
args[0].substring(0, 1).equals("_")) to more readable version e.g.
args[0].charAt(0) == '_'.
This patch adds such refactorings to both of the cases. It also adds
the possiblity to handle expressions like "i+1" and "i+2" to
com.siyeh.ig.psiutils.ExpressionUtils#isDifference.
Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>
GitOrigin-RevId: 6d179c7c9c605f08b4d4468712f8468fd68045a1
Replaceable with append(s, x, y)
Fixes IDEA-185652 Improve StringBulder.append(s.substring(1,2)) intention
Also optimization of new expression resolution