001 /*
002 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package com.sun.source.tree;
027
028 /**
029 * Provides methods to convert between character positions and line numbers
030 * for a compilation unit.
031 *
032 * @since 1.6
033 */
034 public interface LineMap {
035 /**
036 * Find the start position of a line.
037 *
038 * @param line line number (beginning at 1)
039 * @return position of first character in line
040 * @throws IndexOutOfBoundsException
041 * if <tt>lineNumber < 1</tt>
042 * if <tt>lineNumber > no. of lines</tt>
043 */
044 long getStartPosition(long line);
045
046 /**
047 * Find the position corresponding to a (line,column).
048 *
049 * @param line line number (beginning at 1)
050 * @param column tab-expanded column number (beginning 1)
051 *
052 * @return position of character
053 * @throws IndexOutOfBoundsException
054 * if {@code line < 1}
055 * if {@code line > no. of lines}
056 */
057 long getPosition(long line, long column);
058
059 /**
060 * Find the line containing a position; a line termination
061 * character is on the line it terminates.
062 *
063 * @param pos character offset of the position
064 * @return the line number of pos (first line is 1)
065 */
066 long getLineNumber(long pos);
067
068 /**
069 * Find the column for a character position.
070 * Tab characters preceding the position on the same line
071 * will be expanded when calculating the column number.
072 *
073 * @param pos character offset of the position
074 * @return the tab-expanded column number of pos (first column is 1)
075 */
076 long getColumnNumber(long pos);
077
078 }