示例#1
0
 public LeafElement rawReplaceWithText(String newText) {
   LeafElement newLeaf = ASTFactory.leaf(getElementType(), newText);
   copyUserDataTo(newLeaf);
   rawReplaceWithList(newLeaf);
   newLeaf.clearCaches();
   return newLeaf;
 }
  public static void replaceLastWhiteSpace(
      final ASTNode astNode, final String whiteSpace, final TextRange textRange) {
    ASTNode lastWS = TreeUtil.findLastLeaf(astNode);
    if (lastWS == null) {
      return;
    }
    if (lastWS.getElementType() != TokenType.WHITE_SPACE) {
      lastWS = null;
    }
    if (lastWS != null && !lastWS.getTextRange().equals(textRange)) {
      return;
    }
    if (whiteSpace.isEmpty() && lastWS == null) {
      return;
    }
    if (lastWS != null && whiteSpace.isEmpty()) {
      lastWS.getTreeParent().removeRange(lastWS, null);
      return;
    }

    LeafElement whiteSpaceElement = ASTFactory.whitespace(whiteSpace);

    if (lastWS == null) {
      astNode.addChild(whiteSpaceElement, null);
    } else {
      ASTNode treeParent = lastWS.getTreeParent();
      treeParent.replaceChild(lastWS, whiteSpaceElement);
    }
  }
示例#3
0
  @NotNull
  protected FileElement createFileElement(CharSequence docText) {
    final FileElement treeElement;
    final TreeElement contentLeaf = createContentLeafElement(docText);

    if (contentLeaf instanceof FileElement) {
      treeElement = (FileElement) contentLeaf;
    } else {
      final CompositeElement xxx = ASTFactory.composite(myElementType);
      assert xxx instanceof FileElement : "BUMM";
      treeElement = (FileElement) xxx;
      treeElement.rawAddChildrenWithoutNotifications(contentLeaf);
    }

    return treeElement;
  }
示例#4
0
 public TreeElement createContentLeafElement(CharSequence leafText) {
   if (myContentElementType instanceof ILazyParseableElementType) {
     return ASTFactory.lazy((ILazyParseableElementType) myContentElementType, leafText);
   }
   return ASTFactory.leaf(myContentElementType, leafText);
 }
 @Override
 public ASTNode parseContents(ASTNode chameleon) {
   final CharSequence chars = chameleon.getChars();
   return ASTFactory.leaf(PlainTextTokenTypes.PLAIN_TEXT, chars);
 }