Search in sources :

Example 11 with ASTNode

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();
}
Also used : YAMLKeyValue(org.jetbrains.yaml.psi.YAMLKeyValue) ASTNode(com.intellij.lang.ASTNode) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with ASTNode

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);
        }
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) PsiElement(com.intellij.psi.PsiElement)

Example 13 with ASTNode

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());
                }
            }
        }
    }
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) ASTNode(com.intellij.lang.ASTNode) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Example 14 with ASTNode

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;
}
Also used : ASTNode(com.intellij.lang.ASTNode) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) HtmlTag(com.intellij.psi.html.HtmlTag) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with ASTNode

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ASTNode(com.intellij.lang.ASTNode) XmlToken(com.intellij.psi.xml.XmlToken) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ASTNode (com.intellij.lang.ASTNode)839 NotNull (org.jetbrains.annotations.NotNull)154 PsiElement (com.intellij.psi.PsiElement)152 IElementType (com.intellij.psi.tree.IElementType)152 Nullable (org.jetbrains.annotations.Nullable)113 TextRange (com.intellij.openapi.util.TextRange)97 ArrayList (java.util.ArrayList)60 PsiFile (com.intellij.psi.PsiFile)36 IncorrectOperationException (com.intellij.util.IncorrectOperationException)35 Annotation (com.intellij.lang.annotation.Annotation)25 AbstractBlock (com.intellij.psi.formatter.common.AbstractBlock)22 CharTable (com.intellij.util.CharTable)22 FileASTNode (com.intellij.lang.FileASTNode)20 FoldingDescriptor (com.intellij.lang.folding.FoldingDescriptor)20 Document (com.intellij.openapi.editor.Document)20 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)18 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)18 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)18 Project (com.intellij.openapi.project.Project)17 XmlTag (com.intellij.psi.xml.XmlTag)17