Search in sources :

Example 1 with CompositeElement

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

the class CDATAOnAnyEncodedPolicy method createCDATAElement.

@SuppressWarnings({ "HardCodedStringLiteral" })
public static FileElement createCDATAElement(final PsiManager manager, final CharTable charTableByTree, final String displayText) {
    final FileElement dummyParent = DummyHolderFactory.createHolder(manager, null, charTableByTree).getTreeElement();
    final CompositeElement cdata = ASTFactory.composite(XmlElementType.XML_CDATA);
    dummyParent.rawAddChildren(cdata);
    cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_START, "<![CDATA["));
    cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_DATA_CHARACTERS, dummyParent.getCharTable().intern(displayText)));
    cdata.rawAddChildren(ASTFactory.leaf(XmlTokenType.XML_CDATA_END, "]]>"));
    dummyParent.acceptTree(new GeneratedMarkerVisitor());
    return dummyParent;
}
Also used : GeneratedMarkerVisitor(com.intellij.psi.impl.GeneratedMarkerVisitor) FileElement(com.intellij.psi.impl.source.tree.FileElement) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 2 with CompositeElement

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

the class GroovySpacingProcessor method _init.

private void _init(@Nullable final ASTNode child) {
    if (child == null)
        return;
    ASTNode treePrev = child.getTreePrev();
    while (treePrev != null && isWhiteSpace(treePrev)) {
        treePrev = treePrev.getTreePrev();
    }
    if (treePrev == null) {
        _init(child.getTreeParent());
    } else {
        myChild2 = child;
        myType2 = myChild2.getElementType();
        myChild1 = treePrev;
        myType1 = myChild1.getElementType();
        final CompositeElement parent = (CompositeElement) treePrev.getTreeParent();
        myParent = SourceTreeToPsiMap.treeElementToPsi(parent);
    }
}
Also used : ASTNode(com.intellij.lang.ASTNode) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 3 with CompositeElement

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

the class HtmlFileImpl method getDocument.

@Override
public XmlDocument getDocument() {
    CompositeElement treeElement = calcTreeElement();
    ASTNode node = treeElement.findChildByType(XmlElementType.HTML_DOCUMENT);
    return node != null ? (XmlDocument) node.getPsi() : null;
}
Also used : ASTNode(com.intellij.lang.ASTNode) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 4 with CompositeElement

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

the class XmlProcessingInstructionManipulator method handleContentChange.

@Override
public XmlProcessingInstruction handleContentChange(@NotNull XmlProcessingInstruction element, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
    CheckUtil.checkWritable(element);
    final CompositeElement attrNode = (CompositeElement) element.getNode();
    final ASTNode valueNode = attrNode.findLeafElementAt(range.getStartOffset());
    LOG.assertTrue(valueNode != null, "Leaf not found in " + attrNode + " at offset " + range.getStartOffset() + " in element " + element);
    final PsiElement elementToReplace = valueNode.getPsi();
    String text;
    try {
        text = elementToReplace.getText();
        final int offsetInParent = elementToReplace.getStartOffsetInParent();
        String textBeforeRange = text.substring(0, range.getStartOffset() - offsetInParent);
        String textAfterRange = text.substring(range.getEndOffset() - offsetInParent, text.length());
        newContent = element.getText().startsWith("'") || element.getText().endsWith("'") ? newContent.replace("'", "&apos;") : newContent.replace("\"", "&quot;");
        text = textBeforeRange + newContent + textAfterRange;
    } catch (StringIndexOutOfBoundsException e) {
        LOG.error("Range: " + range + " in text: '" + element.getText() + "'", e);
        throw e;
    }
    final CharTable charTableByTree = SharedImplUtil.findCharTableByTree(attrNode);
    final LeafElement newValueElement = Factory.createSingleLeafElement(XmlTokenType.XML_TAG_CHARACTERS, text, charTableByTree, element.getManager());
    attrNode.replaceChildInternal(valueNode, newValueElement);
    return element;
}
Also used : ASTNode(com.intellij.lang.ASTNode) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement) CharTable(com.intellij.util.CharTable) PsiElement(com.intellij.psi.PsiElement) LeafElement(com.intellij.psi.impl.source.tree.LeafElement)

Example 5 with CompositeElement

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

the class ASTDelegatePsiElement method getChildren.

@Override
@NotNull
public PsiElement[] getChildren() {
    PsiElement psiChild = getFirstChild();
    if (psiChild == null)
        return PsiElement.EMPTY_ARRAY;
    List<PsiElement> result = new ArrayList<>();
    while (psiChild != null) {
        if (psiChild.getNode() instanceof CompositeElement) {
            result.add(psiChild);
        }
        psiChild = psiChild.getNextSibling();
    }
    return PsiUtilCore.toPsiElementArray(result);
}
Also used : ArrayList(java.util.ArrayList) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)30 ASTNode (com.intellij.lang.ASTNode)15 PsiElement (com.intellij.psi.PsiElement)6 IElementType (com.intellij.psi.tree.IElementType)5 TreeElement (com.intellij.psi.impl.source.tree.TreeElement)3 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 GrReferenceElement (org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement)2 Wrap (com.intellij.formatting.Wrap)1 LighterASTNode (com.intellij.lang.LighterASTNode)1 JSTreeUtil (com.intellij.lang.javascript.psi.util.JSTreeUtil)1 Project (com.intellij.openapi.project.Project)1 TextRange (com.intellij.openapi.util.TextRange)1 TreeChange (com.intellij.pom.tree.events.TreeChange)1 PsiFile (com.intellij.psi.PsiFile)1 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)1 PsiLanguageInjectionHost (com.intellij.psi.PsiLanguageInjectionHost)1 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)1