use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class YAMLElementGenerator method createSpace.
@NotNull
public PsiElement createSpace() {
final YAMLKeyValue keyValue = createYamlKeyValue("foo", "bar");
final ASTNode whitespaceNode = keyValue.getNode().findChildByType(TokenType.WHITE_SPACE);
assert whitespaceNode != null;
return whitespaceNode.getPsi();
}
use of com.intellij.lang.ASTNode in project intellij-community by JetBrains.
the class HtmlUnknownElementInspection method registerProblemOnAttributeName.
protected static void registerProblemOnAttributeName(@NotNull XmlAttribute attribute, String message, @NotNull ProblemsHolder holder, LocalQuickFix... quickfixes) {
final ASTNode node = attribute.getNode();
assert node != null;
final ASTNode nameNode = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(node);
if (nameNode != null) {
final PsiElement nameElement = nameNode.getPsi();
if (nameElement.getTextLength() > 0) {
holder.registerProblem(nameElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickfixes);
}
}
}
use of com.intellij.lang.ASTNode 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.lang.ASTNode in project intellij-community by JetBrains.
the class XmlHighlightVisitor method reportAttributeProblem.
@Nullable
private HighlightInfo reportAttributeProblem(final XmlTag tag, final String localName, final XmlAttribute attribute, @NotNull String localizedMessage) {
final RemoveAttributeIntentionFix removeAttributeIntention = new RemoveAttributeIntentionFix(localName, attribute);
if (!(tag instanceof HtmlTag)) {
final HighlightInfoType tagProblemInfoType = HighlightInfoType.WRONG_REF;
final ASTNode node = SourceTreeToPsiMap.psiElementToTree(attribute);
assert node != null;
final ASTNode child = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(node);
assert child != null;
final HighlightInfo highlightInfo = HighlightInfo.newHighlightInfo(tagProblemInfoType).range(child).descriptionAndTooltip(localizedMessage).create();
addToResults(highlightInfo);
QuickFixAction.registerQuickFixAction(highlightInfo, removeAttributeIntention);
return highlightInfo;
}
return null;
}
use of com.intellij.lang.ASTNode 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