use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class RemoveExtraClosingTagIntentionAction method doFix.
private static void doFix(@NotNull final PsiElement element) throws IncorrectOperationException {
final XmlToken endNameToken = (XmlToken) element;
final PsiElement tagElement = endNameToken.getParent();
if (!(tagElement instanceof XmlTag) && !(tagElement instanceof PsiErrorElement))
return;
if (tagElement instanceof PsiErrorElement) {
tagElement.delete();
} else {
final ASTNode astNode = tagElement.getNode();
if (astNode != null) {
final ASTNode endTagStart = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(astNode);
if (endTagStart != null) {
final Document document = PsiDocumentManager.getInstance(element.getProject()).getDocument(tagElement.getContainingFile());
if (document != null) {
document.deleteString(endTagStart.getStartOffset(), tagElement.getLastChild().getTextRange().getEndOffset());
}
}
}
}
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class RemoveExtraClosingTagIntentionAction method applyFix.
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
if (!(element instanceof XmlToken))
return;
doFix(element);
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class RenameTagBeginOrEndIntentionAction method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
final int offset = editor.getCaretModel().getOffset();
PsiElement psiElement = file.findElementAt(offset);
if (psiElement == null)
return;
if (psiElement instanceof PsiWhiteSpace)
psiElement = PsiTreeUtil.prevLeaf(psiElement);
if (psiElement instanceof XmlToken) {
final IElementType tokenType = ((XmlToken) psiElement).getTokenType();
if (tokenType != XmlTokenType.XML_NAME) {
if (tokenType == XmlTokenType.XML_TAG_END) {
psiElement = psiElement.getPrevSibling();
if (psiElement == null)
return;
}
}
PsiElement target = null;
final String text = psiElement.getText();
if (!myTargetName.equals(text)) {
target = psiElement;
} else {
// we're in the other
target = findOtherSide(psiElement, myStart);
}
if (target != null) {
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
if (document != null) {
final TextRange textRange = target.getTextRange();
document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), myTargetName);
}
}
}
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class HtmlLocalInspectionTool method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlToken(final XmlToken token) {
IElementType tokenType = token.getTokenType();
if (tokenType == XmlTokenType.XML_NAME || tokenType == XmlTokenType.XML_TAG_NAME) {
PsiElement element = token.getPrevSibling();
while (element instanceof PsiWhiteSpace) element = element.getPrevSibling();
if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_START_TAG_START) {
PsiElement parent = element.getParent();
if (parent instanceof XmlTag && !(token.getNextSibling() instanceof OuterLanguageElement)) {
XmlTag tag = (XmlTag) parent;
checkTag(tag, holder, isOnTheFly);
}
}
}
}
@Override
public void visitXmlAttribute(final XmlAttribute attribute) {
checkAttribute(attribute, holder, isOnTheFly);
}
};
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class XmlWrongClosingTagNameInspection method findEndTagName.
@Nullable
static XmlToken findEndTagName(@Nullable final PsiErrorElement element) {
if (element == null)
return null;
final ASTNode astNode = element.getNode();
if (astNode == null)
return null;
ASTNode current = astNode.getLastChildNode();
ASTNode prev = current;
while (current != null) {
final IElementType elementType = prev.getElementType();
if ((elementType == XmlTokenType.XML_NAME || elementType == XmlTokenType.XML_TAG_NAME) && current.getElementType() == XmlTokenType.XML_END_TAG_START) {
return (XmlToken) prev.getPsi();
}
prev = current;
current = current.getTreePrev();
}
return null;
}
Aggregations