Lines 72-77
Link Here
|
72 |
import org.netbeans.modules.java.source.builder.CommentHandlerService; |
72 |
import org.netbeans.modules.java.source.builder.CommentHandlerService; |
73 |
import org.netbeans.modules.java.source.builder.CommentSetImpl; |
73 |
import org.netbeans.modules.java.source.builder.CommentSetImpl; |
74 |
import org.netbeans.modules.java.source.parsing.SourceFileObject; |
74 |
import org.netbeans.modules.java.source.parsing.SourceFileObject; |
|
|
75 |
import org.netbeans.modules.java.source.query.CommentSet.RelativePosition; |
75 |
import org.openide.util.Exceptions; |
76 |
import org.openide.util.Exceptions; |
76 |
|
77 |
|
77 |
/** |
78 |
/** |
Lines 184-206
Link Here
|
184 |
*/ |
185 |
*/ |
185 |
public List<Comment> getComments(Tree tree, boolean preceding) { |
186 |
public List<Comment> getComments(Tree tree, boolean preceding) { |
186 |
CommentSetImpl set = handler.getComments(tree); |
187 |
CommentSetImpl set = handler.getComments(tree); |
|
|
188 |
|
189 |
ensureCommentsMapped(info, tree, set); |
190 |
|
191 |
List<Comment> comments = preceding ? set.getPrecedingComments() : set.getTrailingComments(); |
187 |
|
192 |
|
|
|
193 |
return Collections.unmodifiableList(comments); |
194 |
} |
195 |
|
196 |
static void ensureCommentsMapped(CompilationInfo info, Tree tree, CommentSetImpl set) { |
188 |
if (!set.areCommentsMapped()) { |
197 |
if (!set.areCommentsMapped()) { |
189 |
boolean assertsEnabled = false; |
198 |
boolean assertsEnabled = false; |
190 |
boolean automap = true; |
199 |
boolean automap = true; |
191 |
|
200 |
|
192 |
assert assertsEnabled = true; |
201 |
assert assertsEnabled = true; |
193 |
|
202 |
|
194 |
if (assertsEnabled) { |
203 |
if (assertsEnabled) { |
195 |
TreePath tp = info.getCompilationUnit() == tree ? new TreePath(info.getCompilationUnit()) : TreePath.getPath(info.getCompilationUnit(), tree); |
204 |
TreePath tp = info.getCompilationUnit() == tree ? new TreePath(info.getCompilationUnit()) : TreePath.getPath(info.getCompilationUnit(), tree); |
196 |
|
205 |
|
197 |
if (tp == null) { |
206 |
if (tp == null) { |
198 |
Logger.getLogger(TreeUtilities.class.getName()).log(Level.WARNING, "Comment automap requested for Tree not from the root compilation info. Please, make sure to call GeneratorUtilities.importComments before Treeutilities.getComments. Tree: {0}", tree); |
207 |
Logger.getLogger(TreeUtilities.class.getName()).log(Level.WARNING, "Comment automap requested for Tree not from the root compilation info. Please, make sure to call GeneratorUtilities.importComments before Treeutilities.getComments. Tree: {0}", tree); |
199 |
Logger.getLogger(TreeUtilities.class.getName()).log(Level.INFO, "Caller", new Exception()); |
208 |
Logger.getLogger(TreeUtilities.class.getName()).log(Level.INFO, "Caller", new Exception()); |
200 |
automap = false; |
209 |
automap = false; |
201 |
} |
210 |
} |
202 |
} |
211 |
} |
203 |
|
212 |
|
204 |
if (automap) { |
213 |
if (automap) { |
205 |
try { |
214 |
try { |
206 |
TokenSequence<JavaTokenId> seq = ((SourceFileObject) info.getCompilationUnit().getSourceFile()).getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
215 |
TokenSequence<JavaTokenId> seq = ((SourceFileObject) info.getCompilationUnit().getSourceFile()).getTokenHierarchy().tokenSequence(JavaTokenId.language()); |
Lines 210-221
Link Here
|
210 |
} |
219 |
} |
211 |
} |
220 |
} |
212 |
} |
221 |
} |
213 |
|
|
|
214 |
List<Comment> comments = preceding ? set.getPrecedingComments() : set.getTrailingComments(); |
215 |
|
216 |
return Collections.unmodifiableList(comments); |
217 |
} |
222 |
} |
218 |
|
223 |
|
219 |
public TreePath pathFor(int pos) { |
224 |
public TreePath pathFor(int pos) { |
220 |
return pathFor(new TreePath(info.getCompilationUnit()), pos); |
225 |
return pathFor(new TreePath(info.getCompilationUnit()), pos); |
221 |
} |
226 |
} |