Java Code Examples for com.intellij.lang.ASTFactory#leaf()

The following examples show how to use com.intellij.lang.ASTFactory#leaf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiParserFacadeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public PsiElement createWhiteSpaceFromText(@Nonnull @NonNls String text) throws IncorrectOperationException {
  final FileElement holderElement = DummyHolderFactory.createHolder(myManager, null).getTreeElement();
  final LeafElement newElement = ASTFactory.leaf(TokenType.WHITE_SPACE, holderElement.getCharTable().intern(text));
  holderElement.rawAddChildren(newElement);
  GeneratedMarkerVisitor.markGenerated(newElement.getPsi());
  return newElement.getPsi();
}
 
Example 2
Source File: Factory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LeafElement createSingleLeafElement(@Nonnull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, PsiFile originalFile) {
  DummyHolder dummyHolder = DummyHolderFactory.createHolder(manager, table, type.getLanguage());
  dummyHolder.setOriginalFile(originalFile);

  FileElement holderElement = dummyHolder.getTreeElement();

  LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(
          buffer, startOffset, endOffset));
  holderElement.rawAddChildren(newElement);
  CodeEditUtil.setNodeGenerated(newElement, true);
  return newElement;
}
 
Example 3
Source File: Factory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LeafElement createSingleLeafElement(@Nonnull IElementType type, CharSequence buffer, int startOffset, int endOffset, CharTable table, PsiManager manager, boolean generatedFlag) {
  final FileElement holderElement = DummyHolderFactory.createHolder(manager, table, type.getLanguage()).getTreeElement();
  final LeafElement newElement = ASTFactory.leaf(type, holderElement.getCharTable().intern(
          buffer, startOffset, endOffset));
  holderElement.rawAddChildren(newElement);
  if(generatedFlag) CodeEditUtil.setNodeGenerated(newElement, true);
  return newElement;
}
 
Example 4
Source File: CompositeElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void addLeaf(@Nonnull final IElementType leafType, @Nonnull CharSequence leafText, final ASTNode anchorBefore) {
  FileElement holder = new DummyHolder(getManager(), null).getTreeElement();
  final LeafElement leaf = ASTFactory.leaf(leafType, holder.getCharTable().intern(leafText));
  CodeEditUtil.setNodeGenerated(leaf, true);
  holder.rawAddChildren(leaf);

  addChild(leaf, anchorBefore);
}
 
Example 5
Source File: LeafElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public LeafElement rawReplaceWithText(@Nonnull String newText) {
  LeafElement newLeaf = ASTFactory.leaf(getElementType(), newText);
  copyUserDataTo(newLeaf);
  rawReplaceWithList(newLeaf);
  newLeaf.clearCaches();
  return newLeaf;
}
 
Example 6
Source File: ChangeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LeafElement copyLeafWithText(@Nonnull LeafElement original, @Nonnull String text) {
  LeafElement element = ASTFactory.leaf(original.getElementType(), text);
  original.copyCopyableDataTo(element);
  encodeInformation(element, original);
  TreeUtil.clearCaches(element);
  saveIndentationToCopy(original, element);
  return element;
}
 
Example 7
Source File: SimpleTreePatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public LeafElement split(LeafElement leaf, int offset, final CharTable table) {
  final CharSequence chars = leaf.getChars();
  final LeafElement leftPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, 0, offset));
  final LeafElement rightPart = ASTFactory.leaf(leaf.getElementType(), table.intern(chars, offset, chars.length()));
  leaf.rawInsertAfterMe(leftPart);
  leftPart.rawInsertAfterMe(rightPart);
  leaf.rawRemove();
  return leftPart;
}
 
Example 8
Source File: ParseUtilBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TreeElement createTokenElement(Lexer lexer, CharTable table) {
  IElementType tokenType = lexer.getTokenType();
  if (tokenType == null) {
    return null;
  }
  else if (tokenType instanceof ILazyParseableElementType) {
    return ASTFactory.lazy((ILazyParseableElementType)tokenType, LexerUtil.internToken(lexer, table));
  }
  else {
    return ASTFactory.leaf(tokenType, LexerUtil.internToken(lexer, table));
  }
}
 
Example 9
Source File: PlainTextTokenTypes.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ASTNode parseContents(ASTNode chameleon) {
  return ASTFactory.leaf(PLAIN_TEXT, chameleon.getChars());
}