Search in sources :

Example 26 with TreeElement

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

the class CodeEditUtil method removeChildren.

public static void removeChildren(ASTNode parent, @NotNull ASTNode first, @NotNull ASTNode last) {
    final boolean tailingElement = last.getStartOffset() + last.getTextLength() == parent.getStartOffset() + parent.getTextLength();
    final boolean forceReformat = needToForceReformat(parent, first, last);
    saveWhitespacesInfo(first);
    TreeElement child = (TreeElement) first;
    while (child != null) {
        //checkForOuters(child);
        if (child == last)
            break;
        child = child.getTreeNext();
    }
    assert child == last : last + " is not a successor of " + first + " in the .getTreeNext() chain";
    final ASTNode prevLeaf = TreeUtil.prevLeaf(first);
    final ASTNode nextLeaf = TreeUtil.nextLeaf(first);
    parent.removeRange(first, last.getTreeNext());
    ASTNode nextLeafToAdjust = nextLeaf;
    if (nextLeafToAdjust != null && prevLeaf != null && nextLeafToAdjust.getTreeParent() == null) {
        //next element has invalidated
        nextLeafToAdjust = prevLeaf.getTreeNext();
    }
    makePlaceHolderBetweenTokens(prevLeaf, nextLeafToAdjust, forceReformat, tailingElement);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 27 with TreeElement

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

the class PsiFileFactoryImpl method markGenerated.

public static void markGenerated(PsiElement element) {
    final TreeElement node = (TreeElement) element.getNode();
    assert node != null;
    node.acceptTree(new GeneratedMarkerVisitor());
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 28 with TreeElement

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

the class PsiDirectoryImpl method updateAddedFile.

private static void updateAddedFile(@NotNull PsiFile copyPsi) throws IncorrectOperationException {
    final UpdateAddedFileProcessor processor = UpdateAddedFileProcessor.forElement(copyPsi);
    if (processor != null) {
        final TreeElement tree = (TreeElement) SourceTreeToPsiMap.psiElementToTree(copyPsi);
        if (tree != null) {
            ChangeUtil.encodeInformation(tree);
        }
        processor.update(copyPsi, null);
        if (tree != null) {
            ChangeUtil.decodeInformation(tree);
        }
    }
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 29 with TreeElement

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

the class LowLevelSearchUtil method processElementsAtOffsets.

static boolean processElementsAtOffsets(@NotNull PsiElement scope, @NotNull StringSearcher searcher, boolean processInjectedPsi, @NotNull ProgressIndicator progress, int[] offsetsInScope, @NotNull TextOccurenceProcessor processor) {
    if (offsetsInScope.length == 0)
        return true;
    Project project = scope.getProject();
    TreeElement lastElement = null;
    for (int offset : offsetsInScope) {
        progress.checkCanceled();
        lastElement = processTreeUp(project, processor, scope, searcher, offset, processInjectedPsi, progress, lastElement);
        if (lastElement == null)
            return false;
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 30 with TreeElement

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

the class LowLevelSearchUtil method findNextLeafElementAt.

private static TreeElement findNextLeafElementAt(ASTNode scopeNode, TreeElement last, int offset) {
    int offsetR = offset;
    if (last != null) {
        offsetR -= last.getStartOffset() - scopeNode.getStartOffset() + last.getTextLength();
        while (offsetR >= 0) {
            TreeElement next = last.getTreeNext();
            if (next == null) {
                last = last.getTreeParent();
                continue;
            }
            int length = next.getTextLength();
            offsetR -= length;
            last = next;
        }
        scopeNode = last;
        offsetR += scopeNode.getTextLength();
    }
    return (LeafElement) scopeNode.findLeafElementAt(offsetR);
}
Also used : LeafElement(com.intellij.psi.impl.source.tree.LeafElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Aggregations

TreeElement (com.intellij.psi.impl.source.tree.TreeElement)43 ASTNode (com.intellij.lang.ASTNode)12 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)4 PsiElement (com.intellij.psi.PsiElement)3 CompositeElement (com.intellij.psi.impl.source.tree.CompositeElement)3 Nullable (org.jetbrains.annotations.Nullable)3 Document (com.intellij.openapi.editor.Document)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PomModel (com.intellij.pom.PomModel)2 PomTransactionBase (com.intellij.pom.impl.PomTransactionBase)2 XmlAspect (com.intellij.pom.xml.XmlAspect)2 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)2 FileElement (com.intellij.psi.impl.source.tree.FileElement)2 TokenSet (com.intellij.psi.tree.TokenSet)2 CharTable (com.intellij.util.CharTable)2 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 Project (com.intellij.openapi.project.Project)1