1 package org.apache.velocity.util.introspection;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.velocity.runtime.log.Log;
23 import org.apache.velocity.runtime.parser.node.Node;
24
25 /**
26 * Little class to carry in info such as template name, line and column
27 * for information error reporting from the uberspector implementations
28 *
29 * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
30 * @version $Id: Info.java 733416 2009-01-11 05:26:52Z byron $
31 */
32 public class Info
33 {
34 private int line;
35 private int column;
36 private String templateName;
37
38 /**
39 * @param source Usually a template name.
40 * @param line The line number from <code>source</code>.
41 * @param column The column number from <code>source</code>.
42 */
43 public Info(String source, int line, int column)
44 {
45 this.templateName = source;
46 this.line = line;
47 this.column = column;
48 }
49
50 public Info(Node node)
51 {
52 this(node.getTemplateName(), node.getLine(), node.getColumn());
53 }
54
55 /**
56 * Force callers to set the location information.
57 */
58 private Info()
59 {
60 }
61
62 /**
63 * @return The template name.
64 */
65 public String getTemplateName()
66 {
67 return templateName;
68 }
69
70 /**
71 * @return The line number.
72 */
73 public int getLine()
74 {
75 return line;
76 }
77
78 /**
79 * @return The column number.
80 */
81 public int getColumn()
82 {
83 return column;
84 }
85
86 /**
87 * Formats a textual representation of this object as <code>SOURCE
88 * [line X, column Y]</code>.
89 *
90 * @return String representing this object.
91 * @since 1.5
92 */
93 public String toString()
94 {
95 return Log.formatFileString(getTemplateName(), getLine(), getColumn());
96 }
97 }