org.incava.analysis
Class ContextReport

java.lang.Object
  extended by org.incava.analysis.Report
      extended by org.incava.analysis.ContextReport

public class ContextReport
extends Report

Reports errors in multiple lines, displaying the contextual code, and denoting the code to which a violation applies.


Field Summary
static int tabWidth
          The number of spaces a tab is equivalent to.
 
Fields inherited from class org.incava.analysis.Report
fileName
 
Constructor Summary
ContextReport(java.io.OutputStream os)
          Creates a context report for the given output stream.
ContextReport(java.io.OutputStream os, java.io.File file)
          Creates a context report for the given output stream, and file.
ContextReport(java.io.OutputStream os, java.lang.String source)
          Creates a context report for the given output stream, and string source.
ContextReport(java.io.Writer writer)
          Creates a context report for the given writer.
ContextReport(java.io.Writer writer, java.io.File file)
          Creates a context report for the given writer, and a file source.
ContextReport(java.io.Writer writer, java.lang.String source)
          Creates a context report for the given writer, and a string source.
 
Method Summary
protected  void indent(java.lang.StringBuffer buf, int line, int column, char ch)
          Adds indentation to the buffer, replacing spacing and tabs.
protected  void markToEndOfLine(java.lang.StringBuffer buf, int line, int column)
          Marks the given line with leading spaces to the column position (inclusive), and from there marking to the end of the line with "<---...".
protected  void markToStartPosition(java.lang.StringBuffer buf, int line, int column)
          Marks the given line with "...--->" leading to the column position (inclusive).
 void reset(java.io.File file)
          Associates the given file with the list of violations, including that are adding to this report later, i.e., prior to flush.
 void reset(java.lang.String source)
          Associates the given string source with the list of violations, including that are adding to this report later, i.e., prior to flush.
protected  java.lang.String toString(Violation violation)
          Returns a string representing the given violation, consistent with the format of the Report subclass.
protected  void underline(java.lang.StringBuffer buf, int line, int beginColumn, int endColumn)
          Underlines ("<--...-->") from beginColumn to endColumn in the given line.
protected  void writeLine(java.lang.StringBuffer buf, int line)
          Writes the given line, adding the line number, right-aligned.
 
Methods inherited from class org.incava.analysis.Report
addViolation, flush, getViolations, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tabWidth

public static int tabWidth
The number of spaces a tab is equivalent to.

Constructor Detail

ContextReport

public ContextReport(java.io.Writer writer)
Creates a context report for the given writer.

Parameters:
writer - The writer associated with this report.

ContextReport

public ContextReport(java.io.OutputStream os)
Creates a context report for the given output stream.

Parameters:
os - The output stream associated with this report.

ContextReport

public ContextReport(java.io.Writer writer,
                     java.lang.String source)
Creates a context report for the given writer, and a string source.

Parameters:
writer - The writer associated with this report.
source - The source code to which this report applies.

ContextReport

public ContextReport(java.io.Writer writer,
                     java.io.File file)
Creates a context report for the given writer, and a file source.

Parameters:
writer - The writer associated with this report.
file - The file, containing source code, to which this report applies.

ContextReport

public ContextReport(java.io.OutputStream os,
                     java.lang.String source)
Creates a context report for the given output stream, and string source.

Parameters:
os - The output stream associated with this report.
source - The source code to which this report applies.

ContextReport

public ContextReport(java.io.OutputStream os,
                     java.io.File file)
Creates a context report for the given output stream, and file.

Parameters:
os - The output stream associated with this report.
file - The file, containing source code, to which this report applies.
Method Detail

reset

public void reset(java.io.File file)
Associates the given file with the list of violations, including that are adding to this report later, i.e., prior to flush.

Overrides:
reset in class Report
Parameters:
file - The file associated with the set of violations.

reset

public void reset(java.lang.String source)
Associates the given string source with the list of violations, including that are adding to this report later, i.e., prior to flush.

Overrides:
reset in class Report
Parameters:
source - The source code associated with the set of violations.

toString

protected java.lang.String toString(Violation violation)
Returns a string representing the given violation, consistent with the format of the Report subclass.

Specified by:
toString in class Report
Parameters:
violation - The violation to represent as a string.

indent

protected void indent(java.lang.StringBuffer buf,
                      int line,
                      int column,
                      char ch)
Adds indentation to the buffer, replacing spacing and tabs. Replaces tabs with tabWidth occurrences of ch.

Parameters:
buf - The buffer to be written to.
line - The current line number.
column - The column to indent to.
ch - The character with which to replace spaces and tabs.

markToEndOfLine

protected void markToEndOfLine(java.lang.StringBuffer buf,
                               int line,
                               int column)
Marks the given line with leading spaces to the column position (inclusive), and from there marking to the end of the line with "<---...".

Parameters:
buf - The buffer to be written to.
line - The current line number.
column - The column to mark to/from.

markToStartPosition

protected void markToStartPosition(java.lang.StringBuffer buf,
                                   int line,
                                   int column)
Marks the given line with "...--->" leading to the column position (inclusive).

Parameters:
buf - The buffer to be written to.
line - The current line number.
column - The column to mark to.

underline

protected void underline(java.lang.StringBuffer buf,
                         int line,
                         int beginColumn,
                         int endColumn)
Underlines ("<--...-->") from beginColumn to endColumn in the given line. If the columns are equal, a single caret is shown.

Parameters:
buf - The buffer to be written to.
line - The current line number.
beginColumn - The column to mark from.
endColumn - The column to mark to.

writeLine

protected void writeLine(java.lang.StringBuffer buf,
                         int line)
Writes the given line, adding the line number, right-aligned. Appends the end-of-line character/sequence.

Parameters:
buf - The buffer to be written to.
line - The current line number.