alternatively chameleoned code blocks and file elements
[fedora-idea.git] / lang-impl / src / com / intellij / psi / impl / source / tree / AstBufferUtil.java
blobacd767f1bdca93d732bcc0c3041919a574eca089
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);
22 if (element instanceof LazyParseableElement) {
23 LazyParseableElement lpe = (LazyParseableElement)element;
24 int lpeResult = lpe.copyTo(buffer, offset);
25 if (lpeResult > 0) return lpeResult;
28 int curOffset = offset;
29 for (TreeElement child = (TreeElement)element.getFirstChildNode(); child != null; child = child.getTreeNext()) {
30 curOffset = toBuffer(child, buffer, curOffset, skipTypes);
32 return curOffset;