ProblemDescriptor (PsiMethodCallExpression call) { PsiExpression[] args = call.getArgumentList().getExpressions(); PsiExpression stringExpression = call.getMethodExpression().getQualifierExpression(); if (args.length == 1) { if (ExpressionUtils.isZero(args[0])) { return getProblem(call, "inspection.redundant.string.call.message"); } else if (isLengthOf(args[0], stringExpression)) { PsiElement anchor = Objects.requireNonNull(call.getMethodExpression().getReferenceNameElement()); return myManager.createProblemDescriptor(anchor, InspectionGadgetsBundle.message("inspection.redundant.string.call.message"), new SubstringToEmptyStringFix(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly); } return null; } // args.length == 2 if (isLengthOf(args[1], stringExpression)) { if (ExpressionUtils.isZero(args[0])) { return getProblem(call, "inspection.redundant.string.call.message"); } LocalQuickFix fix = LocalQuickFix.from(new DeleteElementFix( args[1], InspectionGadgetsBundle.message("inspection.redundant.string.remove.argument.fix.name"))); return myManager.createProblemDescriptor(args[1], InspectionGadgetsBundle.message("inspection.redundant.string.length.argument.message"), fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly); } if (isBetterWithCharAt(call)) { final String converted = String.format("%s.charAt(%s)", Objects.requireNonNull(stringExpression).getText(), args[0].getText()); PsiElement anchor = Objects.requireNonNull(call.getMethodExpression().getReferenceNameElement()); return myManager.createProblemDescriptor(anchor, (TextRange)null, InspectionGadgetsBundle.message("inspection.x.call.can.be.replaced.with.y", "charAt"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly, new SubstringToCharAtQuickFix(call.getText(), converted, false)); } PsiElement parent = PsiUtil.skipParenthesizedExprUp(call.getParent()); if (parent instanceof PsiExpressionList list && list.getExpressionCount() == 1 && parent.getParent() instanceof PsiMethodCallExpression parentCall && STRING_BUILDER_APPEND.test(parentCall)) { PsiElement nameElement = Objects.requireNonNull(call.getMethodExpression().getReferenceNameElement()); return myManager.createProblemDescriptor(nameElement, InspectionGadgetsBundle.message("inspection.redundant.string.call.message"), new RemoveRedundantStringCallFix( nameElement.getText(), FixType.REPLACE_WITH_ARGUMENTS), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly); } return null; }