Clover coverage report - groovy - 1.0-beta-6
Coverage timestamp: Thu Jul 15 2004 13:18:22 BST
file stats: LOC: 261   Methods: 12
NCLOC: 108   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ErrorReporter.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  $Id: ErrorReporter.java,v 1.5 2004/04/19 07:29:45 cpoirier Exp $
 3   
 
 4   
  Copyright 2004 (C) James Strachan and Bob Mcwhirter. All Rights Reserved.
 5   
 
 6   
  Redistribution and use of this software and associated documentation
 7   
  ("Software"), with or without modification, are permitted provided
 8   
  that the following conditions are met:
 9   
 
 10   
  1. Redistributions of source code must retain copyright
 11   
     statements and notices.  Redistributions must also contain a
 12   
     copy of this document.
 13   
 
 14   
  2. Redistributions in binary form must reproduce the
 15   
     above copyright notice, this list of conditions and the
 16   
     following disclaimer in the documentation and/or other
 17   
     materials provided with the distribution.
 18   
 
 19   
  3. The name "groovy" must not be used to endorse or promote
 20   
     products derived from this Software without prior written
 21   
     permission of The Codehaus.  For written permission,
 22   
     please contact info@codehaus.org.
 23   
 
 24   
  4. Products derived from this Software may not be called "groovy"
 25   
     nor may "groovy" appear in their names without prior written
 26   
     permission of The Codehaus. "groovy" is a registered
 27   
     trademark of The Codehaus.
 28   
 
 29   
  5. Due credit should be given to The Codehaus -
 30   
     http://groovy.codehaus.org/
 31   
 
 32   
  THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
 33   
  ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 34   
  NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 35   
  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 36   
  THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 37   
  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 38   
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 39   
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 40   
  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 41   
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 42   
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 43   
  OF THE POSSIBILITY OF SUCH DAMAGE.
 44   
 
 45   
  */
 46   
 
 47   
 
 48   
 package org.codehaus.groovy.tools;
 49   
 
 50   
 import java.io.PrintStream;
 51   
 import java.io.PrintWriter;
 52   
 
 53   
 import org.codehaus.groovy.GroovyExceptionInterface;
 54   
 import org.codehaus.groovy.control.CompilationFailedException;
 55   
 
 56   
 
 57   
 
 58   
 /**
 59   
  *  Provides services for reporting compilation errors to the
 60   
  *  user.  Primary entry point is <code>write()</code>.
 61   
  *
 62   
  *  @author <a href="mailto:cpoirier%20AT%20tapestry_os%20DOT%20org">Chris Poirier</a>
 63   
  *  @version $Revision: 1.5 $
 64   
  */
 65   
 
 66   
 public class ErrorReporter
 67   
 {
 68   
     private Throwable   base     = null;    // The exception on which to report
 69   
     private boolean     debug    = false;   // If true, stack traces are always output
 70   
 
 71   
     private Object      output   = null;    // The stream/writer to which to output
 72   
 
 73   
 
 74   
    /**
 75   
     *  Configures a new Reporter.  Default mode is not to report a stack trace unless
 76   
     *  the error was not of one of the supported types.
 77   
     *
 78   
     *  @param e  the exception on which to report
 79   
     */
 80   
 
 81  0
     public ErrorReporter( Throwable e )
 82   
     { 
 83  0
         this.base     = e;
 84   
     }
 85   
 
 86   
 
 87   
    /**
 88   
     *  Configures a new Reporter.  
 89   
     *
 90   
     *  @param e      the exception on which to report
 91   
     *  @param debug  if set, stack traces will be output for all reports
 92   
     */
 93   
 
 94  0
     public ErrorReporter( Throwable e, boolean debug )
 95   
     {
 96  0
         this.base  = e;
 97  0
         this.debug = debug;
 98   
     }
 99   
 
 100   
 
 101   
    /**
 102   
     *  Writes the error to the specified <code>PrintStream</code>.
 103   
     */
 104   
 
 105  0
     public void write( PrintStream stream )
 106   
     {
 107  0
         this.output = stream;
 108  0
         dispatch( base, false );
 109  0
         stream.flush();
 110   
     }
 111   
 
 112   
 
 113   
    /**
 114   
     *  Writes the error to the specified <code>PrintWriter</code>.
 115   
     */
 116   
 
 117  0
     public void write( PrintWriter writer )
 118   
     {
 119  0
         this.output = writer;
 120  0
         dispatch( base, false );
 121  0
         writer.flush();
 122   
     }
 123   
 
 124   
 
 125   
    /**
 126   
     *  Runs the report once all initialization is complete.
 127   
     */
 128   
 
 129  0
     protected void dispatch( Throwable object, boolean child )
 130   
     {
 131  0
         if( object instanceof CompilationFailedException )
 132   
         {
 133  0
             report( (CompilationFailedException)object, child );
 134   
         }
 135  0
         else if( object instanceof GroovyExceptionInterface )
 136   
         {
 137  0
             report( (GroovyExceptionInterface)object, child );
 138   
         }
 139  0
         else if( object instanceof Exception )
 140   
         {
 141  0
             report( (Exception)object, child );
 142   
         }
 143   
         else
 144   
         {
 145  0
             report( object, child );
 146   
         }
 147   
 
 148   
     }
 149   
 
 150   
 
 151   
 
 152   
   //---------------------------------------------------------------------------
 153   
   // REPORTING ROUTINES
 154   
 
 155   
 
 156   
    /**
 157   
     *  For CompilationFailedException.
 158   
     */
 159   
 
 160  0
     protected void report( CompilationFailedException e, boolean child )
 161   
     {
 162  0
         println( e.toString() );
 163  0
         stacktrace( e, false );
 164   
     }
 165   
 
 166   
 
 167   
 
 168   
    /**
 169   
     *  For GroovyException.
 170   
     */
 171   
 
 172  0
     protected void report( GroovyExceptionInterface e, boolean child )
 173   
     {
 174  0
         println( ((Exception)e).getMessage() );
 175  0
         stacktrace( (Exception)e, false );
 176   
     }
 177   
 
 178   
 
 179   
 
 180   
    /**
 181   
     *  For Exception.
 182   
     */
 183   
 
 184  0
     protected void report( Exception e, boolean child )
 185   
     {
 186  0
         println( e.getMessage() );
 187  0
         stacktrace( e, false );
 188   
     }
 189   
 
 190   
 
 191   
 
 192   
    /**
 193   
     *  For everything else.
 194   
     */
 195   
 
 196  0
     protected void report( Throwable e, boolean child )
 197   
     {
 198  0
         println( ">>> a serious error occurred: " + e.getMessage() );
 199  0
         stacktrace( e, true );
 200   
     }
 201   
 
 202   
 
 203   
 
 204   
   //---------------------------------------------------------------------------
 205   
   // GENERAL SUPPORT ROUTINES
 206   
 
 207   
 
 208   
    /**
 209   
     *  Prints a line to the underlying <code>PrintStream</code>
 210   
     */
 211   
 
 212  0
     protected void println( String line )
 213   
     {
 214  0
         if( output instanceof PrintStream )
 215   
         {
 216  0
             ((PrintStream)output).println( line );
 217   
         }
 218   
         else
 219   
         {
 220  0
             ((PrintWriter)output).println( line );
 221   
         }
 222   
     }
 223   
 
 224  0
     protected void println( StringBuffer line )
 225   
     {
 226  0
         if( output instanceof PrintStream )
 227   
         {
 228  0
             ((PrintStream)output).println( line );
 229   
         }
 230   
         else
 231   
         {
 232  0
             ((PrintWriter)output).println( line );
 233   
         }
 234   
     }
 235   
 
 236   
 
 237   
    /**
 238   
     *  Displays an exception's stack trace, if <code>debug</code> or 
 239   
     *  <code>always</code>.
 240   
     */
 241   
 
 242  0
     protected void stacktrace( Throwable e, boolean always )
 243   
     {
 244  0
         if( debug || always )
 245   
         {
 246  0
             println( ">>> stacktrace:" );
 247  0
             if( output instanceof PrintStream )
 248   
             {
 249  0
                 e.printStackTrace( (PrintStream)output );
 250   
             }
 251   
             else
 252   
             {
 253  0
                 e.printStackTrace( (PrintWriter)output );
 254   
             }
 255   
         }
 256   
     }
 257   
 
 258   
 
 259   
 
 260   
 }
 261