1 /* |
1 /* |
2 * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
77 lineMap.build(src, max); |
77 lineMap.build(src, max); |
78 return lineMap; |
78 return lineMap; |
79 } |
79 } |
80 |
80 |
81 /** Encode line and column numbers in an integer as: |
81 /** Encode line and column numbers in an integer as: |
82 * line-number << LINESHIFT + column-number |
82 * {@code line-number << LINESHIFT + column-number }. |
83 * {@link Position.NOPOS represents an undefined position. |
83 * {@link Position.NOPOS} represents an undefined position. |
84 * |
84 * |
85 * @param line number of line (first is 1) |
85 * @param line number of line (first is 1) |
86 * @param col number of character on line (first is 1) |
86 * @param col number of character on line (first is 1) |
87 * @return an encoded position or {@link Position.NOPOS |
87 * @return an encoded position or {@link Position.NOPOS} |
88 * if the line or column number is too big to |
88 * if the line or column number is too big to |
89 * represent in the encoded format |
89 * represent in the encoded format |
90 * @throws IllegalArgumentException if line or col is less than 1 |
90 * @throws IllegalArgumentException if line or col is less than 1 |
91 */ |
91 */ |
92 public static int encodePosition(int line, int col) { |
92 public static int encodePosition(int line, int col) { |
105 /** Find the start position of a line. |
105 /** Find the start position of a line. |
106 * |
106 * |
107 * @param line number of line (first is 1) |
107 * @param line number of line (first is 1) |
108 * @return position of first character in line |
108 * @return position of first character in line |
109 * @throws ArrayIndexOutOfBoundsException |
109 * @throws ArrayIndexOutOfBoundsException |
110 * if <tt>lineNumber < 1</tt> |
110 * if {@code lineNumber < 1} |
111 * if <tt>lineNumber > no. of lines</tt> |
111 * if {@code lineNumber > no. of lines} |
112 */ |
112 */ |
113 int getStartPosition(int line); |
113 int getStartPosition(int line); |
114 |
114 |
115 /** Find the position corresponding to a (line,column). |
115 /** Find the position corresponding to a (line,column). |
116 * |
116 * |
117 * @param line number of line (first is 1) |
117 * @param line number of line (first is 1) |
118 * @param column number of character on line (first is 1) |
118 * @param column number of character on line (first is 1) |
119 * |
119 * |
120 * @return position of character |
120 * @return position of character |
121 * @throws ArrayIndexOutOfBoundsException |
121 * @throws ArrayIndexOutOfBoundsException |
122 * if <tt>line < 1</tt> |
122 * if {@code line < 1} |
123 * if <tt>line > no. of lines</tt> |
123 * if {@code line > no. of lines} |
124 */ |
124 */ |
125 int getPosition(int line, int column); |
125 int getPosition(int line, int column); |
126 |
126 |
127 /** Find the line containing a position; a line termination |
127 /** Find the line containing a position; a line termination |
128 * character is on the line it terminates. |
128 * character is on the line it terminates. |