Search in sources :

Example 11 with TreeElement

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

the class JavaStubPsiElement method addBefore.

@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(element);
    calcTreeElement().addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.TRUE);
    elementCopy = ChangeUtil.decodeInformation(elementCopy);
    return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 12 with TreeElement

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

the class JavaStubPsiElement method add.

@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(element);
    calcTreeElement().addInternal(elementCopy, elementCopy, null, null);
    elementCopy = ChangeUtil.decodeInformation(elementCopy);
    return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 13 with TreeElement

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

the class JavaStubPsiElement method addAfter.

@Override
public PsiElement addAfter(@NotNull PsiElement element, @Nullable PsiElement anchor) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(element);
    calcTreeElement().addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.FALSE);
    elementCopy = ChangeUtil.decodeInformation(elementCopy);
    return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
Also used : TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 14 with TreeElement

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

the class MultiHostRegistrarImpl method patchLeaves.

private static void patchLeaves(@NotNull ASTNode parsedNode, @NotNull List<LiteralTextEscaper<? extends PsiLanguageInjectionHost>> escapers, @NotNull Place shreds) {
    LeafPatcher patcher = new LeafPatcher(shreds, escapers);
    ((TreeElement) parsedNode).acceptTree(patcher);
    assert ((TreeElement) parsedNode).textMatches(patcher.catLeafs) : "Malformed PSI structure: leaf texts do not add up to the whole file text." + "\nFile text (from tree)  :'" + parsedNode.getText() + "'" + "\nFile text (from PSI)   :'" + parsedNode.getPsi().getText() + "'" + "\nLeaf texts concatenated:'" + patcher.catLeafs + "';" + "\nFile root: " + parsedNode + "\nLanguage: " + parsedNode.getPsi().getLanguage() + "\nHost file: " + shreds.getHostPointer().getVirtualFile();
    DebugUtil.startPsiModification("injection leaf patching");
    try {
        for (Map.Entry<LeafElement, String> entry : patcher.newTexts.entrySet()) {
            LeafElement leaf = entry.getKey();
            String newText = entry.getValue();
            leaf.rawReplaceWithText(newText);
        }
    } finally {
        DebugUtil.finishPsiModification();
    }
    TreeUtil.clearCaches((TreeElement) parsedNode);
}
Also used : Map(java.util.Map) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Example 15 with TreeElement

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

the class ASTDelegatePsiElement method addInnerBefore.

private PsiElement addInnerBefore(final PsiElement element, final PsiElement anchor) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    TreeElement elementCopy = ChangeUtil.copyToElement(element);
    ASTNode treeElement = addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.TRUE);
    if (treeElement != null) {
        if (treeElement instanceof TreeElement) {
            return ChangeUtil.decodeInformation((TreeElement) treeElement).getPsi();
        }
        return treeElement.getPsi();
    }
    throw new IncorrectOperationException("Element cannot be added");
}
Also used : ASTNode(com.intellij.lang.ASTNode) IncorrectOperationException(com.intellij.util.IncorrectOperationException) 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