// XXX make it only caret position sensitive for now private Node findCurrentElement() { Node root = getParserResult().getParseTree(); int astOffset = getParserResult().getSnapshot().getEmbeddedOffset(caretOffset); Node leaf = NodeUtil.findNodeAtOffset(root, astOffset); if (leaf != null) { // we found token node, use its encolosing node - parent leaf = leaf.parent(); } // if leaf == null the astOffset is out of the root's node range, return the root node return leaf == null ? root : leaf; }
@Override public boolean isRefactoringAllowed() { // class, id or element selector // hex color return NodeUtil.isSelectorNode(getElement()) || getElement().type() == NodeType.hexColor; }