boolean (PsiExpression expression) { final PsiExpressionList parent = PsiTreeUtil.getParentOfType(expression, PsiExpressionList.class, true, PsiStatement.class); if (parent == null) { return false; } final PsiElement grandParent = parent.getParent(); if (grandParent instanceof PsiMethodCallExpression methodCallExpression) { return isCallToStringBuilderMethod(methodCallExpression) || isArgumentOfStringBuilderMethod(methodCallExpression); } if (grandParent instanceof PsiNewExpression newExpression) { final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(grandParent, PsiLocalVariable.class, true, PsiExpressionList.class); if (!myVariable.equals(variable)) { return false; } final PsiMethod constructor = newExpression.resolveMethod(); if (constructor == null) { return false; } final PsiClass aClass = constructor.getContainingClass(); if (aClass == null) { return false; } final String name = aClass.getQualifiedName(); return CommonClassNames.JAVA_LANG_STRING_BUFFER.equals(name) || CommonClassNames.JAVA_LANG_STRING_BUILDER.equals(name); } return false; }