void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { final PsiReferenceExpression methodExpression = (PsiReferenceExpression)element.getParent(); final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)methodExpression.getParent(); final PsiElement qualifier = methodExpression.getQualifier(); if (qualifier == null) { return; } final PsiExpressionList argumentList = methodCall.getArgumentList(); final PsiExpression[] expressions = argumentList.getExpressions(); final PsiExpression expression = expressions[0]; final String expressionText = expression.getText(); String character = expressionText.substring(1, expressionText.length() - 1); if (character.equals("'")) { character = "\\'"; } final String qualifierText = qualifier.getText(); @NonNls final StringBuilder newExpression = new StringBuilder(); final PsiClass stringClass = ClassUtils.findClass(CommonClassNames.JAVA_LANG_STRING, qualifier); // String.isEmpty() was introduced in Java 6 final PsiMethod[] isEmptyMethod = (stringClass == null) ? PsiMethod.EMPTY_ARRAY : stringClass.findMethodsByName("isEmpty", false); if (isEmptyMethod.length > 0) { newExpression.append("!").append(qualifierText).append(".isEmpty() && "); } else { newExpression.append(qualifierText).append(".length() > 0 && "); } final String referenceName = methodExpression.getReferenceName(); newExpression.append(qualifierText).append(".charAt("); if (HardcodedMethodConstants.STARTS_WITH.equals(referenceName)) { newExpression.append("0) == '"); } else { newExpression.append(qualifierText).append(".length() - 1) == '"); } newExpression.append(character).append('\''); final CommentTracker commentTracker = new CommentTracker(); commentTracker.markUnchanged(qualifier); PsiReplacementUtil.replaceExpression(methodCall, newExpression.toString(), commentTracker); }