private static boolean isStatementPosition(PsiElement position) { if (PsiTreeUtil.getNonStrictParentOfType(position, PsiLiteralExpression.class, PsiComment.class) != null) { return false; } if (psiElement() .withSuperParent(2, PsiConditionalExpression.class) .andNot(psiElement().insideStarting(psiElement(PsiConditionalExpression.class))) .accepts(position)) { return false; } if (END_OF_BLOCK.getValue().isAcceptable(position, position) && PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, true, PsiMember.class) != null) { return true; } if (psiElement() .withParents( PsiReferenceExpression.class, PsiExpressionStatement.class, PsiIfStatement.class) .andNot(psiElement().afterLeaf(".")) .accepts(position)) { PsiElement stmt = position.getParent().getParent(); PsiIfStatement ifStatement = (PsiIfStatement) stmt.getParent(); if (ifStatement.getElseBranch() == stmt || ifStatement.getThenBranch() == stmt) { return true; } } return false; }