001 /**
002 *
003 * Copyright 2004 James Strachan
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.codehaus.groovy.antlr;
019
020 import antlr.collections.AST;
021
022 /**
023 * @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
024 * @version $Revision: 1.1 $
025 */
026 public class ASTRuntimeException extends RuntimeException {
027 private AST ast;
028
029 public ASTRuntimeException(AST ast, String message) {
030 super(message + description(ast));
031 this.ast = ast;
032 }
033
034 public ASTRuntimeException(AST ast, String message, Throwable throwable) {
035 super(message + description(ast), throwable);
036 }
037
038 protected static String description(AST node) {
039 return (node != null) ? " at line: " + node.getLine() + " column: " + node.getColumn() : "";
040 }
041
042 public AST getAst() {
043 return ast;
044 }
045
046 public int getLine() {
047 return ast != null ? ast.getLine() : -1;
048 }
049
050 public int getColumn() {
051 return ast != null ? ast.getColumn() : -1;
052 }
053
054 }