1 package net.sourceforge.phpdt.core.dom;
3 /*******************************************************************************
4 * Copyright (c) 2000, 2004 IBM Corporation and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Common Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/cpl-v10.html
11 * IBM Corporation - initial API and implementation
12 *******************************************************************************/
15 * Java compilation unit AST node type. This is the type of the root of an AST.
17 * The source range for this type of node is ordinarily the entire source file,
18 * including leading and trailing whitespace and comments.
24 * [ PackageDeclaration ]
25 * { ImportDeclaration }
26 * { TypeDeclaration | <b>;</b> }
29 * For JLS3, the kinds of type declarations grew to include enum and annotation
34 * [ PackageDeclaration ]
35 * { ImportDeclaration }
36 * { TypeDeclaration | EnumDeclaration | AnnotationTypeDeclaration | <b>;</b> }
41 public class CompilationUnit {
44 // * The "package" structural property of this node type.
48 // public static final ChildPropertyDescriptor PACKAGE_PROPERTY =
49 // new ChildPropertyDescriptor(CompilationUnit.class, "package",
50 // PackageDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
53 // * The "imports" structural property of this node type.
57 // public static final ChildListPropertyDescriptor IMPORTS_PROPERTY =
58 // new ChildListPropertyDescriptor(CompilationUnit.class, "imports",
59 // ImportDeclaration.class, NO_CYCLE_RISK); //$NON-NLS-1$
62 // * The "types" structural property of this node type.
66 // public static final ChildListPropertyDescriptor TYPES_PROPERTY =
67 // new ChildListPropertyDescriptor(CompilationUnit.class, "types",
68 // AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
71 // * A list of property descriptors (element type:
72 // * {@link StructuralPropertyDescriptor}),
73 // * or null if uninitialized.
76 // private static final List PROPERTY_DESCRIPTORS;
79 // createPropertyList(CompilationUnit.class);
80 // addProperty(PACKAGE_PROPERTY);
81 // addProperty(IMPORTS_PROPERTY);
82 // addProperty(TYPES_PROPERTY);
83 // PROPERTY_DESCRIPTORS = reapPropertyList();
87 // * Returns a list of structural property descriptors for this node type.
88 // * Clients must not modify the result.
90 // * @param apiLevel the API level; one of the
91 // * <code>AST.JLS*</code> constants
93 // * @return a list of property descriptors (element type:
94 // * {@link StructuralPropertyDescriptor})
97 // public static List propertyDescriptors(int apiLevel) {
98 // return PROPERTY_DESCRIPTORS;
102 // * The comment table, or <code>null</code> if none; initially
103 // * <code>null</code>. This array is the storage underlying
104 // * the <code>optionalCommentList</code> ArrayList.
107 // Comment[] optionalCommentTable = null;
110 // * The comment list (element type: <code>Comment</code>,
111 // * or <code>null</code> if none; initially <code>null</code>.
114 // private List optionalCommentList = null;
117 // * The package declaration, or <code>null</code> if none; initially
118 // * <code>null</code>.
120 // private PackageDeclaration optionalPackageDeclaration = null;
123 // * The list of import declarations in textual order order;
124 // * initially none (elementType: <code>ImportDeclaration</code>).
126 // private ASTNode.NodeList imports =
127 // new ASTNode.NodeList(IMPORTS_PROPERTY);
130 // * The list of type declarations in textual order order;
131 // * initially none (elementType: <code>AbstractTypeDeclaration</code>)
133 // private ASTNode.NodeList types =
134 // new ASTNode.NodeList(TYPES_PROPERTY);
137 // * Line end table. If <code>lineEndTable[i] == p</code> then the
138 // * line number <code>i+1</code> ends at character position
139 // * <code>p</code>. Except for the last line, the positions are that
140 // * of the last character of the line delimiter.
141 // * For example, the source string <code>A\nB\nC</code> has
142 // * line end table {1, 3} (if \n is one character).
144 // private int[] lineEndTable = new int[0];
147 // * Canonical empty list of messages.
149 // private static final Message[] EMPTY_MESSAGES = new Message[0];
152 // * Canonical empty list of problems.
154 // private static final IProblem[] EMPTY_PROBLEMS = new IProblem[0];
157 // * Messages reported by the compiler during parsing or name resolution.
159 // private Message[] messages;
162 // * Problems reported by the compiler during parsing or name resolution.
164 // private IProblem[] problems = EMPTY_PROBLEMS;
167 // * The comment mapper, or <code>null</code> in none;
168 // * initially <code>null</code>.
171 // private DefaultCommentMapper commentMapper = null;
174 // * Sets the line end table for this compilation unit.
175 // * If <code>lineEndTable[i] == p</code> then line number <code>i+1</code>
176 // * ends at character position <code>p</code>. Except for the last line,
178 // * positions are that of (the last character of) the line delimiter.
179 // * For example, the source string <code>A\nB\nC</code> has
180 // * line end table {1, 3, 4}.
182 // * @param lineEndtable the line end table
184 // void setLineEndTable(int[] lineEndTable) {
185 // if (lineEndTable == null) {
186 // throw new NullPointerException();
188 // // alternate root is *not* considered a structural property
189 // // but we protect them nevertheless
190 // checkModifiable();
191 // this.lineEndTable = lineEndTable;
195 // * Creates a new AST node for a compilation owned by the given AST.
196 // * The compilation unit initially has no package declaration, no
197 // * import declarations, and no type declarations.
199 // * N.B. This constructor is package-private; all subclasses must be
200 // * declared in the same package; clients are unable to declare
201 // * additional subclasses.
204 // * @param ast the AST that is to own this node
206 // CompilationUnit(AST ast) {
210 // /* (omit javadoc for this method)
211 // * Method declared on ASTNode.
214 // final List internalStructuralPropertiesForType(int apiLevel) {
215 // return propertyDescriptors(apiLevel);
218 // /* (omit javadoc for this method)
219 // * Method declared on ASTNode.
221 // final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor
222 // property, boolean get, ASTNode child) {
223 // if (property == PACKAGE_PROPERTY) {
225 // return getPackage();
227 // setPackage((PackageDeclaration) child);
231 // // allow default implementation to flag the error
232 // return super.internalGetSetChildProperty(property, get, child);
235 // /* (omit javadoc for this method)
236 // * Method declared on ASTNode.
238 // final List internalGetChildListProperty(ChildListPropertyDescriptor
240 // if (property == IMPORTS_PROPERTY) {
243 // if (property == TYPES_PROPERTY) {
246 // // allow default implementation to flag the error
247 // return super.internalGetChildListProperty(property);
250 // /* (omit javadoc for this method)
251 // * Method declared on ASTNode.
253 // final int getNodeType0() {
254 // return COMPILATION_UNIT;
257 // /* (omit javadoc for this method)
258 // * Method declared on ASTNode.
260 // ASTNode clone0(AST target) {
261 // CompilationUnit result = new CompilationUnit(target);
262 // // n.b do not copy line number table or messages
263 // result.setSourceRange(this.getStartPosition(), this.getLength());
264 // result.setPackage(
265 // (PackageDeclaration) ASTNode.copySubtree(target, getPackage()));
266 // result.imports().addAll(ASTNode.copySubtrees(target, imports()));
267 // result.types().addAll(ASTNode.copySubtrees(target, types()));
271 // /* (omit javadoc for this method)
272 // * Method declared on ASTNode.
274 // final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
275 // // dispatch to correct overloaded match method
276 // return matcher.match(this, other);
279 // /* (omit javadoc for this method)
280 // * Method declared on ASTNode.
282 // void accept0(ASTVisitor visitor) {
283 // boolean visitChildren = visitor.visit(this);
284 // if (visitChildren) {
285 // // visit children in normal left to right reading order
286 // acceptChild(visitor, getPackage());
287 // acceptChildren(visitor, this.imports);
288 // acceptChildren(visitor, this.types);
290 // visitor.endVisit(this);
294 // * Returns the node for the package declaration of this compilation
295 // * unit, or <code>null</code> if this compilation unit is in the
296 // * default package.
298 // * @return the package declaration node, or <code>null</code> if none
300 // public PackageDeclaration getPackage() {
301 // return this.optionalPackageDeclaration;
305 // * Sets or clears the package declaration of this compilation unit
306 // * node to the given package declaration node.
308 // * @param pkgDecl the new package declaration node, or
309 // * <code>null</code> if this compilation unit does not have a package
310 // * declaration (that is in the default package)
311 // * @exception IllegalArgumentException if:
313 // * <li>the node belongs to a different AST</li>
314 // * <li>the node already has a parent</li>
317 // public void setPackage(PackageDeclaration pkgDecl) {
318 // ASTNode oldChild = this.optionalPackageDeclaration;
319 // preReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
320 // this.optionalPackageDeclaration = pkgDecl;
321 // postReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
325 // * Returns the live list of nodes for the import declarations of this
326 // * compilation unit, in order of appearance.
328 // * @return the live list of import declaration nodes
329 // * (elementType: <code>ImportDeclaration</code>)
331 // public List imports() {
332 // return this.imports;
336 // * Returns the live list of nodes for the top-level type declarations of
338 // * compilation unit, in order of appearance.
340 // * Note that in JLS3, the types may include both enum declarations
341 // * and annotation type declarations introduced in J2SE 1.5.
342 // * For JLS2, the elements are always <code>TypeDeclaration</code>.
345 // * @return the live list of top-level type declaration
346 // * nodes (elementType: <code>AbstractTypeDeclaration</code>)
348 // public List types() {
349 // return this.types;
353 // * Finds the corresponding AST node in the given compilation unit from
354 // * which the given binding originated. Returns <code>null</code> if the
355 // * binding does not correspond to any node in this compilation unit.
356 // * This method always returns <code>null</code> if bindings were not
358 // * when this AST was built.
360 // * The following table indicates the expected node type for the various
361 // * different kinds of bindings:
364 // * <li>package - a <code>PackageDeclaration</code></li>
365 // * <li>class or interface - a <code>TypeDeclaration</code> or a
366 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
367 // * <li>primitive type - none</li>
368 // * <li>array type - none</li>
369 // * <li>field - a <code>VariableDeclarationFragment</code> in a
370 // * <code>FieldDeclaration</code> </li>
371 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
372 // * a <code>VariableDeclarationFragment</code> in a
373 // * <code>VariableDeclarationStatement</code> or
374 // * <code>VariableDeclarationExpression</code></li>
375 // * <li>method - a <code>MethodDeclaration</code> </li>
376 // * <li>constructor - a <code>MethodDeclaration</code> </li>
377 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
378 // * <li>annotation type member - an
379 // <code>AnnotationTypeMemberDeclaration</code></li>
380 // * <li>enum type - an <code>EnumDeclaration</code></li>
381 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
385 // * Each call to {@link ASTParser#createAST(IProgressMonitor)} with a
386 // request for bindings
387 // * gives rise to separate universe of binding objects. This method always
389 // * <code>null</code> when the binding object comes from a different AST.
390 // * Use <code>findDeclaringNode(binding.getKey())</code> when the binding
392 // * from a different AST.
395 // * @param binding the binding
396 // * @return the corresponding node where the given binding is declared,
397 // * or <code>null</code> if the binding does not correspond to a node in
399 // * compilation unit or if bindings were not requested when this AST was
401 // * @see #findDeclaringNode(String)
403 // public ASTNode findDeclaringNode(IBinding binding) {
404 // return this.ast.getBindingResolver().findDeclaringNode(binding);
408 // * Finds the corresponding AST node in the given compilation unit from
409 // * which the binding with the given key originated. Returns
410 // * <code>null</code> if the corresponding node cannot be determined.
411 // * This method always returns <code>null</code> if bindings were not
413 // * when this AST was built.
415 // * The following table indicates the expected node type for the various
416 // * different kinds of binding keys:
419 // * <li>package - a <code>PackageDeclaration</code></li>
420 // * <li>class or interface - a <code>TypeDeclaration</code> or a
421 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
422 // * <li>primitive type - none</li>
423 // * <li>array type - none</li>
424 // * <li>field - a <code>VariableDeclarationFragment</code> in a
425 // * <code>FieldDeclaration</code> </li>
426 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
427 // * a <code>VariableDeclarationFragment</code> in a
428 // * <code>VariableDeclarationStatement</code> or
429 // * <code>VariableDeclarationExpression</code></li>
430 // * <li>method - a <code>MethodDeclaration</code> </li>
431 // * <li>constructor - a <code>MethodDeclaration</code> </li>
432 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
433 // * <li>annotation type member - an
434 // <code>AnnotationTypeMemberDeclaration</code></li>
435 // * <li>enum type - an <code>EnumDeclaration</code></li>
436 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
440 // * Note that as explained in {@link IBinding#getKey() IBinding.getkey}
441 // * there may be no keys for finding the declaring node for local
443 // * local or anonymous classes, etc.
446 // * @param key the binding key, or <code>null</code>
447 // * @return the corresponding node where a binding with the given
448 // * key is declared, or <code>null</code> if the key is <code>null</code>
449 // * or if the key does not correspond to a node in this compilation unit
450 // * or if bindings were not requested when this AST was built
451 // * @see IBinding#getKey()
454 // public ASTNode findDeclaringNode(String key) {
455 // return this.ast.getBindingResolver().findDeclaringNode(key);
459 // * Returns the internal comment mapper.
461 // * @return the comment mapper, or <code>null</code> if none.
464 // DefaultCommentMapper getCommentMapper() {
465 // return this.commentMapper;
469 // * Initializes the internal comment mapper with the given
472 // * @param scanner the scanner
475 // void initCommentMapper(Scanner scanner) {
476 // this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
477 // this.commentMapper.initialize(this, scanner);
481 // * Returns the extended start position of the given node. Unlike
482 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
483 // * the extended source range may include comments and whitespace
484 // * immediately before or after the normal source range for the node.
486 // * @param node the node
487 // * @return the 0-based character index, or <code>-1</code>
488 // * if no source position information is recorded for this node
489 // * @see #getExtendedLength(ASTNode)
492 // public int getExtendedStartPosition(ASTNode node) {
493 // if (this.commentMapper == null) {
496 // return this.commentMapper.getExtendedStartPosition(node);
501 // * Returns the extended source length of the given node. Unlike
502 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
503 // * the extended source range may include comments and whitespace
504 // * immediately before or after the normal source range for the node.
506 // * @param node the node
507 // * @return a (possibly 0) length, or <code>0</code>
508 // * if no source position information is recorded for this node
509 // * @see #getExtendedStartPosition(ASTNode)
512 // public int getExtendedLength(ASTNode node) {
513 // if (this.commentMapper == null) {
516 // return this.commentMapper.getExtendedLength(node);
521 // * Returns the line number corresponding to the given source character
522 // * position in the original source string. The initial line of the
523 // * compilation unit is numbered 1, and each line extends through the
524 // * last character of the end-of-line delimiter. The very last line extends
525 // * through the end of the source string and has no line delimiter.
526 // * For example, the source string <code>class A\n{\n}</code> has 3 lines
527 // * corresponding to inclusive character ranges [0,7], [8,9], and [10,10].
528 // * Returns 1 for a character position that does not correspond to any
529 // * source line, or if no line number information is available for this
530 // * compilation unit.
532 // * @param position a 0-based character position, possibly
533 // * negative or out of range
534 // * @return the 1-based line number, or <code>1</code> if the character
535 // * position does not correspond to a source line in the original
536 // * source file or if line number information is not known for this
537 // * compilation unit
540 // public int lineNumber(int position) {
541 // int length = lineEndTable.length;
542 // if (length == 0) {
543 // // no line number info
547 // if (position <= lineEndTable[low]) {
548 // // position illegal or before the first line delimiter
551 // // assert position > lineEndTable[low+1] && low == 0
552 // int hi = length - 1;
553 // if (position > lineEndTable[hi]) {
554 // // position beyond the last line separator
555 // if (position >= getStartPosition() + getLength()) {
556 // // this is beyond the end of the source length
559 // return length + 1;
562 // // assert lineEndTable[low] < position <= lineEndTable[hi]
563 // // && low == 0 && hi == length - 1 && low < hi
565 // // binary search line end table
567 // // invariant lineEndTable[low] < position <= lineEndTable[hi]
568 // // && 0 <= low < hi <= length - 1
569 // // reducing measure hi - low
570 // if (low + 1 == hi) {
571 // // assert lineEndTable[low] < position <= lineEndTable[low+1]
572 // // position is on line low+1 (line number is low+2)
575 // // assert hi - low >= 2, so average is truly in between
576 // int mid = (low + hi) / 2;
577 // // assert 0 <= low < mid < hi <= length - 1
578 // if (position <= lineEndTable[mid]) {
579 // // assert lineEndTable[low] < position <= lineEndTable[mid]
580 // // && 0 <= low < mid < hi <= length - 1
583 // // position > lineEndTable[mid]
584 // // assert lineEndTable[mid] < position <= lineEndTable[hi]
585 // // && 0 <= low < mid < hi <= length - 1
588 // // in both cases, invariant reachieved with reduced measure
593 // * Returns the list of messages reported by the compiler during the
595 // * or the type checking of this compilation unit. This list might be a
597 // * errors detected and reported by a Java compiler.
599 // * This list of messages is suitable for simple clients that do little
600 // * more than log the messages or display them to the user. Clients that
601 // * need further details should call <code>getProblems</code> to get
602 // * compiler problem objects.
605 // * @return the list of messages, possibly empty
606 // * @see #getProblems()
609 // public Message[] getMessages() {
610 // if (this.messages == null) {
611 // int problemLength = this.problems.length;
612 // if (problemLength == 0) {
613 // this.messages = EMPTY_MESSAGES;
615 // this.messages = new Message[problemLength];
616 // for (int i = 0; i < problemLength; i++) {
617 // IProblem problem = this.problems[i];
618 // int start = problem.getSourceStart();
619 // int end = problem.getSourceEnd();
620 // messages[i] = new Message(problem.getMessage(), start, end - start + 1);
624 // return this.messages;
628 // * Returns the list of detailed problem reports noted by the compiler
629 // * during the parsing or the type checking of this compilation unit. This
630 // * list might be a subset of errors detected and reported by a Java
633 // * Simple clients that do little more than log the messages or display
634 // * them to the user should probably call <code>getMessages</code> instead.
637 // * @return the list of detailed problem objects, possibly empty
638 // * @see #getMessages()
642 // public IProblem[] getProblems() {
643 // return this.problems;
647 // * Sets the array of problems reported by the compiler during the parsing
649 // * name resolution of this compilation unit.
651 // * @param problems the list of problems
653 // void setProblems(IProblem[] problems) {
654 // if (problems == null) {
655 // throw new IllegalArgumentException();
657 // this.problems = problems;
661 // * Returns a list of the comments encountered while parsing
662 // * this compilation unit.
664 // * Since the Java language allows comments to appear most anywhere
665 // * in the source text, it is problematic to locate comments in relation
666 // * to the structure of an AST. The one exception is doc comments
667 // * which, by convention, immediately precede type, field, and
668 // * method declarations; these comments are located in the AST
669 // * by {@link BodyDeclaration#getJavadoc BodyDeclaration.getJavadoc}.
670 // * Other comments do not show up in the AST. The table of comments
671 // * is provided for clients that need to find the source ranges of
672 // * all comments in the original source string. It includes entries
673 // * for comments of all kinds (line, block, and doc), arranged in order
674 // * of increasing source position.
676 // * Note on comment parenting: The {@link ASTNode#getParent() getParent()}
677 // * of a doc comment associated with a body declaration is the body
678 // * declaration node; for these comment nodes
679 // * {@link ASTNode#getRoot() getRoot()} will return the compilation unit
680 // * (assuming an unmodified AST) reflecting the fact that these nodes
681 // * are property located in the AST for the compilation unit.
682 // * However, for other comment nodes, {@link ASTNode#getParent()
684 // * will return <code>null</code>, and {@link ASTNode#getRoot() getRoot()}
685 // * will return the comment node itself, indicating that these comment
687 // * are not directly connected to the AST for the compilation unit. The
688 // * {@link Comment#getAlternateRoot Comment.getAlternateRoot}
689 // * method provides a way to navigate from a comment to its compilation
693 // * A note on visitors: The only comment nodes that will be visited when
694 // * visiting a compilation unit are the doc comments parented by body
695 // * declarations. To visit all comments in normal reading order, iterate
696 // * over the comment table and call {@link ASTNode#accept(ASTVisitor)
698 // * on each element.
701 // * Clients cannot modify the resulting list.
704 // * @return an unmodifiable list of comments in increasing order of source
705 // * start position, or <code>null</code> if comment information
706 // * for this compilation unit is not available
710 // public List getCommentList() {
711 // return this.optionalCommentList;
715 // * Sets the list of the comments encountered while parsing
716 // * this compilation unit.
718 // * @param commentTable a list of comments in increasing order
719 // * of source start position, or <code>null</code> if comment
720 // * information for this compilation unit is not available
721 // * @exception IllegalArgumentException if the comment table is
722 // * not in increasing order of source position
723 // * @see #getCommentList()
727 // void setCommentTable(Comment[] commentTable) {
728 // // double check table to ensure that all comments have
729 // // source positions and are in strictly increasing order
730 // if (commentTable == null) {
731 // this.optionalCommentList = null;
732 // this.optionalCommentTable = null;
734 // int nextAvailablePosition = 0;
735 // for (int i = 0; i < commentTable.length; i++) {
736 // Comment comment = commentTable[i];
737 // if (comment == null) {
738 // throw new IllegalArgumentException();
740 // int start = comment.getStartPosition();
741 // int length = comment.getLength();
742 // if (start < 0 || length < 0 || start < nextAvailablePosition) {
743 // throw new IllegalArgumentException();
745 // nextAvailablePosition = comment.getStartPosition() + comment.getLength();
747 // this.optionalCommentTable = commentTable;
748 // List commentList = Arrays.asList(commentTable);
749 // // protect the list from further modification
750 // this.optionalCommentList = Collections.unmodifiableList(commentList);
755 // /* (omit javadoc for this method)
756 // * Method declared on ASTNode.
758 // void appendDebugString(StringBuffer buffer) {
759 // buffer.append("CompilationUnit"); //$NON-NLS-1$
760 // // include the type names
761 // buffer.append("["); //$NON-NLS-1$
762 // for (Iterator it = types().iterator(); it.hasNext(); ) {
763 // AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
764 // buffer.append(d.getName().getIdentifier());
765 // if (it.hasNext()) {
766 // buffer.append(","); //$NON-NLS-1$
769 // buffer.append("]"); //$NON-NLS-1$
772 // /* (omit javadoc for this method)
773 // * Method declared on ASTNode.
776 // int size = BASE_NODE_SIZE + 8 * 4;
777 // if (this.lineEndTable != null) {
778 // size += HEADERS + 4 * this.lineEndTable.length;
780 // if (this.optionalCommentTable != null) {
781 // size += HEADERS + 4 * this.optionalCommentTable.length;
783 // // ignore the space taken up by optionalCommentList
787 // /* (omit javadoc for this method)
788 // * Method declared on ASTNode.
791 // int size = memSize();
792 // if (this.optionalPackageDeclaration != null) {
793 // size += getPackage().treeSize();
795 // size += this.imports.listSize();
796 // size += this.types.listSize();
797 // // include disconnected comments
798 // if (this.optionalCommentList != null) {
799 // for (int i = 0; i < this.optionalCommentList.size(); i++) {
800 // Comment comment = (Comment) this.optionalCommentList.get(i);
801 // if (comment != null && comment.getParent() == null) {
802 // size += comment.treeSize();
810 // * Enables the recording of changes to this compilation
811 // * unit and its descendents. The compilation unit must have
812 // * been created by <code>ASTParser</code> and still be in
813 // * its original state. Once recording is on,
814 // * arbitrary changes to the subtree rooted at this compilation
815 // * unit are recorded internally. Once the modification has
816 // * been completed, call <code>rewrite</code> to get an object
817 // * representing the corresponding edits to the original
818 // * source code string.
820 // * @exception IllegalArgumentException if this compilation unit is
821 // * marked as unmodifiable, or if this compilation unit has already
822 // * been tampered with, or recording has already been enabled
825 // public void recordModifications() {
826 // getAST().recordModifications(this);
830 // * Converts all modifications recorded for this compilation
831 // * unit into an object representing the corresponding text
832 // * edits to the given document containing the original source
833 // * code for this compilation unit.
835 // * The compilation unit must have been created by
836 // * <code>ASTParser</code> from the source code string in the
837 // * given document, and recording must have been turned
838 // * on with a prior call to <code>recordModifications</code>
839 // * while the AST was still in its original state.
842 // * Calling this methods does not discard the modifications
843 // * on record. Subsequence modifications made to the AST
844 // * are added to the ones already on record. If this method
845 // * is called again later, the resulting text edit object will
846 // * accurately reflect the net cumulative affect of all those
850 // * @param document original document containing source code
851 // * for this compilation unit
852 // * @param options the table of formatter options
853 // * (key type: <code>String</code>; value type: <code>String</code>);
854 // * or <code>null</code> to use the standard global options
855 // * {@link JavaCore#getOptions() JavaCore.getOptions()}.
856 // * @return text edit object describing the changes to the
857 // * document corresponding to the recorded AST modifications
858 // * @exception IllegalArgumentException if the document passed is
859 // * <code>null</code> or does not correspond to this AST
860 // * @exception IllegalStateException if <code>recordModifications</code>
861 // * was not called to enable recording
862 // * @see #recordModifications()
865 // public TextEdit rewrite(IDocument document, Map options) {
866 // return getAST().rewrite(document, options);