@@ -0,0 +1,2272 @@
+/*%0A * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.%0A */%0A%0Apackage com.intellij.formatting;%0A%0Aimport org.jdom.Element;%0A%0Aimport java.util.List;%0A%0Apublic class FormatInfoPrinter %7B%0A  private final Block myRootBlock;%0A  private final FormattingDocumentModel myDocumentModel;%0A%0A%0A  public FormatInfoPrinter(final Block rootBlock, final FormattingDocumentModel documentModel) %7B%0A    myRootBlock = rootBlock;%0A    myDocumentModel = documentModel;%0A  %7D%0A%0A  public Element blocksAsTree()%7B%0A    return createBlockElement(myRootBlock);%0A  %7D%0A%0A  private Element createBlockElement(final Block block) %7B%0A    final Element result = new Element(getBlockElementName(block));%0A    printSimpleBlock(block, result);%0A    final List%3CBlock%3E subBlocks = block.getSubBlocks();%0A    for (int i = 0; i %3C subBlocks.size(); i++) %7B%0A      if (i %3E 0 && i %3C subBlocks.size() - 1) %7B%0A        result.addContent(createSpacingElement(block.getSpacing(subBlocks.get(i), subBlocks.get(i+1))));        %0A      %7D%0A      result.addContent(createBlockElement(subBlocks.get(i)));%0A    %7D%0A    %0A    return result;%0A  %7D%0A%0A  private Element createSpacingElement(final Spacing spacing) %7B%0A    final Element result = new Element(%22Spacing%22);%0A    final SpacingImpl impl = ((SpacingImpl)spacing);%0A    return result;%0A  %7D%0A%0A  private String getBlockElementName(final Block block) %7B%0A    return block.getSubBlocks().size() %3E 0 ? %22CompositeBlock%22 : %22LeafBlock%22;%0A  %7D%0A%0A  private void printSimpleBlock(final Block block, Element element) %7B%0A    if (block.getSubBlocks().size() == 0) %7B%0A      element.setAttribute(%22text%22, myDocumentModel.getText(block.getTextRange()).toString());%0A    %7D%0A    %0A    element.setAttribute(%22wrap%22, wrapAsString(block.getWrap()));%0A    if (block.getAlignment() != null) %7B%0A      element.setAttribute(%22align%22, ((AlignmentImpl)block.getAlignment()).getId());%0A    %7D%0A  %7D%0A%0A  private String wrapAsString(final Wrap wrap) %7B%0A    if (wrap == null) return %22null%22;%0A    final WrapImpl impl = ((WrapImpl)wrap);%0A    StringBuffer result = new StringBuffer();%0A    result.append(impl.getType().toString()).append(%22 %22).append(impl.getId());%0A    if (impl.isWrapFirstElement()) %7B%0A      result.append(%22 wrapFirst%22);%0A    %7D%0A    if (impl.getIgnoreParentWraps()) %7B%0A      result.append(%22 ignoreParents%22);%0A    %7D%0A    return result.toString();%0A  %7D%0A%7D%0A

format tree printer