001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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 package org.apache.commons.jexl2; 018 019 020 /** 021 * Little class to carry in info such as a url/file name, line and column for 022 * information error reporting from the uberspector implementations. 023 * @version $Id: DebugInfo.java 885553 2009-11-30 19:28:40Z henrib $ 024 */ 025 public class DebugInfo implements JexlInfo { 026 /** line number. */ 027 private final int line; 028 /** column number. */ 029 private final int column; 030 /** name. */ 031 private final String name; 032 /** 033 * Create info. 034 * @param tn template name 035 * @param l line number 036 * @param c column 037 */ 038 public DebugInfo(String tn, int l, int c) { 039 name = tn; 040 line = l; 041 column = c; 042 } 043 044 /** 045 * Formats this info in the form 'name@line:column'. 046 * @return the formatted info 047 */ 048 @Override 049 public String toString() { 050 StringBuilder sb = new StringBuilder(name != null? name : ""); 051 if (line > 0) { 052 sb.append("@"); 053 sb.append(line); 054 if (column > 0) { 055 sb.append(":"); 056 sb.append(column); 057 } 058 } 059 return sb.toString(); 060 } 061 062 /** {@inheritDoc} */ 063 public String debugString() { 064 return toString(); 065 } 066 067 /** 068 * Gets the file/script/url name. 069 * @return template name 070 */ 071 public String getName() { 072 return name; 073 } 074 075 /** 076 * Gets the line number. 077 * @return line number. 078 */ 079 public int getLine() { 080 return line; 081 } 082 083 /** 084 * Gets the column number. 085 * @return the column. 086 */ 087 public int getColumn() { 088 return column; 089 } 090 }