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);
}
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);
}
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);
}
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);
}
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");
}
Aggregations