ProblemDescriptor (PsiMethodCallExpression call) { PsiMethodCallExpression qualifierCall = MethodCallUtils.getQualifierMethodCall(call); if (qualifierCall == null) return null; PsiExpression receiver = qualifierCall.getMethodExpression().getQualifierExpression(); if (receiver == null) return null; if (STRING_SUBSTRING_TWO_ARG.test(qualifierCall)) { PsiExpression equalTo = call.getArgumentList().getExpressions()[0]; PsiExpression[] args = qualifierCall.getArgumentList().getExpressions(); boolean lengthMatches = lengthMatches(equalTo, args[0], args[1]); if (lengthMatches) { PsiElement anchor = qualifierCall.getMethodExpression().getReferenceNameElement(); if (anchor != null) { if (equalTo instanceof PsiLiteralExpression literal && literal.getValue() instanceof String str && StringUtil.length(str) == 1) { return createSubstringToCharAtProblemDescriptor(call, anchor); } RemoveRedundantSubstringFix fix = new RemoveRedundantSubstringFix(isLengthOf(args[1], receiver) ? "endsWith" : "startsWith"); return myManager.createProblemDescriptor(anchor, (TextRange)null, InspectionGadgetsBundle.message("inspection.redundant.string.call.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly, fix); } } } if (STRING_SUBSTRING_ONE_ARG.test(qualifierCall)) { PsiExpression equalTo = call.getArgumentList().getExpressions()[0]; PsiExpression from = qualifierCall.getArgumentList().getExpressions()[0]; PsiExpression to = getLengthExpression(receiver, JavaPsiFacade.getElementFactory(myHolder.getProject())); boolean lengthMatches = lengthMatches(equalTo, from, to); if (lengthMatches) { PsiElement anchor = qualifierCall.getMethodExpression().getReferenceNameElement(); if (anchor != null) { return myManager.createProblemDescriptor(anchor, (TextRange)null, InspectionGadgetsBundle.message("inspection.redundant.string.call.message"), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myIsOnTheFly, new RemoveRedundantSubstringFix("endsWith")); } } } return null; }