Java 类com.intellij.psi.impl.source.tree.ForeignLeafPsiElement 实例源码

项目:intellij-ce-playground    文件:DocumentCommitProcessor.java   
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;
}
项目:intellij-ce-playground    文件:LeafPatcher.java   
@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 (leaf.getElementType() == TokenType.WHITE_SPACE && prevElementTail != null) {
    // optimization: put all garbage into whitespace
    leafEncodedText.insert(0, prevElementTail);
    newTexts.remove(prevElement);
    storeUnescapedTextFor(prevElement, null);
  }
  if (!Comparing.equal(leafText, leafEncodedText)) {
    newTexts.put(leaf, leafEncodedText.toString());
    storeUnescapedTextFor(leaf, leafText);
  }
  prevElementTail = StringUtil.startsWith(leafEncodedText, leafText) && leafEncodedText.length() != leafText.length() ?
                    leafEncodedText.substring(leafText.length()) : null;
  prevElement = leaf;
}
项目:tools-idea    文件:LeafPatcher.java   
@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 (leaf.getElementType() == TokenType.WHITE_SPACE && prevElementTail != null) {
    // optimization: put all garbage into whitespace
    leafEncodedText.insert(0, prevElementTail);
    newTexts.remove(prevElement);
    storeUnescapedTextFor(prevElement, null);
  }
  if (!Comparing.equal(leafText, leafEncodedText)) {
    newTexts.put(leaf, leafEncodedText.toString());
    storeUnescapedTextFor(leaf, leafText);
  }
  prevElementTail = StringUtil.startsWith(leafEncodedText, leafText) && leafEncodedText.length() != leafText.length() ?
                    leafEncodedText.substring(leafText.length()) : null;
  prevElement = leaf;
}
项目:consulo    文件:ChangedPsiRangeUtil.java   
private static int getMatchingLength(@Nonnull FileElement treeElement, @Nonnull 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;
}
项目:intellij-ce-playground    文件:PsiVisitors.java   
@Override
public void visitElement(PsiElement element) {
  if (!(element instanceof ForeignLeafPsiElement) && element.isPhysical()) {
    super.visitElement(element);
  }
}
项目:intellij-ce-playground    文件:ForeignLeafType.java   
@Override
@NotNull
public ASTNode createLeafNode(CharSequence leafText) {
  return new ForeignLeafPsiElement(this, getValue());
}
项目:tools-idea    文件:ForeignLeafType.java   
@Override
@NotNull
public ASTNode createLeafNode(CharSequence leafText) {
  return new ForeignLeafPsiElement(this, getValue());
}
项目:consulo    文件:ForeignLeafType.java   
@Override
@Nonnull
public ASTNode createLeafNode(CharSequence leafText) {
  return new ForeignLeafPsiElement(this, getValue());
}