PsiReturnStatement (PsiStatement statement) { while (true) { PsiElement nextStatement = PsiTreeUtil.skipWhitespacesAndCommentsForward(statement); if (nextStatement instanceof PsiReturnStatement) return (PsiReturnStatement)nextStatement; PsiElement parent = statement.getParent(); if (parent instanceof PsiCodeBlock) { PsiStatement[] statements = ((PsiCodeBlock)parent).getStatements(); if (statements.length == 0 || statements[statements.length - 1] != statement) return null; parent = parent.getParent(); } if (!(parent instanceof PsiIfStatement) && !(parent instanceof PsiBlockStatement)) return null; statement = (PsiStatement)parent; } }