1 /*
2 * Copyright (c) 2013, 2021, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.source.util;
27
28 import com.sun.source.doctree.DocCommentTree;
29 import com.sun.source.doctree.DocTree;
30 import com.sun.source.tree.CompilationUnitTree;
31 import com.sun.source.tree.Tree;
32
33 /**
34 * Provides methods to obtain the position of a DocTree within a javadoc comment.
35 * A position is defined as a simple character offset from the start of a
36 * CompilationUnit where the first character is at offset 0.
37 *
38 * @since 1.8
39 */
40 public interface DocSourcePositions extends SourcePositions {
41
42 /**
43 * Returns the starting position of the tree within the comment within the file. If tree is not found within
44 * file, or if the starting position is not available,
45 * returns {@link javax.tools.Diagnostic#NOPOS}.
46 * The given tree should be under the given comment tree, and the given documentation
47 * comment tree should be returned from a {@link DocTrees#getDocCommentTree(com.sun.source.util.TreePath) }
48 * for a tree under the given file.
49 * The returned position must be at the start of the yield of this tree, that
50 * is for any sub-tree of this tree, the following must hold:
51 *
52 * <p>
53 * {@code getStartPosition(file, comment, tree) <= getStartPosition(file, comment, subtree)} or <br>
54 * {@code getStartPosition(file, comment, tree) == NOPOS} or <br>
55 * {@code getStartPosition(file, comment, subtree) == NOPOS}
56 * </p>
57 *
58 * @param file compilation unit in which to find tree
59 * @param comment the comment tree that encloses the tree for which the
60 * position is being sought
61 * @param tree tree for which a position is sought
62 * @return the start position of tree
63 * @deprecated use {@link #getStartPosition(DocCommentTree, DocTree)} instead
64 */
65 @Deprecated(since = "27", forRemoval = true)
66 default long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
67 return getStartPosition(comment, tree);
68 }
69
70 /**
71 * {@return the starting position of the given {@link Tree}. If the starting position is not available, returns
72 * {@link javax.tools.Diagnostic#NOPOS}}
73 *
74 * <p>The given tree should be under the given comment tree. The returned position must be at the start of the
75 * yield of this tree, that is for any sub-tree of this tree, the following must hold:
76 *
77 * <p>
78 * {@code getStartPosition(comment, tree) <= getStartPosition(comment, subtree)} or <br>
79 * {@code getStartPosition(comment, tree) == NOPOS} or <br>
80 * {@code getStartPosition(comment, subtree) == NOPOS}
81 * </p>
82 *
83 * @param comment the comment tree that encloses the tree for which the
84 * position is being sought
85 * @param tree tree for which a position is sought
86 */
87 long getStartPosition(DocCommentTree comment, DocTree tree);
88
89 /**
90 * Returns the ending position of the tree within the comment within the file. If tree is not found within
91 * file, or if the ending position is not available,
92 * returns {@link javax.tools.Diagnostic#NOPOS}.
93 * The given tree should be under the given comment tree, and the given documentation
94 * comment tree should be returned from a {@link DocTrees#getDocCommentTree(com.sun.source.util.TreePath) }
95 * for a tree under the given file.
96 * The returned position must be at the end of the yield of this tree,
97 * that is for any sub-tree of this tree, the following must hold:
98 *
99 * <p>
100 * {@code getEndPosition(file, comment, tree) >= getEndPosition(file, comment, subtree)} or <br>
101 * {@code getEndPosition(file, comment, tree) == NOPOS} or <br>
102 * {@code getEndPosition(file, comment, subtree) == NOPOS}
103 * </p>
104 *
105 * In addition, the following must hold:
106 *
107 * <p>
108 * {@code getStartPosition(file, comment, tree) <= getEndPosition(file, comment, tree)} or <br>
109 * {@code getStartPosition(file, comment, tree) == NOPOS} or <br>
110 * {@code getEndPosition(file, comment, tree) == NOPOS}
111 * </p>
112 *
113 * @param file compilation unit in which to find tree
114 * @param comment the comment tree that encloses the tree for which the
115 * position is being sought
116 * @param tree tree for which a position is sought
117 * @return the end position of tree
118 * @deprecated use {@link #getEndPosition(DocCommentTree, DocTree)} instead
119 */
120 @Deprecated(since = "27", forRemoval = true)
121 default long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) {
122 return getEndPosition(comment, tree);
123 }
124
125 /**
126 * {@return the ending position of the given {@link Tree}. If the ending position is not available, returns
127 * {@link javax.tools.Diagnostic#NOPOS}}
128 *
129 * <p>The given tree should be under the given comment tree. The returned position must be at the end of the yield
130 * of this tree, that is for any sub-tree of this tree, the following must hold:
131 *
132 * <p>
133 * {@code getEndPosition(comment, tree) >= getEndPosition(comment, subtree)} or <br>
134 * {@code getEndPosition(comment, tree) == NOPOS} or <br>
135 * {@code getEndPosition(comment, subtree) == NOPOS}
136 * </p>
137 *
138 * In addition, the following must hold:
139 *
140 * <p>
141 * {@code getStartPosition(comment, tree) <= getEndPosition(comment, tree)} or <br>
142 * {@code getStartPosition(comment, tree) == NOPOS} or <br>
143 * {@code getEndPosition(comment, tree) == NOPOS}
144 * </p>
145 *
146 * @param comment the comment tree that encloses the tree for which the
147 * position is being sought
148 * @param tree tree for which a position is sought
149 */
150 long getEndPosition(DocCommentTree comment, DocTree tree);
151
152 }