Clover coverage report - ATP library for Java - 3.6.4-stable-060214
Coverage timestamp: Вт фев 14 2006 13:45:22 MSK
file stats: LOC: 239   Methods: 20
NCLOC: 163   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TreePrinter.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Copyright (c) 2001-2004,
 3    * RedVerst Group, ISP RAS http://www.ispras.ru
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    *
 9    * 1. Redistributions of source code must retain the above copyright notice, this
 10    * list of conditions and the following disclaimer.
 11    *
 12    * 2. Redistributions in binary form must reproduce the above copyright notice,
 13    * this list of conditions and the following disclaimer in the documentation
 14    * and/or other materials provided with the distribution.
 15    *
 16    * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS"
 17    * may not be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 21    * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 22    * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 23    * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 24    * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 25    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 26    * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 27    * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 29    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30    */
 31    package com.unitesk.atp.tree;
 32   
 33    import java.io.File;
 34    import java.io.FileWriter;
 35    import java.io.IOException;
 36    import java.io.Writer;
 37    import java.util.Iterator;
 38    import java.util.List;
 39   
 40    import com.unitesk.atp.dynattrs.Accessor;
 41    import com.unitesk.atp.text.filters.ExceptionHandler;
 42    import com.unitesk.atp.text.filters.IndentFilter;
 43    import com.unitesk.atp.text.filters.WriterTextReceiver;
 44   
 45    /**
 46    * Dump tree structure for debugging
 47    *
 48    * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
 49    * @version $Id: TreePrinter.java,v 1.4 2005/11/30 10:06:18 all-x Exp $
 50    */
 51    public class TreePrinter
 52    {
 53    protected Writer writer;
 54    protected IndentFilter indentFilter;
 55    protected ExceptionHandler exceptionHandler;
 56   
 57  0 public static TreePrinter create( String file, ExceptionHandler exceptionHandler )
 58    {
 59  0 return create( new File( file ), exceptionHandler );
 60    }
 61   
 62  0 public static
 63    TreePrinter create( String file, ExceptionHandler exceptionHandler, int indentStep )
 64    {
 65  0 return create( new File( file ), exceptionHandler, indentStep );
 66    }
 67   
 68  0 public static TreePrinter create( File file, ExceptionHandler exceptionHandler )
 69    {
 70  0 return create( file, exceptionHandler, IndentFilter.DEFAULT_INDENT_STEP );
 71    }
 72   
 73  0 public static TreePrinter create( File file, ExceptionHandler exceptionHandler, int indentStep )
 74    {
 75  0 try
 76    {
 77  0 return create( new FileWriter( file.getCanonicalPath() )
 78    , exceptionHandler
 79    , indentStep
 80    );
 81    }
 82    catch( IOException e )
 83    {
 84  0 exceptionHandler.process( e );
 85  0 return null;
 86    }
 87    }
 88   
 89  0 public static TreePrinter create( Writer writer
 90    , ExceptionHandler exceptionHandler
 91    )
 92    {
 93  0 return create( writer, exceptionHandler, IndentFilter.DEFAULT_INDENT_STEP );
 94    }
 95   
 96  0 public static TreePrinter create( Writer writer
 97    , ExceptionHandler exceptionHandler
 98    , int indentStep
 99    )
 100    {
 101  0 return new TreePrinter( writer, exceptionHandler, indentStep );
 102    }
 103   
 104    /**
 105    * Close output stream
 106    */
 107  0 public void close()
 108    {
 109  0 try
 110    {
 111  0 writer.close();
 112    }
 113    catch( IOException e )
 114    {
 115  0 exceptionHandler.process( e );
 116    }
 117    }
 118   
 119    /**
 120    * Dump tree
 121    *
 122    * @param tree Tree to be dumped
 123    */
 124  0 public void dumpTree( Tree tree )
 125    {
 126  0 txt( "tree " + tree.getFile() ); nl();
 127  0 block_nl();
 128  0 dumpTree( tree.getRootNode() );
 129  0 unblock_nl();
 130    }
 131   
 132    /**
 133    * Dump subtree.
 134    *
 135    * @param node Subtree root node.
 136    */
 137  0 public void dumpTree( Node node )
 138    {
 139  0 dumpNode( node );
 140    }
 141   
 142  0 protected TreePrinter( Writer writer, ExceptionHandler exceptionHandler, int indentStep )
 143    {
 144  0 this.writer = writer;
 145  0 WriterTextReceiver out = new WriterTextReceiver( writer, exceptionHandler );
 146  0 indentFilter = new IndentFilter( out, indentStep );
 147    }
 148   
 149  0 protected final void incIndent()
 150    {
 151  0 indentFilter.pushIndent( indentFilter.getIndent()
 152    + indentFilter.getIndentStep()
 153    );
 154    }
 155   
 156  0 protected final void popIndent()
 157    {
 158  0 indentFilter.popIndent();
 159    }
 160   
 161  0 protected final void txt( String s )
 162    {
 163  0 indentFilter.txt( s );
 164    }
 165   
 166  0 protected final void nl()
 167    {
 168  0 indentFilter.nl();
 169    }
 170   
 171  0 protected final void block()
 172    {
 173  0 txt( "{" );
 174  0 incIndent();
 175    }
 176   
 177  0 protected final void unblock()
 178    {
 179  0 popIndent();
 180  0 txt( "}" );
 181    }
 182   
 183  0 protected final void block_nl()
 184    {
 185  0 block();
 186  0 nl();
 187    }
 188   
 189  0 protected final void unblock_nl()
 190    {
 191  0 unblock();
 192  0 nl();
 193    }
 194   
 195  0 protected void dumpNode( Node node )
 196    {
 197  0 txt( node.toString() ); nl();
 198  0 block_nl();
 199   
 200  0 for( Iterator attr_name_iterator = Accessor.getAttributeNames( node ).iterator();
 201  0 attr_name_iterator.hasNext();
 202    )
 203    {
 204  0 String name = (String)attr_name_iterator.next();
 205  0 Object value = Accessor.getAttribute( node, name );
 206   
 207  0 if( value instanceof List )
 208    {
 209  0 txt( name + "[" + ((List)value).size() + "] =" ); nl();
 210  0 block_nl();
 211  0 for( int i = 0; i < ((List)value).size(); i++ )
 212    {
 213  0 dumpAttribute( node
 214    , name + "[" + i + "]"
 215    , ((List)value).get( i )
 216    );
 217    }
 218  0 unblock_nl();
 219    } else {
 220  0 dumpAttribute( node, name, value );
 221    }
 222    }
 223  0 unblock_nl();
 224    }
 225   
 226  0 protected void dumpAttribute( Node node, String name, Object value )
 227    {
 228  0 txt( name + " = " );
 229   
 230  0 if( value instanceof Node && ((Node)value).getParent() == node )
 231    {
 232    // child
 233  0 dumpNode( (Node)value );
 234    } else {
 235  0 txt( "'" + value + "'" );
 236  0 nl();
 237    }
 238    }
 239    }