View Javadoc
Minimize
Table

1   /*
2    * Copyright 2003-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.groovy.antlr;
17  
18  import antlr.collections.AST;
19  
20  /**
21   * @author <a href="mailto:jstrachan@protique.com">James Strachan</a>
22   * @version $Revision: 8004 $
23   */
24  public class ASTRuntimeException extends RuntimeException {
25      private final AST ast;
26  
27      public ASTRuntimeException(AST ast, String message) {
28          super(message + description(ast));
29          this.ast = ast;
30      }
31  
32      public ASTRuntimeException(AST ast, String message, Throwable throwable) {
33          super(message + description(ast), throwable);
34          this.ast = null;
35      }
36  
37      protected static String description(AST node) {
38          return (node != null) ? " at line: " + node.getLine() + " column: " + node.getColumn() : "";
39      }
40  
41      public AST getAst() {
42          return ast;
43      }
44  
45      public int getLine() {
46          return ast != null ? ast.getLine() : -1;
47      }
48  
49      public int getColumn() {
50          return ast != null ? ast.getColumn() : -1;
51      }
52  
53  }