View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jexl2;
18  
19  
20  /**
21   * Helper class to carry in info such as a url/file name, line and column for
22   * debugging information reporting.
23   */
24  public class DebugInfo implements JexlInfo {
25      /** line number. */
26      private final int line;
27      /** column number. */
28      private final int column;
29      /** name. */
30      private final String name;
31      /** 
32       * Create info.
33       * @param tn template name
34       * @param l line number
35       * @param c column
36       */
37      public DebugInfo(String tn, int l, int c) {
38          name = tn;
39          line = l;
40          column = c;
41      }
42  
43      /**
44       * Formats this info in the form 'name@line:column'.
45       * @return the formatted info
46       */
47      @Override
48      public String toString() {
49          StringBuilder sb = new StringBuilder(name != null? name : "");
50          if (line > 0) {
51              sb.append("@");
52              sb.append(line);
53              if (column > 0) {
54                  sb.append(":");
55                  sb.append(column);
56              }
57          }
58          return sb.toString();
59      }
60      
61      /** {@inheritDoc} */
62      public String debugString() {
63          return toString();
64      }
65      
66      /** {@inheritDoc} 
67       * @since 2.1 
68       */
69      public DebugInfo debugInfo() {
70          return this;
71      }
72  
73      /**
74       * Gets the file/script/url name.
75       * @return template name
76       */
77      public String getName() {
78          return name;
79      }
80  
81      /**
82       * Gets the line number.
83       * @return line number.
84       */
85      public int getLine() {
86          return line;
87      }
88  
89      /**
90       * Gets the column number.
91       * @return the column.
92       */
93      public int getColumn() {
94          return column;
95      }
96  }