Search in sources :

Example 1 with IReparseableLeafElementType

use of com.intellij.psi.tree.IReparseableLeafElementType in project intellij-community by JetBrains.

the class PomModelImpl method tryReparseOneLeaf.

@Nullable
private static Runnable tryReparseOneLeaf(@NotNull FileElement treeElement, @NotNull CharSequence newText, @NotNull TextRange changedPsiRange) {
    final LeafElement leaf = treeElement.findLeafElementAt(changedPsiRange.getStartOffset());
    IElementType leafType = leaf == null ? null : leaf.getElementType();
    if (!(leafType instanceof IReparseableLeafElementType))
        return null;
    CharSequence newLeafText = getLeafChangedText(leaf, treeElement, newText, changedPsiRange);
    //noinspection unchecked
    final ASTNode copy = newLeafText == null ? null : ((IReparseableLeafElementType) leafType).reparseLeaf(leaf, newLeafText);
    return copy == null ? null : () -> leaf.getTreeParent().replaceChild(leaf, copy);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) IReparseableLeafElementType(com.intellij.psi.tree.IReparseableLeafElementType) ASTNode(com.intellij.lang.ASTNode) LeafElement(com.intellij.psi.impl.source.tree.LeafElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ASTNode (com.intellij.lang.ASTNode)1 LeafElement (com.intellij.psi.impl.source.tree.LeafElement)1 IElementType (com.intellij.psi.tree.IElementType)1 IReparseableLeafElementType (com.intellij.psi.tree.IReparseableLeafElementType)1 Nullable (org.jetbrains.annotations.Nullable)1