SyntaxException.java
package edu.udel.cis.vsl.tass.model.IF;
import edu.udel.cis.vsl.tass.util.Source;
import edu.udel.cis.vsl.tass.util.Sourceable;
/**
* A SyntaxException is thrown whenever a syntax error is encountered in a
* source file that TASS is attempting to parse. A SyntaxException comprises two
* data: a source object (instance of Source) and a message (instance of
* String). The source object provides detailed information on the source of the
* error: filename, line number, etc. (see the Source class). The message
* contains some human-readable explanation of the cause of the error.
*
* The source object is allowed to be null. This is for cases where it is not
* really possible to point to a specific place in the source code that is the
* causes of the syntax error. That should be pretty rare, though.
*/
public class SyntaxException extends Exception {
/** Required to implement Serializeable, which is required by Exception. */
private static final long serialVersionUID = 1L;
/**
* The source object referring to the point in the source code responsible
* for the syntax error
*/
private Source source;
/**
* Constructs a new SyntaxException with the given source and message. The
* source may be null, but not the message.
*
* @param source
* @param message
*/
public SyntaxException(Source source, String message) {
super("Syntax error "
+ (source == null ? "" : "at " + source.toString()) + ": "
+ message);
setSource(source);
}
/**
* Constructs a new SyntaxException, getting the source object from the
* given Sourceable element.
*
* @param sourceable
* @param message
*/
public SyntaxException(Sourceable sourceable, String message) {
super("Syntax error "
+ (sourceable == null ? "" : "at " + sourceable.getSource())
+ ": " + message);
if (sourceable != null) {
this.source = sourceable.getSource();
} else {
this.source = null;
}
}
/** Constructs a SyntaxException with null source object */
public SyntaxException(String msg) {
super("Syntax error: " + msg);
this.source = null;
}
public Source getSource() {
return source;
}
public void setSource(Source source) {
this.source = source;
}
}