Node for the root of a parse tree. It contains the statements and functions in the script, and a list of Comment nodes associated with the script as a whole. Node type is Token#SCRIPT. Note that the tree itself does not store errors. To collect the parse errors and warnings, pass
| 21 | * via the {@link org.mozilla.javascript.CompilerEnvirons}. |
| 22 | */ |
| 23 | public class AstRoot extends ScriptNode { |
| 24 | |
| 25 | private SortedSet<Comment> comments; |
| 26 | |
| 27 | { |
| 28 | type = Token.SCRIPT; |
| 29 | } |
| 30 | |
| 31 | public AstRoot() {} |
| 32 | |
| 33 | public AstRoot(int pos) { |
| 34 | super(pos); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Returns comment set |
| 39 | * |
| 40 | * @return comment set, sorted by start position. Can be {@code null}. |
| 41 | */ |
| 42 | public SortedSet<Comment> getComments() { |
| 43 | return comments; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Sets comment list, and updates the parent of each entry to point to this node. Replaces any |
| 48 | * existing comments. |
| 49 | * |
| 50 | * @param comments comment list. can be {@code null}. |
| 51 | */ |
| 52 | public void setComments(SortedSet<Comment> comments) { |
| 53 | if (comments == null) { |
| 54 | this.comments = null; |
| 55 | } else { |
| 56 | if (this.comments != null) this.comments.clear(); |
| 57 | for (Comment c : comments) addComment(c); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Add a comment to the comment set. |
| 63 | * |
| 64 | * @param comment the comment node. |
| 65 | * @throws IllegalArgumentException if comment is {@code null} |
| 66 | */ |
| 67 | public void addComment(Comment comment) { |
| 68 | assertNotNull(comment); |
| 69 | if (comments == null) { |
| 70 | comments = new TreeSet<>(new AstNode.PositionComparator()); |
| 71 | } |
| 72 | comments.add(comment); |
| 73 | comment.setParent(this); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Visits the comment nodes in the order they appear in the source code. The comments are not |
| 78 | * visited by the {@link #visit} function - you must use this function to visit them. |
| 79 | * |
| 80 | * @param visitor the callback object. It is passed each comment node. The return value is |
nothing calls this directly
no outgoing calls
no test coverage detected