boolean (PsiElement element) { if (!(element instanceof PsiJavaToken token)) { return false; } @NonNls final String text = element.getText(); if (!PsiKeyword.ELSE.equals(text)) { return false; } final PsiElement parent = token.getParent(); if (!(parent instanceof PsiIfStatement ifStatement)) { return false; } if (ErrorUtil.containsError(ifStatement)) { return false; } final PsiStatement thenBranch = ifStatement.getThenBranch(); final PsiStatement elseBranch = ifStatement.getElseBranch(); if (thenBranch == null) { return false; } if (!(elseBranch instanceof PsiBlockStatement)) { return false; } final PsiCodeBlock block = ((PsiBlockStatement)elseBranch).getCodeBlock(); final PsiStatement[] statements = block.getStatements(); return statements.length == 1 && statements[0] instanceof PsiIfStatement; }