Make mutating methods of TreeUtil/ChangeUtil be a member of data structures they...
[fedora-idea.git] / lang-impl / src / com / intellij / psi / impl / source / tree / AstBufferUtil.java
blob2b93269252083f841e8b7541fb2af3766d3d5d6b
1 /*
2 * @author max
3 */
4 package com.intellij.psi.impl.source.tree;
6 import com.intellij.lang.ASTNode;
7 import com.intellij.psi.tree.TokenSet;
9 public class AstBufferUtil {
10 private AstBufferUtil() {}
12 public static int toBuffer(ASTNode element, char[] buffer, int offset) {
13 return toBuffer(element, buffer, offset, null);
16 public static int toBuffer(ASTNode element, char[] buffer, int offset, TokenSet skipTypes) {
17 if (element instanceof ForeignLeafPsiElement || skipTypes != null && skipTypes.contains(element.getElementType())) return offset;
18 if (element instanceof LeafElement) {
19 return ((LeafElement)element).copyTo(buffer, offset);
21 int curOffset = offset;
22 for (TreeElement child = (TreeElement)element.getFirstChildNode(); child != null; child = child.getTreeNext()) {
23 curOffset = toBuffer(child, buffer, curOffset, skipTypes);
25 return curOffset;