edu.rice.cs.drjava.model
Class DJError

java.lang.Object
  extended by edu.rice.cs.drjava.model.DJError
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<DJError>
Direct Known Subclasses:
CompilerError, JUnitError

public class DJError
extends java.lang.Object
implements java.lang.Comparable<DJError>, java.io.Serializable

A class to represent source errors and warnings generated by the compiler, JUnit, etc. This class enables DrJava to highlight the error text.

Version:
$Id: DJError.java 5439 2011-08-11 17:13:04Z rcartwright $
See Also:
Serialized Form

Field Summary
private  java.io.File _file
           
private  boolean _isWarning
           
private  int _lineNumber
          zero-based line number.
private  java.lang.String _message
           
private  boolean _noLocation
          This boolean is true when the DJError does not have a location (lineNumber is -1).
private  int _startColumn
          zero-based column number.
 
Constructor Summary
DJError(java.io.File file, int lineNumber, int startColumn, java.lang.String message, boolean isWarning)
          Constructor.
DJError(java.io.File file, java.lang.String message, boolean isWarning)
          Constructor for an DJError with an associated file but no location in the source
DJError(java.lang.String message, boolean isWarning)
          Constructor for CompilerErrors without files.
 
Method Summary
private  int compareByPosition(DJError other)
          Compares this error's postion with other error's, based first on line number, then by column.
private  int compareErrorWarning(DJError other)
          Compare otherwise equal errors.
 int compareTo(DJError other)
          Compares by file, then by line, then by column.
 java.io.File file()
          Gets the file.
 java.lang.String fileName()
          Gets the full name of the file.
 java.lang.String getFileMessage()
          This function returns a message telling the file this error is from appropriate to display to a user, indicating if there is no file associated with this error.
 java.lang.String getLineMessage()
          This function returns a message telling the line this error is from appropriate to display to a user, indicating if there is no file associated with this error.
 boolean hasNoLocation()
          This function returns true if and only if the given error has no location
 boolean isWarning()
          Determines if the error is a warning.
 int lineNumber()
          Gets the zero-based line number of the error.
 java.lang.String message()
          Gets the error message.
 void setLineNumber(int ln)
          Sets the line number.
 int startColumn()
          Gets the column where the error begins.
 java.lang.String toString()
          Gets a String representation of the error.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_file

private volatile java.io.File _file

_lineNumber

private volatile int _lineNumber
zero-based line number.


_startColumn

private final int _startColumn
zero-based column number.


_message

private final java.lang.String _message

_isWarning

private final boolean _isWarning

_noLocation

private volatile boolean _noLocation
This boolean is true when the DJError does not have a location (lineNumber is -1).

Constructor Detail

DJError

public DJError(java.io.File file,
               int lineNumber,
               int startColumn,
               java.lang.String message,
               boolean isWarning)
Constructor.

Parameters:
file - the file where the error occurred
lineNumber - the line number of the error
startColumn - the starting column of the error
message - the error message

DJError

public DJError(java.io.File file,
               java.lang.String message,
               boolean isWarning)
Constructor for an DJError with an associated file but no location in the source


DJError

public DJError(java.lang.String message,
               boolean isWarning)
Constructor for CompilerErrors without files.

Parameters:
message - the error message
Method Detail

hasNoLocation

public boolean hasNoLocation()
This function returns true if and only if the given error has no location


toString

public java.lang.String toString()
Gets a String representation of the error. Abstract.

Overrides:
toString in class java.lang.Object
Returns:
the error as a String

file

public java.io.File file()
Gets the file.

Returns:
the file with errors.

fileName

public java.lang.String fileName()
Gets the full name of the file.

Returns:
the file name.

lineNumber

public int lineNumber()
Gets the zero-based line number of the error. NOTE: javac/javadoc produces zero-based line numbers internally, but prints one-based line numbers to the command line.

Returns:
the zero-based line number

setLineNumber

public void setLineNumber(int ln)
Sets the line number.

Parameters:
ln - line number

startColumn

public int startColumn()
Gets the column where the error begins.

Returns:
the starting column

message

public java.lang.String message()
Gets the error message.

Returns:
the error message.

getFileMessage

public java.lang.String getFileMessage()
This function returns a message telling the file this error is from appropriate to display to a user, indicating if there is no file associated with this error.


getLineMessage

public java.lang.String getLineMessage()
This function returns a message telling the line this error is from appropriate to display to a user, indicating if there is no file associated with this error. This is adjusted to show one-based numbers, since internally we store a zero-based index.


isWarning

public boolean isWarning()
Determines if the error is a warning.

Returns:
true if the error is a warning.

compareTo

public int compareTo(DJError other)
Compares by file, then by line, then by column. Errors without files are considered equal, but less than any errors with files. Warnings are considered greater than errors when they are otherwise equal.

Specified by:
compareTo in interface java.lang.Comparable<DJError>

compareByPosition

private int compareByPosition(DJError other)
Compares this error's postion with other error's, based first on line number, then by column.


compareErrorWarning

private int compareErrorWarning(DJError other)
Compare otherwise equal errors.