/**Returns list of comments attached to a given tree. Can return either * preceding or trailing comments. * * @param tree for which comments should be returned * @param preceding true if preceding comments should be returned, false if trailing comments should be returned. * @return list of preceding/trailing comments attached to the given tree */ public List<Comment> getComments(Tree tree, boolean preceding) { CommentSetImpl set = handler.getComments(tree); ensureCommentsMapped(info, tree, set); List<Comment> comments = preceding ? set.getPrecedingComments() : set.getTrailingComments(); return Collections.unmodifiableList(comments); }
/** * Copy comments from source tree to target tree. Copying a given comment twice will be ignored. * * @param source tree to copy comments from * @param target tree to copy comments to * @param preceding true iff preceding comments should be copied * @since 0.51 */ public void copyComments(Tree source, Tree target, boolean preceding) { CommentHandlerService handler = CommentHandlerService.instance(copy.impl.getJavacTask().getContext()); CommentSetImpl s = handler.getComments(source); TreeUtilities.ensureCommentsMapped(copy, source, s); CommentSetImpl t = handler.getComments(target); if (preceding) { t.addComments(RelativePosition.PRECEDING, copy.useComments(s.getComments(RelativePosition.PRECEDING))); t.addComments(RelativePosition.INNER, copy.useComments(s.getComments(RelativePosition.INNER))); } else { t.addComments(RelativePosition.INLINE, copy.useComments(s.getComments(RelativePosition.INLINE))); t.addComments(RelativePosition.TRAILING, copy.useComments(s.getComments(RelativePosition.TRAILING))); } }