|
1 /* |
|
2 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
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 |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package com.sun.source.util; |
|
27 |
|
28 import com.sun.source.tree.*; |
|
29 |
|
30 /** |
|
31 * Provides methods to obtain the position of a Tree within a CompilationUnit. |
|
32 * A position is defined as a simple character offset from the start of a |
|
33 * CompilationUnit where the first character is at offset 0. |
|
34 * |
|
35 * @author Peter von der Ahé |
|
36 * @since 1.6 |
|
37 */ |
|
38 public interface SourcePositions { |
|
39 |
|
40 /** |
|
41 * Gets the starting position of tree within file. If tree is not found within |
|
42 * file, or if the starting position is not available, |
|
43 * return {@link javax.tools.Diagnostic#NOPOS}. |
|
44 * The returned position must be at the start of the yield of this tree, that |
|
45 * is for any sub-tree of this tree, the following must hold: |
|
46 * |
|
47 * <p> |
|
48 * {@code tree.getStartPosition() <= subtree.getStartPosition()} or <br> |
|
49 * {@code tree.getStartPosition() == NOPOS} or <br> |
|
50 * {@code subtree.getStartPosition() == NOPOS} |
|
51 * </p> |
|
52 * |
|
53 * @param file CompilationUnit in which to find tree. |
|
54 * @param tree tree for which a position is sought. |
|
55 * @return the start position of tree. |
|
56 */ |
|
57 long getStartPosition(CompilationUnitTree file, Tree tree); |
|
58 |
|
59 /** |
|
60 * Gets the ending position of tree within file. If tree is not found within |
|
61 * file, or if the starting position is not available, |
|
62 * return {@link javax.tools.Diagnostic#NOPOS}. |
|
63 * The returned position must be at the end of the yield of this tree, |
|
64 * that is for any sub-tree of this tree, the following must hold: |
|
65 * |
|
66 * <p> |
|
67 * {@code tree.getEndPosition() >= subtree.getEndPosition()} or <br> |
|
68 * {@code tree.getEndPosition() == NOPOS} or <br> |
|
69 * {@code subtree.getEndPosition() == NOPOS} |
|
70 * </p> |
|
71 * |
|
72 * In addition, the following must hold: |
|
73 * |
|
74 * <p> |
|
75 * {@code tree.getStartPosition() <= tree.getEndPosition()} or <br> |
|
76 * {@code tree.getStartPosition() == NOPOS} or <br> |
|
77 * {@code tree.getEndPosition() == NOPOS} |
|
78 * </p> |
|
79 * |
|
80 * @param file CompilationUnit in which to find tree. |
|
81 * @param tree tree for which a position is sought. |
|
82 * @return the end position of tree. |
|
83 */ |
|
84 long getEndPosition(CompilationUnitTree file, Tree tree); |
|
85 |
|
86 } |