Search in sources :

Example 11 with CompositeElement

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

the class JavaStubPsiElement method deleteChildRange.

@Override
public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    if (first == null) {
        LOG.assertTrue(last == null);
        return;
    }
    ASTNode firstElement = SourceTreeToPsiMap.psiElementToTree(first);
    ASTNode lastElement = SourceTreeToPsiMap.psiElementToTree(last);
    CompositeElement treeElement = calcTreeElement();
    LOG.assertTrue(firstElement.getTreeParent() == treeElement);
    LOG.assertTrue(lastElement.getTreeParent() == treeElement);
    CodeEditUtil.removeChildren(treeElement, firstElement, lastElement);
}
Also used : ASTNode(com.intellij.lang.ASTNode) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 12 with CompositeElement

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

the class JavaStubPsiElement method subtreeChanged.

@Override
public void subtreeChanged() {
    final CompositeElement compositeElement = calcTreeElement();
    if (compositeElement != null)
        compositeElement.clearCaches();
    super.subtreeChanged();
}
Also used : CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 13 with CompositeElement

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

the class AstPathPsiMap method switchToStrongRefs.

void switchToStrongRefs() {
    myQueue.cleanupStaleReferences();
    for (MyReference reference : myMap.values()) {
        StubBasedPsiElementBase<?> psi = SoftReference.dereference(reference);
        if (psi != null) {
            CompositeElement node = (CompositeElement) psi.getNode();
            node.setPsi(psi);
            psi.setSubstrateRef(SubstrateRef.createAstStrongRef(node));
        }
    }
    myMap.clear();
}
Also used : CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

Example 14 with CompositeElement

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

the class TreeChangeEventImpl method compactChanges.

private void compactChanges(ASTNode parent, int depth) {
    int currentDepth = myOfEqualDepth.size();
    while (--currentDepth > depth) {
        final Set<ASTNode> treeElements = myOfEqualDepth.get(currentDepth);
        if (treeElements == null)
            continue;
        final Iterator<ASTNode> iterator = treeElements.iterator();
        while (iterator.hasNext()) {
            boolean isUnderCompacted = false;
            final TreeElement treeElement = (TreeElement) iterator.next();
            ASTNode currentParent = treeElement;
            while (currentParent != null) {
                if (currentParent == parent) {
                    isUnderCompacted = true;
                    break;
                }
                currentParent = currentParent.getTreeParent();
            }
            if (isUnderCompacted) {
                final ChangeInfoImpl compactedChange = ChangeInfoImpl.create(ChangeInfo.CONTENTS_CHANGED, treeElement);
                compactedChange.compactChange(getChangesByElement(treeElement));
                iterator.remove();
                removeAssociatedChanges(treeElement, currentDepth);
                final CompositeElement treeParent = treeElement.getTreeParent();
                final TreeChange changesByElement = getChangesByElement(treeParent);
                if (changesByElement != null) {
                    final ChangeInfoImpl changeByChild = (ChangeInfoImpl) changesByElement.getChangeByChild(treeElement);
                    if (changeByChild != null) {
                        changeByChild.setOldLength(compactedChange.getOldLength());
                    } else {
                        changesByElement.addChange(treeElement, compactedChange);
                    }
                } else {
                    processElementaryChange(treeParent, treeElement, compactedChange, currentDepth - 1);
                }
            }
        }
    }
}
Also used : TreeChange(com.intellij.pom.tree.events.TreeChange) ASTNode(com.intellij.lang.ASTNode) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 15 with CompositeElement

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

the class DebugUtil method treeToBuffer.

public static void treeToBuffer(@NotNull final Appendable buffer, @NotNull final ASTNode root, final int indent, final boolean skipWhiteSpaces, final boolean showRanges, final boolean showChildrenRanges, final boolean usePsi, @Nullable PairConsumer<PsiElement, Consumer<PsiElement>> extra) {
    if (skipWhiteSpaces && root.getElementType() == TokenType.WHITE_SPACE)
        return;
    StringUtil.repeatSymbol(buffer, ' ', indent);
    try {
        PsiElement psiElement = null;
        if (root instanceof CompositeElement) {
            if (usePsi) {
                psiElement = root.getPsi();
                if (psiElement != null) {
                    buffer.append(psiElement.toString());
                } else {
                    buffer.append(root.getElementType().toString());
                }
            } else {
                buffer.append(root.toString());
            }
        } else {
            final String text = fixWhiteSpaces(root.getText());
            buffer.append(root.toString()).append("('").append(text).append("')");
        }
        if (showRanges)
            buffer.append(root.getTextRange().toString());
        buffer.append("\n");
        if (root instanceof CompositeElement) {
            ASTNode child = root.getFirstChildNode();
            if (child == null) {
                StringUtil.repeatSymbol(buffer, ' ', indent + 2);
                buffer.append("<empty list>\n");
            } else {
                while (child != null) {
                    treeToBuffer(buffer, child, indent + 2, skipWhiteSpaces, showChildrenRanges, showChildrenRanges, usePsi, extra);
                    child = child.getTreeNext();
                }
            }
        }
        if (psiElement != null && extra != null) {
            extra.consume(psiElement, element -> treeToBuffer(buffer, element.getNode(), indent + 2, skipWhiteSpaces, showChildrenRanges, showChildrenRanges, usePsi, null));
        }
    } catch (IOException e) {
        LOG.error(e);
    }
}
Also used : LighterASTNode(com.intellij.lang.LighterASTNode) ASTNode(com.intellij.lang.ASTNode) IOException(java.io.IOException) CompositeElement(com.intellij.psi.impl.source.tree.CompositeElement)

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