PageRenderTime 35ms CodeModel.GetById 29ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist030708/src/edu/vub/at/exceptions/XParseError.java

http://ambienttalk.googlecode.com/
Java | 130 lines | 51 code | 15 blank | 64 comment | 3 complexity | e0c4d81d63440c3766a84207720ed60a MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * XParseError.java created on 29-jul-2006 at 14:36:07
  4 * (c) Programming Technology Lab, 2006 - 2007
  5 * Authors: Tom Van Cutsem & Stijn Mostinckx
  6 * 
  7 * Permission is hereby granted, free of charge, to any person
  8 * obtaining a copy of this software and associated documentation
  9 * files (the "Software"), to deal in the Software without
 10 * restriction, including without limitation the rights to use,
 11 * copy, modify, merge, publish, distribute, sublicense, and/or
 12 * sell copies of the Software, and to permit persons to whom the
 13 * Software is furnished to do so, subject to the following
 14 * conditions:
 15 *
 16 * The above copyright notice and this permission notice shall be
 17 * included in all copies or substantial portions of the Software.
 18 *
 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 26 * OTHER DEALINGS IN THE SOFTWARE.
 27 */
 28package edu.vub.at.exceptions;
 29
 30import edu.vub.at.objects.ATTypeTag;
 31import edu.vub.at.objects.coercion.NativeTypeTags;
 32
 33import java.io.InputStream;
 34
 35/**
 36 * XParseError is thrown when illegal input is parsed by the AmbientTalk parser.
 37 * 
 38 * @author tvc
 39 */
 40public final class XParseError extends InterpreterException {
 41
 42	private static final long serialVersionUID = 3910243526236096495L;
 43
 44	private InputStream erroneousCode_;
 45	
 46	// indicates the position of the parse error
 47	private final String fileName_;
 48	private final int line_;
 49	private final int column_;
 50
 51	/**
 52	 * Convenience constructor which takes only a message and an underlying exception.
 53	 * @param message a message detailing the suspected reason for the parser to fail
 54	 * @param cause an underlying exception detailing the actual cause of this exception
 55	 */
 56	public XParseError(String message, Throwable cause) {
 57		super(message, cause);
 58		fileName_ = null;
 59		line_ = 0;
 60		column_ = 0;
 61	}
 62	
 63	/**
 64	 * Complete constructor taking information on both the error and the precise position in which
 65	 * the erroneous code was detected by the parser.
 66	 * @param erroneousCode the code snippet which could not be parsed
 67	 * @param message a message detailing the suspected reason for the parser to fail
 68	 * @param filename the file from which the parser was reading
 69	 * @param line the line at which the erroneous code is situated
 70	 * @param column the column at which the token that could not be parsed starts.
 71	 * @param cause an underlying exception detailing the actual cause of this exception
 72	 */
 73	public XParseError(InputStream erroneousCode,
 74			          String message,
 75			          String filename,
 76			          int line,
 77			          int column,
 78			          Throwable cause) {
 79		super(message, cause);
 80		erroneousCode_ = erroneousCode;
 81		fileName_ = filename;
 82		line_ = line;
 83		column_ = column;
 84	}
 85	
 86	/**
 87	 * @return Returns the column.
 88	 */
 89	public int getColumn() {
 90		return column_;
 91	}
 92
 93	/**
 94	 * @return Returns the fileName.
 95	 */
 96	public String getFileName() {
 97		return fileName_;
 98	}
 99
100	/**
101	 * @return Returns the line.
102	 */
103	public int getLine() {
104		return line_;
105	}
106
107	/**
108	 * @return Returns the erroneous code.
109	 */
110	public InputStream getErroneousCode() {
111		return erroneousCode_;
112	}
113	
114	/**
115	 * Method overridden to provide a more elaborate message when information on the source file,
116	 * the line number and column position were provided.
117	 */
118	public String getMessage() {
119		if (fileName_ != null) {
120			return fileName_ + ":" + line_ + ":" + column_ + ":" + super.getMessage();
121		} else {
122			return super.getMessage();
123		}
124	}
125	
126	public ATTypeTag getType() {
127		return NativeTypeTags._PARSEERROR_;
128	}
129
130}