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.syntax;
17  
18  import org.codehaus.groovy.GroovyException;
19  
20  /** Base exception indicating a syntax error.
21   *
22   *  @author <a href="bob@werken.com">bob mcwhirter</a>
23   *
24   *  @version $Id: SyntaxException.java 14281 2008-12-05 12:23:54Z glaforge $
25   */
26  public class SyntaxException extends GroovyException {
27  
28      /** Line upon which the error occurred. */
29      private final int line;
30  
31      /** Column upon which the error occurred. */
32      private final int column;
33  
34      private String sourceLocator;
35  
36      public SyntaxException(String message, int line, int column) {
37          super(message, false);
38          this.line = line;
39          this.column = column;
40      }
41  
42      public SyntaxException(String message, Throwable cause, int line, int column) {
43          super(message, cause);
44          this.line = line;
45          this.column = column;
46      }
47  
48      // Properties
49      // ----------------------------------------------------------------------
50      public void setSourceLocator(String sourceLocator) {
51          this.sourceLocator = sourceLocator;
52      }
53  
54      public String getSourceLocator() {
55          return this.sourceLocator;
56      }
57  
58      /** Retrieve the line upon which the error occurred.
59       *
60       *  @return The line.
61       */
62      public int getLine() {
63          return line;
64      }
65  
66      /** Retrieve the column upon which the error occurred.
67       *
68       *  @return The column.
69       */
70      public int getStartColumn() {
71          return column;
72      }
73      
74      /** 
75       * @return the end of the line on which the error occurs
76       */
77      public int getStartLine() {
78          return getLine();
79      }
80  
81      /**
82       * @return the end column on which the error occurs
83       */
84      public int getEndColumn() {
85          return getStartColumn() + 1;
86      }
87  
88      public String getOriginalMessage() {
89          return super.getMessage();
90      }
91  
92      public String getMessage() {
93          return super.getMessage() + " @ line " + line + ", column " + column + ".";
94      }
95  }