boolean (Editor editor, PsiFile file, String newName) { final SelectionModel selectionModel = editor.getSelectionModel(); if (!selectionModel.hasSelection()) { return false; } int startOffset = selectionModel.getSelectionStart(); PsiElement start = file.findElementAt(startOffset); if (start instanceof PsiWhiteSpace) { if ((start = PsiTreeUtil.nextLeaf(start)) != null) { startOffset = start.getTextOffset(); } } int endOffset = selectionModel.getSelectionEnd(); PsiElement end = file.findElementAt(endOffset - 1); if (end instanceof PsiWhiteSpace) { if ((end = PsiTreeUtil.prevLeaf(end)) != null) { endOffset = end.getTextRange().getEndOffset(); } } if (start == null || end == null) { return false; } final PsiElement parent = start.getParent(); if (!(parent instanceof XmlTag || parent instanceof XmlComment)) { return false; } if (start == end) { if (start.getTextRange().getStartOffset() != startOffset) { return false; } if (end.getTextRange().getEndOffset() != endOffset) { return false; } if (extractFrom(start, end, newName)) { // tests dislike empty selection selectionModel.removeSelection(); return true; } } else { final XmlElement startTag = PsiTreeUtil.getParentOfType(start, XmlTag.class, XmlComment.class); if (startTag == null) { return false; } if (startTag.getTextRange().getStartOffset() != startOffset) { return false; } final XmlElement endTag = PsiTreeUtil.getParentOfType(end, XmlTag.class, XmlComment.class); if (endTag == null) { return false; } if (endTag.getTextRange().getEndOffset() != endOffset) { return false; } if (startTag != endTag) { if (startTag.getParent() != endTag.getParent()) { return false; } } if (extractFrom(startTag, endTag, newName)) { // tests dislike empty selection selectionModel.removeSelection(); return true; } } return false; }