1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
16 * Java compilation unit AST node type. This is the type of the root of an AST.
18 * The source range for this type of node is ordinarily the entire source file,
19 * including leading and trailing whitespace and comments.
24 * [ PackageDeclaration ]
25 * { ImportDeclaration }
26 * { TypeDeclaration | <b>;</b> }
28 * For JLS3, the kinds of type declarations
29 * grew to include enum and annotation type declarations:
32 * [ PackageDeclaration ]
33 * { ImportDeclaration }
34 * { TypeDeclaration | EnumDeclaration | AnnotationTypeDeclaration | <b>;</b> }
39 public class CompilationUnit {
42 // * The "package" structural property of this node type.
46 // public static final ChildPropertyDescriptor PACKAGE_PROPERTY =
47 // new ChildPropertyDescriptor(CompilationUnit.class, "package", PackageDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
50 // * The "imports" structural property of this node type.
54 // public static final ChildListPropertyDescriptor IMPORTS_PROPERTY =
55 // new ChildListPropertyDescriptor(CompilationUnit.class, "imports", ImportDeclaration.class, NO_CYCLE_RISK); //$NON-NLS-1$
58 // * The "types" structural property of this node type.
62 // public static final ChildListPropertyDescriptor TYPES_PROPERTY =
63 // new ChildListPropertyDescriptor(CompilationUnit.class, "types", AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
66 // * A list of property descriptors (element type:
67 // * {@link StructuralPropertyDescriptor}),
68 // * or null if uninitialized.
71 // private static final List PROPERTY_DESCRIPTORS;
74 // createPropertyList(CompilationUnit.class);
75 // addProperty(PACKAGE_PROPERTY);
76 // addProperty(IMPORTS_PROPERTY);
77 // addProperty(TYPES_PROPERTY);
78 // PROPERTY_DESCRIPTORS = reapPropertyList();
82 // * Returns a list of structural property descriptors for this node type.
83 // * Clients must not modify the result.
85 // * @param apiLevel the API level; one of the
86 // * <code>AST.JLS*</code> constants
88 // * @return a list of property descriptors (element type:
89 // * {@link StructuralPropertyDescriptor})
92 // public static List propertyDescriptors(int apiLevel) {
93 // return PROPERTY_DESCRIPTORS;
97 // * The comment table, or <code>null</code> if none; initially
98 // * <code>null</code>. This array is the storage underlying
99 // * the <code>optionalCommentList</code> ArrayList.
102 // Comment[] optionalCommentTable = null;
105 // * The comment list (element type: <code>Comment</code>,
106 // * or <code>null</code> if none; initially <code>null</code>.
109 // private List optionalCommentList = null;
112 // * The package declaration, or <code>null</code> if none; initially
113 // * <code>null</code>.
115 // private PackageDeclaration optionalPackageDeclaration = null;
118 // * The list of import declarations in textual order order;
119 // * initially none (elementType: <code>ImportDeclaration</code>).
121 // private ASTNode.NodeList imports =
122 // new ASTNode.NodeList(IMPORTS_PROPERTY);
125 // * The list of type declarations in textual order order;
126 // * initially none (elementType: <code>AbstractTypeDeclaration</code>)
128 // private ASTNode.NodeList types =
129 // new ASTNode.NodeList(TYPES_PROPERTY);
132 // * Line end table. If <code>lineEndTable[i] == p</code> then the
133 // * line number <code>i+1</code> ends at character position
134 // * <code>p</code>. Except for the last line, the positions are that
135 // * of the last character of the line delimiter.
136 // * For example, the source string <code>A\nB\nC</code> has
137 // * line end table {1, 3} (if \n is one character).
139 // private int[] lineEndTable = new int[0];
142 // * Canonical empty list of messages.
144 // private static final Message[] EMPTY_MESSAGES = new Message[0];
147 // * Canonical empty list of problems.
149 // private static final IProblem[] EMPTY_PROBLEMS = new IProblem[0];
152 // * Messages reported by the compiler during parsing or name resolution.
154 // private Message[] messages;
157 // * Problems reported by the compiler during parsing or name resolution.
159 // private IProblem[] problems = EMPTY_PROBLEMS;
162 // * The comment mapper, or <code>null</code> in none;
163 // * initially <code>null</code>.
166 // private DefaultCommentMapper commentMapper = null;
169 // * Sets the line end table for this compilation unit.
170 // * If <code>lineEndTable[i] == p</code> then line number <code>i+1</code>
171 // * ends at character position <code>p</code>. Except for the last line, the
172 // * positions are that of (the last character of) the line delimiter.
173 // * For example, the source string <code>A\nB\nC</code> has
174 // * line end table {1, 3, 4}.
176 // * @param lineEndtable the line end table
178 // void setLineEndTable(int[] lineEndTable) {
179 // if (lineEndTable == null) {
180 // throw new NullPointerException();
182 // // alternate root is *not* considered a structural property
183 // // but we protect them nevertheless
184 // checkModifiable();
185 // this.lineEndTable = lineEndTable;
189 // * Creates a new AST node for a compilation owned by the given AST.
190 // * The compilation unit initially has no package declaration, no
191 // * import declarations, and no type declarations.
193 // * N.B. This constructor is package-private; all subclasses must be
194 // * declared in the same package; clients are unable to declare
195 // * additional subclasses.
198 // * @param ast the AST that is to own this node
200 // CompilationUnit(AST ast) {
204 // /* (omit javadoc for this method)
205 // * Method declared on ASTNode.
208 // final List internalStructuralPropertiesForType(int apiLevel) {
209 // return propertyDescriptors(apiLevel);
212 // /* (omit javadoc for this method)
213 // * Method declared on ASTNode.
215 // final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
216 // if (property == PACKAGE_PROPERTY) {
218 // return getPackage();
220 // setPackage((PackageDeclaration) child);
224 // // allow default implementation to flag the error
225 // return super.internalGetSetChildProperty(property, get, child);
228 // /* (omit javadoc for this method)
229 // * Method declared on ASTNode.
231 // final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
232 // if (property == IMPORTS_PROPERTY) {
235 // if (property == TYPES_PROPERTY) {
238 // // allow default implementation to flag the error
239 // return super.internalGetChildListProperty(property);
242 // /* (omit javadoc for this method)
243 // * Method declared on ASTNode.
245 // final int getNodeType0() {
246 // return COMPILATION_UNIT;
249 // /* (omit javadoc for this method)
250 // * Method declared on ASTNode.
252 // ASTNode clone0(AST target) {
253 // CompilationUnit result = new CompilationUnit(target);
254 // // n.b do not copy line number table or messages
255 // result.setSourceRange(this.getStartPosition(), this.getLength());
256 // result.setPackage(
257 // (PackageDeclaration) ASTNode.copySubtree(target, getPackage()));
258 // result.imports().addAll(ASTNode.copySubtrees(target, imports()));
259 // result.types().addAll(ASTNode.copySubtrees(target, types()));
263 // /* (omit javadoc for this method)
264 // * Method declared on ASTNode.
266 // final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
267 // // dispatch to correct overloaded match method
268 // return matcher.match(this, other);
271 // /* (omit javadoc for this method)
272 // * Method declared on ASTNode.
274 // void accept0(ASTVisitor visitor) {
275 // boolean visitChildren = visitor.visit(this);
276 // if (visitChildren) {
277 // // visit children in normal left to right reading order
278 // acceptChild(visitor, getPackage());
279 // acceptChildren(visitor, this.imports);
280 // acceptChildren(visitor, this.types);
282 // visitor.endVisit(this);
286 // * Returns the node for the package declaration of this compilation
287 // * unit, or <code>null</code> if this compilation unit is in the
288 // * default package.
290 // * @return the package declaration node, or <code>null</code> if none
292 // public PackageDeclaration getPackage() {
293 // return this.optionalPackageDeclaration;
297 // * Sets or clears the package declaration of this compilation unit
298 // * node to the given package declaration node.
300 // * @param pkgDecl the new package declaration node, or
301 // * <code>null</code> if this compilation unit does not have a package
302 // * declaration (that is in the default package)
303 // * @exception IllegalArgumentException if:
305 // * <li>the node belongs to a different AST</li>
306 // * <li>the node already has a parent</li>
309 // public void setPackage(PackageDeclaration pkgDecl) {
310 // ASTNode oldChild = this.optionalPackageDeclaration;
311 // preReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
312 // this.optionalPackageDeclaration = pkgDecl;
313 // postReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
317 // * Returns the live list of nodes for the import declarations of this
318 // * compilation unit, in order of appearance.
320 // * @return the live list of import declaration nodes
321 // * (elementType: <code>ImportDeclaration</code>)
323 // public List imports() {
324 // return this.imports;
328 // * Returns the live list of nodes for the top-level type declarations of this
329 // * compilation unit, in order of appearance.
331 // * Note that in JLS3, the types may include both enum declarations
332 // * and annotation type declarations introduced in J2SE 1.5.
333 // * For JLS2, the elements are always <code>TypeDeclaration</code>.
336 // * @return the live list of top-level type declaration
337 // * nodes (elementType: <code>AbstractTypeDeclaration</code>)
339 // public List types() {
340 // return this.types;
344 // * Finds the corresponding AST node in the given compilation unit from
345 // * which the given binding originated. Returns <code>null</code> if the
346 // * binding does not correspond to any node in this compilation unit.
347 // * This method always returns <code>null</code> if bindings were not requested
348 // * when this AST was built.
350 // * The following table indicates the expected node type for the various
351 // * different kinds of bindings:
354 // * <li>package - a <code>PackageDeclaration</code></li>
355 // * <li>class or interface - a <code>TypeDeclaration</code> or a
356 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
357 // * <li>primitive type - none</li>
358 // * <li>array type - none</li>
359 // * <li>field - a <code>VariableDeclarationFragment</code> in a
360 // * <code>FieldDeclaration</code> </li>
361 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
362 // * a <code>VariableDeclarationFragment</code> in a
363 // * <code>VariableDeclarationStatement</code> or
364 // * <code>VariableDeclarationExpression</code></li>
365 // * <li>method - a <code>MethodDeclaration</code> </li>
366 // * <li>constructor - a <code>MethodDeclaration</code> </li>
367 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
368 // * <li>annotation type member - an <code>AnnotationTypeMemberDeclaration</code></li>
369 // * <li>enum type - an <code>EnumDeclaration</code></li>
370 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
374 // * Each call to {@link ASTParser#createAST(IProgressMonitor)} with a request for bindings
375 // * gives rise to separate universe of binding objects. This method always returns
376 // * <code>null</code> when the binding object comes from a different AST.
377 // * Use <code>findDeclaringNode(binding.getKey())</code> when the binding comes
378 // * from a different AST.
381 // * @param binding the binding
382 // * @return the corresponding node where the given binding is declared,
383 // * or <code>null</code> if the binding does not correspond to a node in this
384 // * compilation unit or if bindings were not requested when this AST was built
385 // * @see #findDeclaringNode(String)
387 // public ASTNode findDeclaringNode(IBinding binding) {
388 // return this.ast.getBindingResolver().findDeclaringNode(binding);
392 // * Finds the corresponding AST node in the given compilation unit from
393 // * which the binding with the given key originated. Returns
394 // * <code>null</code> if the corresponding node cannot be determined.
395 // * This method always returns <code>null</code> if bindings were not requested
396 // * when this AST was built.
398 // * The following table indicates the expected node type for the various
399 // * different kinds of binding keys:
402 // * <li>package - a <code>PackageDeclaration</code></li>
403 // * <li>class or interface - a <code>TypeDeclaration</code> or a
404 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
405 // * <li>primitive type - none</li>
406 // * <li>array type - none</li>
407 // * <li>field - a <code>VariableDeclarationFragment</code> in a
408 // * <code>FieldDeclaration</code> </li>
409 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
410 // * a <code>VariableDeclarationFragment</code> in a
411 // * <code>VariableDeclarationStatement</code> or
412 // * <code>VariableDeclarationExpression</code></li>
413 // * <li>method - a <code>MethodDeclaration</code> </li>
414 // * <li>constructor - a <code>MethodDeclaration</code> </li>
415 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
416 // * <li>annotation type member - an <code>AnnotationTypeMemberDeclaration</code></li>
417 // * <li>enum type - an <code>EnumDeclaration</code></li>
418 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
422 // * Note that as explained in {@link IBinding#getKey() IBinding.getkey}
423 // * there may be no keys for finding the declaring node for local variables,
424 // * local or anonymous classes, etc.
427 // * @param key the binding key, or <code>null</code>
428 // * @return the corresponding node where a binding with the given
429 // * key is declared, or <code>null</code> if the key is <code>null</code>
430 // * or if the key does not correspond to a node in this compilation unit
431 // * or if bindings were not requested when this AST was built
432 // * @see IBinding#getKey()
435 // public ASTNode findDeclaringNode(String key) {
436 // return this.ast.getBindingResolver().findDeclaringNode(key);
440 // * Returns the internal comment mapper.
442 // * @return the comment mapper, or <code>null</code> if none.
445 // DefaultCommentMapper getCommentMapper() {
446 // return this.commentMapper;
450 // * Initializes the internal comment mapper with the given
453 // * @param scanner the scanner
456 // void initCommentMapper(Scanner scanner) {
457 // this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
458 // this.commentMapper.initialize(this, scanner);
462 // * Returns the extended start position of the given node. Unlike
463 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
464 // * the extended source range may include comments and whitespace
465 // * immediately before or after the normal source range for the node.
467 // * @param node the node
468 // * @return the 0-based character index, or <code>-1</code>
469 // * if no source position information is recorded for this node
470 // * @see #getExtendedLength(ASTNode)
473 // public int getExtendedStartPosition(ASTNode node) {
474 // if (this.commentMapper == null) {
477 // return this.commentMapper.getExtendedStartPosition(node);
482 // * Returns the extended source length of the given node. Unlike
483 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
484 // * the extended source range may include comments and whitespace
485 // * immediately before or after the normal source range for the node.
487 // * @param node the node
488 // * @return a (possibly 0) length, or <code>0</code>
489 // * if no source position information is recorded for this node
490 // * @see #getExtendedStartPosition(ASTNode)
493 // public int getExtendedLength(ASTNode node) {
494 // if (this.commentMapper == null) {
497 // return this.commentMapper.getExtendedLength(node);
502 // * Returns the line number corresponding to the given source character
503 // * position in the original source string. The initial line of the
504 // * compilation unit is numbered 1, and each line extends through the
505 // * last character of the end-of-line delimiter. The very last line extends
506 // * through the end of the source string and has no line delimiter.
507 // * For example, the source string <code>class A\n{\n}</code> has 3 lines
508 // * corresponding to inclusive character ranges [0,7], [8,9], and [10,10].
509 // * Returns 1 for a character position that does not correspond to any
510 // * source line, or if no line number information is available for this
511 // * compilation unit.
513 // * @param position a 0-based character position, possibly
514 // * negative or out of range
515 // * @return the 1-based line number, or <code>1</code> if the character
516 // * position does not correspond to a source line in the original
517 // * source file or if line number information is not known for this
518 // * compilation unit
521 // public int lineNumber(int position) {
522 // int length = lineEndTable.length;
523 // if (length == 0) {
524 // // no line number info
528 // if (position <= lineEndTable[low]) {
529 // // position illegal or before the first line delimiter
532 // // assert position > lineEndTable[low+1] && low == 0
533 // int hi = length - 1;
534 // if (position > lineEndTable[hi]) {
535 // // position beyond the last line separator
536 // if (position >= getStartPosition() + getLength()) {
537 // // this is beyond the end of the source length
540 // return length + 1;
543 // // assert lineEndTable[low] < position <= lineEndTable[hi]
544 // // && low == 0 && hi == length - 1 && low < hi
546 // // binary search line end table
548 // // invariant lineEndTable[low] < position <= lineEndTable[hi]
549 // // && 0 <= low < hi <= length - 1
550 // // reducing measure hi - low
551 // if (low + 1 == hi) {
552 // // assert lineEndTable[low] < position <= lineEndTable[low+1]
553 // // position is on line low+1 (line number is low+2)
556 // // assert hi - low >= 2, so average is truly in between
557 // int mid = (low + hi) / 2;
558 // // assert 0 <= low < mid < hi <= length - 1
559 // if (position <= lineEndTable[mid]) {
560 // // assert lineEndTable[low] < position <= lineEndTable[mid]
561 // // && 0 <= low < mid < hi <= length - 1
564 // // position > lineEndTable[mid]
565 // // assert lineEndTable[mid] < position <= lineEndTable[hi]
566 // // && 0 <= low < mid < hi <= length - 1
569 // // in both cases, invariant reachieved with reduced measure
574 // * Returns the list of messages reported by the compiler during the parsing
575 // * or the type checking of this compilation unit. This list might be a subset of
576 // * errors detected and reported by a Java compiler.
578 // * This list of messages is suitable for simple clients that do little
579 // * more than log the messages or display them to the user. Clients that
580 // * need further details should call <code>getProblems</code> to get
581 // * compiler problem objects.
584 // * @return the list of messages, possibly empty
585 // * @see #getProblems()
588 // public Message[] getMessages() {
589 // if (this.messages == null) {
590 // int problemLength = this.problems.length;
591 // if (problemLength == 0) {
592 // this.messages = EMPTY_MESSAGES;
594 // this.messages = new Message[problemLength];
595 // for (int i = 0; i < problemLength; i++) {
596 // IProblem problem = this.problems[i];
597 // int start = problem.getSourceStart();
598 // int end = problem.getSourceEnd();
599 // messages[i] = new Message(problem.getMessage(), start, end - start + 1);
603 // return this.messages;
607 // * Returns the list of detailed problem reports noted by the compiler
608 // * during the parsing or the type checking of this compilation unit. This
609 // * list might be a subset of errors detected and reported by a Java
612 // * Simple clients that do little more than log the messages or display
613 // * them to the user should probably call <code>getMessages</code> instead.
616 // * @return the list of detailed problem objects, possibly empty
617 // * @see #getMessages()
621 // public IProblem[] getProblems() {
622 // return this.problems;
626 // * Sets the array of problems reported by the compiler during the parsing or
627 // * name resolution of this compilation unit.
629 // * @param problems the list of problems
631 // void setProblems(IProblem[] problems) {
632 // if (problems == null) {
633 // throw new IllegalArgumentException();
635 // this.problems = problems;
639 // * Returns a list of the comments encountered while parsing
640 // * this compilation unit.
642 // * Since the Java language allows comments to appear most anywhere
643 // * in the source text, it is problematic to locate comments in relation
644 // * to the structure of an AST. The one exception is doc comments
645 // * which, by convention, immediately precede type, field, and
646 // * method declarations; these comments are located in the AST
647 // * by {@link BodyDeclaration#getJavadoc BodyDeclaration.getJavadoc}.
648 // * Other comments do not show up in the AST. The table of comments
649 // * is provided for clients that need to find the source ranges of
650 // * all comments in the original source string. It includes entries
651 // * for comments of all kinds (line, block, and doc), arranged in order
652 // * of increasing source position.
654 // * Note on comment parenting: The {@link ASTNode#getParent() getParent()}
655 // * of a doc comment associated with a body declaration is the body
656 // * declaration node; for these comment nodes
657 // * {@link ASTNode#getRoot() getRoot()} will return the compilation unit
658 // * (assuming an unmodified AST) reflecting the fact that these nodes
659 // * are property located in the AST for the compilation unit.
660 // * However, for other comment nodes, {@link ASTNode#getParent() getParent()}
661 // * will return <code>null</code>, and {@link ASTNode#getRoot() getRoot()}
662 // * will return the comment node itself, indicating that these comment nodes
663 // * are not directly connected to the AST for the compilation unit. The
664 // * {@link Comment#getAlternateRoot Comment.getAlternateRoot}
665 // * method provides a way to navigate from a comment to its compilation
669 // * A note on visitors: The only comment nodes that will be visited when
670 // * visiting a compilation unit are the doc comments parented by body
671 // * declarations. To visit all comments in normal reading order, iterate
672 // * over the comment table and call {@link ASTNode#accept(ASTVisitor) accept}
673 // * on each element.
676 // * Clients cannot modify the resulting list.
679 // * @return an unmodifiable list of comments in increasing order of source
680 // * start position, or <code>null</code> if comment information
681 // * for this compilation unit is not available
685 // public List getCommentList() {
686 // return this.optionalCommentList;
690 // * Sets the list of the comments encountered while parsing
691 // * this compilation unit.
693 // * @param commentTable a list of comments in increasing order
694 // * of source start position, or <code>null</code> if comment
695 // * information for this compilation unit is not available
696 // * @exception IllegalArgumentException if the comment table is
697 // * not in increasing order of source position
698 // * @see #getCommentList()
702 // void setCommentTable(Comment[] commentTable) {
703 // // double check table to ensure that all comments have
704 // // source positions and are in strictly increasing order
705 // if (commentTable == null) {
706 // this.optionalCommentList = null;
707 // this.optionalCommentTable = null;
709 // int nextAvailablePosition = 0;
710 // for (int i = 0; i < commentTable.length; i++) {
711 // Comment comment = commentTable[i];
712 // if (comment == null) {
713 // throw new IllegalArgumentException();
715 // int start = comment.getStartPosition();
716 // int length = comment.getLength();
717 // if (start < 0 || length < 0 || start < nextAvailablePosition) {
718 // throw new IllegalArgumentException();
720 // nextAvailablePosition = comment.getStartPosition() + comment.getLength();
722 // this.optionalCommentTable = commentTable;
723 // List commentList = Arrays.asList(commentTable);
724 // // protect the list from further modification
725 // this.optionalCommentList = Collections.unmodifiableList(commentList);
730 // /* (omit javadoc for this method)
731 // * Method declared on ASTNode.
733 // void appendDebugString(StringBuffer buffer) {
734 // buffer.append("CompilationUnit"); //$NON-NLS-1$
735 // // include the type names
736 // buffer.append("["); //$NON-NLS-1$
737 // for (Iterator it = types().iterator(); it.hasNext(); ) {
738 // AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
739 // buffer.append(d.getName().getIdentifier());
740 // if (it.hasNext()) {
741 // buffer.append(","); //$NON-NLS-1$
744 // buffer.append("]"); //$NON-NLS-1$
747 // /* (omit javadoc for this method)
748 // * Method declared on ASTNode.
751 // int size = BASE_NODE_SIZE + 8 * 4;
752 // if (this.lineEndTable != null) {
753 // size += HEADERS + 4 * this.lineEndTable.length;
755 // if (this.optionalCommentTable != null) {
756 // size += HEADERS + 4 * this.optionalCommentTable.length;
758 // // ignore the space taken up by optionalCommentList
762 // /* (omit javadoc for this method)
763 // * Method declared on ASTNode.
766 // int size = memSize();
767 // if (this.optionalPackageDeclaration != null) {
768 // size += getPackage().treeSize();
770 // size += this.imports.listSize();
771 // size += this.types.listSize();
772 // // include disconnected comments
773 // if (this.optionalCommentList != null) {
774 // for (int i = 0; i < this.optionalCommentList.size(); i++) {
775 // Comment comment = (Comment) this.optionalCommentList.get(i);
776 // if (comment != null && comment.getParent() == null) {
777 // size += comment.treeSize();
785 // * Enables the recording of changes to this compilation
786 // * unit and its descendents. The compilation unit must have
787 // * been created by <code>ASTParser</code> and still be in
788 // * its original state. Once recording is on,
789 // * arbitrary changes to the subtree rooted at this compilation
790 // * unit are recorded internally. Once the modification has
791 // * been completed, call <code>rewrite</code> to get an object
792 // * representing the corresponding edits to the original
793 // * source code string.
795 // * @exception IllegalArgumentException if this compilation unit is
796 // * marked as unmodifiable, or if this compilation unit has already
797 // * been tampered with, or recording has already been enabled
800 // public void recordModifications() {
801 // getAST().recordModifications(this);
805 // * Converts all modifications recorded for this compilation
806 // * unit into an object representing the corresponding text
807 // * edits to the given document containing the original source
808 // * code for this compilation unit.
810 // * The compilation unit must have been created by
811 // * <code>ASTParser</code> from the source code string in the
812 // * given document, and recording must have been turned
813 // * on with a prior call to <code>recordModifications</code>
814 // * while the AST was still in its original state.
817 // * Calling this methods does not discard the modifications
818 // * on record. Subsequence modifications made to the AST
819 // * are added to the ones already on record. If this method
820 // * is called again later, the resulting text edit object will
821 // * accurately reflect the net cumulative affect of all those
825 // * @param document original document containing source code
826 // * for this compilation unit
827 // * @param options the table of formatter options
828 // * (key type: <code>String</code>; value type: <code>String</code>);
829 // * or <code>null</code> to use the standard global options
830 // * {@link JavaCore#getOptions() JavaCore.getOptions()}.
831 // * @return text edit object describing the changes to the
832 // * document corresponding to the recorded AST modifications
833 // * @exception IllegalArgumentException if the document passed is
834 // * <code>null</code> or does not correspond to this AST
835 // * @exception IllegalStateException if <code>recordModifications</code>
836 // * was not called to enable recording
837 // * @see #recordModifications()
840 // public TextEdit rewrite(IDocument document, Map options) {
841 // return getAST().rewrite(document, options);