@Override public boolean satisfiedBy(@NotNull PsiElement element) { if (!(element instanceof JSStatement)) { return false; } if (element instanceof JSBlockStatement) { return false; } final PsiElement parentElement = element.getParent(); if (!(parentElement instanceof JSElement)) return false; final JSElement parent = (JSElement) parentElement; if (parent instanceof JSIfStatement) { final JSIfStatement ifStatement = (JSIfStatement) parent; return (!(element instanceof JSIfStatement && element.equals(ifStatement.getElse()))); } if (parent instanceof JSForStatement || parent instanceof JSForInStatement) { return element.equals(((JSLoopStatement) parent).getBody()); } return (parent instanceof JSWhileStatement || parent instanceof JSDoWhileStatement); }
@Override protected String getTextForElement(PsiElement element) { final JSElement parent = (JSElement) element.getParent(); final String keyword; assert (parent != null); if (parent instanceof JSIfStatement) { final JSIfStatement ifStatement = (JSIfStatement) parent; final JSStatement elseBranch = ifStatement.getElse(); keyword = (element.equals(elseBranch) ? ELSE_KEYWORD : IF_KEYWORD); } else { final PsiElement firstChild = parent.getFirstChild(); assert (firstChild != null); keyword = firstChild.getText(); } return this.getText(keyword); }