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
);