edu.rice.cs.drjava.model.compiler
Class CompilerErrorModel

java.lang.Object
  extended by edu.rice.cs.drjava.model.compiler.CompilerErrorModel
Direct Known Subclasses:
JUnitErrorModel

public class CompilerErrorModel
extends java.lang.Object

Contains the CompilerErrors for a set of compiled file after a compile has ended.

Version:
$Id: CompilerErrorModel.java 5439 2011-08-11 17:13:04Z rcartwright $

Nested Class Summary
private static class CompilerErrorModel.StartAndEndIndex
          This class is used only to track where the errors with positions for a file begin and end.
 
Field Summary
private  DJError[] _errors
          An array of errors to be displayed in the CompilerErrorPanel associated with this model.
private  java.util.HashMap<java.io.File,CompilerErrorModel.StartAndEndIndex> _filesToIndexes
          Used internally in building _positions.
private  GlobalModel _model
          The global model which created/controls this object.
private  int _numCompilerErrors
          The number of compile errors.
private  int _numErrors
          The size of _errors and _positions.
private  int _numWarnings
          The number of compile warnings.
private  int _onlyWarnings
          Cached result of hasOnlyWarnings.
private  javax.swing.text.Position[] _positions
          An array of file offsets, parallel to the _errors array.
private static java.lang.String newLine
           
 
Constructor Summary
CompilerErrorModel()
          Constructs an empty CompilerErrorModel with no errors and a dummy global model.
CompilerErrorModel(DJError[] errors, GlobalModel model)
          Constructs a new CompilerErrorModel with specified global model.
 
Method Summary
private  void _calculatePositions()
          Create array of positions where each error occurred.
 DJError getError(int idx)
          Accessor for errors maintained here.
 DJError getErrorAtOffset(OpenDefinitionsDocument odd, int offset)
          This method finds and returns the error that is at the given offset
 int getNumCompErrors()
          Returns the number of CompilerErrors that are compiler errors
 int getNumErrors()
          Returns the number of CompilerErrors.
 int getNumWarnings()
          Returns the number of CompilerErrors that are warnings
 javax.swing.text.Position getPosition(DJError error)
          Returns the position of the given error in the document representing its file.
 boolean hasErrorsWithPositions(OpenDefinitionsDocument odd)
          This function tells if there are errors with source locations associated with the given file.
 boolean hasOnlyWarnings()
          Checks whether all CompilerErrors contained here are actually warnings.
private  int nextErrorWithLine(int idx)
          Finds the first error after numProcessed which has a file and line number.
 java.lang.String toString()
          Prints out this model's errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

newLine

private static final java.lang.String newLine

_errors

private final DJError[] _errors
An array of errors to be displayed in the CompilerErrorPanel associated with this model. After model construction, this array should be sorted in this order: (i) Errors with no file. (ii) Errors for each file in path-alphabetical order. Within each file: (i) Errors with no line number. (ii) Errors with line numbers, in order. In all cases, where all else is equal, warnings are sorted below errors.


_positions

private final javax.swing.text.Position[] _positions
An array of file offsets, parallel to the _errors array. NOTE: If there is no position associated with an error, its entry here should be set to null.


_numErrors

private final int _numErrors
The size of _errors and _positions. This should never change after model construction


_numCompilerErrors

private volatile int _numCompilerErrors
The number of compile errors. Used for display purposes only.


_numWarnings

private volatile int _numWarnings
The number of compile warnings. Used for display purposes only.


_onlyWarnings

private volatile int _onlyWarnings
Cached result of hasOnlyWarnings. Three-state enum: -1 => result has not been computed 0 => false 1 => true


_filesToIndexes

private final java.util.HashMap<java.io.File,CompilerErrorModel.StartAndEndIndex> _filesToIndexes
Used internally in building _positions. The file used as the index *must* be a canonical file, or else errors won't always be associated with the right documents.


_model

private final GlobalModel _model
The global model which created/controls this object.

Constructor Detail

CompilerErrorModel

public CompilerErrorModel()
Constructs an empty CompilerErrorModel with no errors and a dummy global model. As a side effect, it opens any documents containing errors/warnings that are not currently open.


CompilerErrorModel

public CompilerErrorModel(DJError[] errors,
                          GlobalModel model)
Constructs a new CompilerErrorModel with specified global model. Performed in DefaultGlobalModel construction and after compilation has been performed.

Parameters:
errors - the list of DJError's (or a subclass).
model - is the model to find documents from
Method Detail

getError

public DJError getError(int idx)
Accessor for errors maintained here.

Parameters:
idx - the index of the error to retrieve
Returns:
the error at index idx
Throws:
java.lang.NullPointerException - if this object was improperly initialized
java.lang.ArrayIndexOutOfBoundsException - if !(0 <= idx < this.getNumErrors())

getPosition

public javax.swing.text.Position getPosition(DJError error)
Returns the position of the given error in the document representing its file.


getNumErrors

public int getNumErrors()
Returns the number of CompilerErrors.


getNumCompErrors

public int getNumCompErrors()
Returns the number of CompilerErrors that are compiler errors


getNumWarnings

public int getNumWarnings()
Returns the number of CompilerErrors that are warnings


toString

public java.lang.String toString()
Prints out this model's errors.

Overrides:
toString in class java.lang.Object

getErrorAtOffset

public DJError getErrorAtOffset(OpenDefinitionsDocument odd,
                                int offset)
This method finds and returns the error that is at the given offset

Parameters:
odd - the OpenDefinitionsDocument where you want to find the error at the caret
offset - the offset into the document
Returns:
the DJError at the given offset, null if no error corresponds to this location

hasErrorsWithPositions

public boolean hasErrorsWithPositions(OpenDefinitionsDocument odd)
This function tells if there are errors with source locations associated with the given file.


hasOnlyWarnings

public boolean hasOnlyWarnings()
Checks whether all CompilerErrors contained here are actually warnings. This would indicate that there were no "real" errors, so output is valid.

Returns:
false if any error contained here is not a warning, true otherwise

_calculatePositions

private void _calculatePositions()
Create array of positions where each error occurred. Positions are related their corresponding documents.


nextErrorWithLine

private int nextErrorWithLine(int idx)
Finds the first error after numProcessed which has a file and line number.

Parameters:
idx - the starting index of the search
Returns:
the index of the found error