boolean (PsiStatement stmt, PsiElement elementAtCaret, PsiInstanceOfExpression instanceOfExpression) { PsiBlockStatement block = PsiTreeUtil.getParentOfType(elementAtCaret, PsiBlockStatement.class); if (block != null && block.getParent() == stmt) { final PsiStatement[] statements = block.getCodeBlock().getStatements(); if (statements.length == 0) { return true; } if (statements.length == 1 && statements[0] instanceof PsiExpressionStatement) { return replaceReference(instanceOfExpression, (PsiExpressionStatement)statements[0]); } } return false; }