use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class XmlParameterInfoHandler method findXmlTag.
@Nullable
private static XmlTag findXmlTag(PsiFile file, int offset) {
if (!(file instanceof XmlFile))
return null;
PsiElement element = file.findElementAt(offset);
if (element == null)
return null;
element = element.getParent();
while (element != null) {
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
final PsiElement[] children = tag.getChildren();
if (offset <= children[0].getTextRange().getStartOffset())
return null;
for (PsiElement child : children) {
final TextRange range = child.getTextRange();
if (range.getStartOffset() <= offset && range.getEndOffset() > offset)
return tag;
if (child instanceof XmlToken) {
XmlToken token = (XmlToken) child;
if (token.getTokenType() == XmlTokenType.XML_TAG_END)
return null;
}
}
return null;
}
element = element.getParent();
}
return null;
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class XmlCDATAContentSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
PsiElement[] children = e.getChildren();
PsiElement first = null;
PsiElement last = null;
for (PsiElement child : children) {
if (child instanceof XmlToken) {
XmlToken token = (XmlToken) child;
if (token.getTokenType() == XmlTokenType.XML_CDATA_START) {
first = token.getNextSibling();
}
if (token.getTokenType() == XmlTokenType.XML_CDATA_END) {
last = token.getPrevSibling();
break;
}
}
}
if (first != null && last != null) {
result.addAll(expandToWholeLine(editorText, new TextRange(first.getTextRange().getStartOffset(), last.getTextRange().getEndOffset()), false));
}
return result;
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class XmlWrongClosingTagNameInspection method annotate.
@Override
public void annotate(@NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) {
if (psiElement instanceof XmlToken) {
final PsiElement parent = psiElement.getParent();
if (parent instanceof XmlTag) {
final XmlTag tag = (XmlTag) parent;
final XmlToken start = XmlTagUtil.getStartTagNameElement(tag);
XmlToken endTagName = XmlTagUtil.getEndTagNameElement(tag);
if (start == psiElement) {
if (endTagName != null && !(tag instanceof HtmlTag) && !tag.getName().equals(endTagName.getText())) {
registerProblemStart(holder, tag, start, endTagName);
} else if (endTagName == null && !(tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag.getName()))) {
final PsiErrorElement errorElement = PsiTreeUtil.getChildOfType(tag, PsiErrorElement.class);
endTagName = findEndTagName(errorElement);
if (endTagName != null) {
registerProblemStart(holder, tag, start, endTagName);
}
}
} else if (endTagName == psiElement) {
if (!(tag instanceof HtmlTag) && !tag.getName().equals(endTagName.getText())) {
registerProblemEnd(holder, tag, endTagName);
}
}
} else if (parent instanceof PsiErrorElement) {
if (XmlTokenType.XML_NAME == ((XmlToken) psiElement).getTokenType()) {
final PsiFile psiFile = psiElement.getContainingFile();
if (psiFile != null && (HTMLLanguage.INSTANCE == psiFile.getViewProvider().getBaseLanguage() || HTMLLanguage.INSTANCE == parent.getLanguage())) {
final String message = XmlErrorMessages.message("xml.parsing.closing.tag.matches.nothing");
if (message.equals(((PsiErrorElement) parent).getErrorDescription()) && psiFile.getContext() == null) {
final Annotation annotation = holder.createWarningAnnotation(parent, message);
annotation.registerFix(new RemoveExtraClosingTagIntentionAction());
}
}
}
}
}
}
use of com.intellij.psi.xml.XmlToken in project intellij-community by JetBrains.
the class XMLExternalAnnotator method addMessagesForTag.
private static void addMessagesForTag(XmlTag tag, String message, Validator.ValidationHost.ErrorType type, AnnotationHolder myHolder, IntentionAction... actions) {
XmlToken childByRole = XmlTagUtil.getStartTagNameElement(tag);
addMessagesForTreeChild(childByRole, type, message, myHolder, actions);
childByRole = XmlTagUtil.getEndTagNameElement(tag);
addMessagesForTreeChild(childByRole, type, message, myHolder, actions);
}
Aggregations