boolean (@NotNull PsiElement statement, @NotNull PsiLocalVariable referent, @NotNull String previousMethodName) { final PsiElement sibling = PsiTreeUtil.getNextSiblingOfType(statement, PsiStatement.class); if (sibling instanceof PsiExpressionStatement expressionStatement) { final PsiExpression siblingExpression = expressionStatement.getExpression(); if (siblingExpression instanceof PsiMethodCallExpression siblingMethodCall) { final PsiExpression qualifier = siblingMethodCall.getMethodExpression().getQualifierExpression(); if (qualifier instanceof PsiReferenceExpression ref && referent.isEquivalentTo(ref.resolve())) { final PsiMethod method = siblingMethodCall.resolveMethod(); if (method != null && method.getName().equals(previousMethodName)) { return true; } } } } return false; }