    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     * Helper class to carry in info such as a url/file name, line and column for
    022     * debugging information reporting.
    023     */
    024    public class DebugInfo implements JexlInfo {
    025        /** line number. */
    026        private final int line;
    027        /** column number. */
    028        private final int column;
    029        /** name. */
    030        private final String name;
    031        /**
    032         * Create info.
    033         * @param tn template name
    034         * @param l line number
    035         * @param c column
    036         */
    037        public DebugInfo(String tn, int l, int c) {
    038            name = tn;
    039            line = l;
    040            column = c;
    041        }
    042
    043        /**
    044         * Formats this info in the form 'name&#064;line:column'.
    045         * @return the formatted info
    046         */
    047        @Override
    048        public String toString() {
    049            StringBuilder sb = new StringBuilder(name != null? name : "");
    050            if (line > 0) {
    051                sb.append("@");
    052                sb.append(line);
    053                if (column > 0) {
    054                    sb.append(":");
    055                    sb.append(column);
    056                }
    057            }
    058            return sb.toString();
    059        }
    060
    061        /** {@inheritDoc} */
    062        public String debugString() {
    063            return toString();
    064        }
    065
    066        /** {@inheritDoc}
    067         * @since 2.1
    068         */
    069        public DebugInfo debugInfo() {
    070            return this;
    071        }
    072
    073        /**
    074         * Gets the file/script/url name.
    075         * @return template name
    076         */
    077        public String getName() {
    078            return name;
    079        }
    080
    081        /**
    082         * Gets the line number.
    083         * @return line number.
    084         */
    085        public int getLine() {
    086            return line;
    087        }
    088
    089        /**
    090         * Gets the column number.
    091         * @return the column.
    092         */
    093        public int getColumn() {
    094            return column;
    095        }
    096    }