Occurrence (@NotNull PsiExpressionStatement statement, @Nullable PsiVariable variable) { if (variable == null) return null; final PsiElement parent = PsiTreeUtil.getParentOfType(statement, PsiCodeBlock.class, PsiLambdaExpression.class); if (parent instanceof PsiCodeBlock) { final PsiStatement prevStatement = PsiTreeUtil.getPrevSiblingOfType(statement, PsiStatement.class); final PsiStatement nextStatement = PsiTreeUtil.getNextSiblingOfType(statement, PsiStatement.class); if (prevStatement instanceof PsiExpressionStatement || nextStatement instanceof PsiExpressionStatement) { final ControlFlow flow = getControlFlow(parent); if (prevStatement instanceof PsiExpressionStatement) { final PsiReferenceExpression prevOccurrence = ControlFlowUtil.findSingleReadOccurrence(flow, prevStatement, variable); if (prevOccurrence != null) { return new Occurrence(prevOccurrence, true); } } if (nextStatement instanceof PsiExpressionStatement) { final PsiReferenceExpression nextOccurrence = ControlFlowUtil.findSingleReadOccurrence(flow, nextStatement, variable); if (nextOccurrence != null) { return new Occurrence(nextOccurrence, false); } } } } return null; }