Search in sources :

Example 1 with ForeignLeafPsiElement

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

the class LeafPatcher method visitLeaf.

@Override
public void visitLeaf(LeafElement leaf) {
    String leafText = leaf instanceof ForeignLeafPsiElement ? "" : leaf.getText();
    catLeafs.append(leafText);
    final TextRange leafRange = leaf.getTextRange();
    StringBuilder leafEncodedText = constructTextFromHostPSI(leafRange.getStartOffset(), leafRange.getEndOffset());
    if (!Comparing.equal(leafText, leafEncodedText)) {
        newTexts.put(leaf, leafEncodedText.toString());
        storeUnescapedTextFor(leaf, leafText);
    }
}
Also used : ForeignLeafPsiElement(com.intellij.psi.impl.source.tree.ForeignLeafPsiElement) TextRange(com.intellij.openapi.util.TextRange)

Example 2 with ForeignLeafPsiElement

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

the class DocumentCommitThread method getMatchingLength.

private static int getMatchingLength(@NotNull FileElement treeElement, @NotNull CharSequence text, boolean fromStart) {
    int patternIndex = fromStart ? 0 : text.length() - 1;
    int finalPatternIndex = fromStart ? text.length() - 1 : 0;
    int direction = fromStart ? 1 : -1;
    ASTNode leaf = fromStart ? TreeUtil.findFirstLeaf(treeElement, false) : TreeUtil.findLastLeaf(treeElement, false);
    int result = 0;
    while (leaf != null && (fromStart ? patternIndex <= finalPatternIndex : patternIndex >= finalPatternIndex)) {
        if (!(leaf instanceof ForeignLeafPsiElement)) {
            CharSequence chars = leaf.getChars();
            if (chars.length() > 0) {
                int matchingLength = getLeafMatchingLength(chars, text, patternIndex, finalPatternIndex, direction);
                result += matchingLength;
                if (matchingLength != chars.length()) {
                    break;
                }
                patternIndex += fromStart ? matchingLength : -matchingLength;
            }
        }
        leaf = fromStart ? TreeUtil.nextLeaf(leaf, false) : TreeUtil.prevLeaf(leaf, false);
    }
    return result;
}
Also used : FileASTNode(com.intellij.lang.FileASTNode) ASTNode(com.intellij.lang.ASTNode) ForeignLeafPsiElement(com.intellij.psi.impl.source.tree.ForeignLeafPsiElement)

Aggregations

ForeignLeafPsiElement (com.intellij.psi.impl.source.tree.ForeignLeafPsiElement)2 ASTNode (com.intellij.lang.ASTNode)1 FileASTNode (com.intellij.lang.FileASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1