Search in sources :

Example 36 with LeafElement

use of com.intellij.psi.impl.source.tree.LeafElement in project intellij-community by JetBrains.

the class XmlUtil method expandTag.

public static void expandTag(@NotNull XmlTag tag) {
    XmlTag newTag = XmlElementFactory.getInstance(tag.getProject()).createTagFromText('<' + tag.getName() + "></" + tag.getName() + '>');
    ASTNode node = tag.getNode();
    if (!(node instanceof CompositeElement))
        return;
    CompositeElement compositeElement = (CompositeElement) node;
    final LeafElement emptyTagEnd = (LeafElement) XmlChildRole.EMPTY_TAG_END_FINDER.findChild(compositeElement);
    if (emptyTagEnd == null)
        return;
    compositeElement.removeChild(emptyTagEnd);
    PsiElement[] children = newTag.getChildren();
    compositeElement.addChildren(children[2].getNode(), null, null);
}
Also used : ASTNode(com.intellij.lang.ASTNode) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement) LeafElement(com.intellij.psi.impl.source.tree.LeafElement)

Example 37 with LeafElement

use of com.intellij.psi.impl.source.tree.LeafElement in project intellij-community by JetBrains.

the class XmlTemplateTreePatcher method split.

@Override
public LeafElement split(LeafElement leaf, int offset, final CharTable table) {
    final CharSequence chars = leaf.getChars();
    final LeafElement leftPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, 0, offset));
    final LeafElement rightPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, offset, chars.length()));
    leaf.rawInsertAfterMe(leftPart);
    leftPart.rawInsertAfterMe(rightPart);
    leaf.rawRemove();
    return leftPart;
}
Also used : LeafElement(com.intellij.psi.impl.source.tree.LeafElement)

Example 38 with LeafElement

use of com.intellij.psi.impl.source.tree.LeafElement in project oxy-template-support-plugin by mutant-industries.

the class OxyTemplateInnerJsElementType method convertReferencesToVariables.

private void convertReferencesToVariables(final FileElement root) {
    for (TextRange range : variables.get().pop()) {
        LeafElement elementAt = root.findLeafElementAt(range.getStartOffset());
        CompositeElement parent;
        if (elementAt == null || elementAt.getElementType() != JSTokenTypes.IDENTIFIER || elementAt.getTextLength() != range.getLength() || (parent = elementAt.getTreeParent()).getElementType() != JSElementTypes.REFERENCE_EXPRESSION || (parent = parent.getTreeParent()).getElementType() != JSElementTypes.EXPRESSION_STATEMENT) {
            continue;
        }
        ASTNode replacement = JSChangeUtil.createJSTreeFromText(root.getManager().getProject(), "var " + elementAt.getText());
        replacement.removeRange(replacement.getFirstChildNode(), replacement.getLastChildNode());
        parent.getTreeParent().replaceChild(parent, replacement);
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement) LeafElement(com.intellij.psi.impl.source.tree.LeafElement)

Example 39 with LeafElement

use of com.intellij.psi.impl.source.tree.LeafElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoPsiImplUtil method updateText.

@NotNull
public static GoStringLiteralImpl updateText(@NotNull GoStringLiteral o, @NotNull String text) {
    if (text.length() > 2) {
        if (o.getString() != null) {
            StringBuilder outChars = new StringBuilder();
            GoStringLiteralEscaper.escapeString(text.substring(1, text.length() - 1), outChars);
            outChars.insert(0, '"');
            outChars.append('"');
            text = outChars.toString();
        }
    }
    ASTNode valueNode = o.getNode().getFirstChildNode();
    assert valueNode instanceof LeafElement;
    ((LeafElement) valueNode).replaceWithText(text);
    return (GoStringLiteralImpl) o;
}
Also used : ASTNode(com.intellij.lang.ASTNode) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with LeafElement

use of com.intellij.psi.impl.source.tree.LeafElement in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoExpressionUtil method isOperatorEquals.

private static boolean isOperatorEquals(@Nullable PsiElement l, @Nullable PsiElement r) {
    if (l == null || r == null)
        return false;
    ASTNode lNode = l.getNode();
    ASTNode rNode = r.getNode();
    return lNode instanceof LeafElement && lNode.getElementType().equals(rNode.getElementType());
}
Also used : ASTNode(com.intellij.lang.ASTNode) LeafElement(com.intellij.psi.impl.source.tree.LeafElement)

Aggregations

LeafElement (com.intellij.psi.impl.source.tree.LeafElement)41 ASTNode (com.intellij.lang.ASTNode)15 PsiElement (com.intellij.psi.PsiElement)9 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)6 TreeElement (com.intellij.psi.impl.source.tree.TreeElement)4 IElementType (com.intellij.psi.tree.IElementType)4 PsiFragment (com.intellij.dupLocator.util.PsiFragment)3 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)3 FileElement (com.intellij.psi.impl.source.tree.FileElement)3 EquivalenceDescriptorProvider (com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)2 CharTable (com.intellij.util.CharTable)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)1