1 package net.sourceforge.phpdt.core.dom;
2 /*******************************************************************************
3 * Copyright (c) 2000, 2004 IBM Corporation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Common Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/cpl-v10.html
10 * IBM Corporation - initial API and implementation
11 *******************************************************************************/
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.
23 * [ PackageDeclaration ]
24 * { ImportDeclaration }
25 * { TypeDeclaration | <b>;</b> }
27 * For JLS3, the kinds of type declarations
28 * grew to include enum and annotation type declarations:
31 * [ PackageDeclaration ]
32 * { ImportDeclaration }
33 * { TypeDeclaration | EnumDeclaration | AnnotationTypeDeclaration | <b>;</b> }
38 public class CompilationUnit {
41 // * The "package" structural property of this node type.
45 // public static final ChildPropertyDescriptor PACKAGE_PROPERTY =
46 // new ChildPropertyDescriptor(CompilationUnit.class, "package", PackageDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
49 // * The "imports" structural property of this node type.
53 // public static final ChildListPropertyDescriptor IMPORTS_PROPERTY =
54 // new ChildListPropertyDescriptor(CompilationUnit.class, "imports", ImportDeclaration.class, NO_CYCLE_RISK); //$NON-NLS-1$
57 // * The "types" structural property of this node type.
61 // public static final ChildListPropertyDescriptor TYPES_PROPERTY =
62 // new ChildListPropertyDescriptor(CompilationUnit.class, "types", AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
65 // * A list of property descriptors (element type:
66 // * {@link StructuralPropertyDescriptor}),
67 // * or null if uninitialized.
70 // private static final List PROPERTY_DESCRIPTORS;
73 // createPropertyList(CompilationUnit.class);
74 // addProperty(PACKAGE_PROPERTY);
75 // addProperty(IMPORTS_PROPERTY);
76 // addProperty(TYPES_PROPERTY);
77 // PROPERTY_DESCRIPTORS = reapPropertyList();
81 // * Returns a list of structural property descriptors for this node type.
82 // * Clients must not modify the result.
84 // * @param apiLevel the API level; one of the
85 // * <code>AST.JLS*</code> constants
87 // * @return a list of property descriptors (element type:
88 // * {@link StructuralPropertyDescriptor})
91 // public static List propertyDescriptors(int apiLevel) {
92 // return PROPERTY_DESCRIPTORS;
96 // * The comment table, or <code>null</code> if none; initially
97 // * <code>null</code>. This array is the storage underlying
98 // * the <code>optionalCommentList</code> ArrayList.
101 // Comment[] optionalCommentTable = null;
104 // * The comment list (element type: <code>Comment</code>,
105 // * or <code>null</code> if none; initially <code>null</code>.
108 // private List optionalCommentList = null;
111 // * The package declaration, or <code>null</code> if none; initially
112 // * <code>null</code>.
114 // private PackageDeclaration optionalPackageDeclaration = null;
117 // * The list of import declarations in textual order order;
118 // * initially none (elementType: <code>ImportDeclaration</code>).
120 // private ASTNode.NodeList imports =
121 // new ASTNode.NodeList(IMPORTS_PROPERTY);
124 // * The list of type declarations in textual order order;
125 // * initially none (elementType: <code>AbstractTypeDeclaration</code>)
127 // private ASTNode.NodeList types =
128 // new ASTNode.NodeList(TYPES_PROPERTY);
131 // * Line end table. If <code>lineEndTable[i] == p</code> then the
132 // * line number <code>i+1</code> ends at character position
133 // * <code>p</code>. Except for the last line, the positions are that
134 // * of the last character of the line delimiter.
135 // * For example, the source string <code>A\nB\nC</code> has
136 // * line end table {1, 3} (if \n is one character).
138 // private int[] lineEndTable = new int[0];
141 // * Canonical empty list of messages.
143 // private static final Message[] EMPTY_MESSAGES = new Message[0];
146 // * Canonical empty list of problems.
148 // private static final IProblem[] EMPTY_PROBLEMS = new IProblem[0];
151 // * Messages reported by the compiler during parsing or name resolution.
153 // private Message[] messages;
156 // * Problems reported by the compiler during parsing or name resolution.
158 // private IProblem[] problems = EMPTY_PROBLEMS;
161 // * The comment mapper, or <code>null</code> in none;
162 // * initially <code>null</code>.
165 // private DefaultCommentMapper commentMapper = null;
168 // * Sets the line end table for this compilation unit.
169 // * If <code>lineEndTable[i] == p</code> then line number <code>i+1</code>
170 // * ends at character position <code>p</code>. Except for the last line, the
171 // * positions are that of (the last character of) the line delimiter.
172 // * For example, the source string <code>A\nB\nC</code> has
173 // * line end table {1, 3, 4}.
175 // * @param lineEndtable the line end table
177 // void setLineEndTable(int[] lineEndTable) {
178 // if (lineEndTable == null) {
179 // throw new NullPointerException();
181 // // alternate root is *not* considered a structural property
182 // // but we protect them nevertheless
183 // checkModifiable();
184 // this.lineEndTable = lineEndTable;
188 // * Creates a new AST node for a compilation owned by the given AST.
189 // * The compilation unit initially has no package declaration, no
190 // * import declarations, and no type declarations.
192 // * N.B. This constructor is package-private; all subclasses must be
193 // * declared in the same package; clients are unable to declare
194 // * additional subclasses.
197 // * @param ast the AST that is to own this node
199 // CompilationUnit(AST ast) {
203 // /* (omit javadoc for this method)
204 // * Method declared on ASTNode.
207 // final List internalStructuralPropertiesForType(int apiLevel) {
208 // return propertyDescriptors(apiLevel);
211 // /* (omit javadoc for this method)
212 // * Method declared on ASTNode.
214 // final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
215 // if (property == PACKAGE_PROPERTY) {
217 // return getPackage();
219 // setPackage((PackageDeclaration) child);
223 // // allow default implementation to flag the error
224 // return super.internalGetSetChildProperty(property, get, child);
227 // /* (omit javadoc for this method)
228 // * Method declared on ASTNode.
230 // final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
231 // if (property == IMPORTS_PROPERTY) {
234 // if (property == TYPES_PROPERTY) {
237 // // allow default implementation to flag the error
238 // return super.internalGetChildListProperty(property);
241 // /* (omit javadoc for this method)
242 // * Method declared on ASTNode.
244 // final int getNodeType0() {
245 // return COMPILATION_UNIT;
248 // /* (omit javadoc for this method)
249 // * Method declared on ASTNode.
251 // ASTNode clone0(AST target) {
252 // CompilationUnit result = new CompilationUnit(target);
253 // // n.b do not copy line number table or messages
254 // result.setSourceRange(this.getStartPosition(), this.getLength());
255 // result.setPackage(
256 // (PackageDeclaration) ASTNode.copySubtree(target, getPackage()));
257 // result.imports().addAll(ASTNode.copySubtrees(target, imports()));
258 // result.types().addAll(ASTNode.copySubtrees(target, types()));
262 // /* (omit javadoc for this method)
263 // * Method declared on ASTNode.
265 // final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
266 // // dispatch to correct overloaded match method
267 // return matcher.match(this, other);
270 // /* (omit javadoc for this method)
271 // * Method declared on ASTNode.
273 // void accept0(ASTVisitor visitor) {
274 // boolean visitChildren = visitor.visit(this);
275 // if (visitChildren) {
276 // // visit children in normal left to right reading order
277 // acceptChild(visitor, getPackage());
278 // acceptChildren(visitor, this.imports);
279 // acceptChildren(visitor, this.types);
281 // visitor.endVisit(this);
285 // * Returns the node for the package declaration of this compilation
286 // * unit, or <code>null</code> if this compilation unit is in the
287 // * default package.
289 // * @return the package declaration node, or <code>null</code> if none
291 // public PackageDeclaration getPackage() {
292 // return this.optionalPackageDeclaration;
296 // * Sets or clears the package declaration of this compilation unit
297 // * node to the given package declaration node.
299 // * @param pkgDecl the new package declaration node, or
300 // * <code>null</code> if this compilation unit does not have a package
301 // * declaration (that is in the default package)
302 // * @exception IllegalArgumentException if:
304 // * <li>the node belongs to a different AST</li>
305 // * <li>the node already has a parent</li>
308 // public void setPackage(PackageDeclaration pkgDecl) {
309 // ASTNode oldChild = this.optionalPackageDeclaration;
310 // preReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
311 // this.optionalPackageDeclaration = pkgDecl;
312 // postReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
316 // * Returns the live list of nodes for the import declarations of this
317 // * compilation unit, in order of appearance.
319 // * @return the live list of import declaration nodes
320 // * (elementType: <code>ImportDeclaration</code>)
322 // public List imports() {
323 // return this.imports;
327 // * Returns the live list of nodes for the top-level type declarations of this
328 // * compilation unit, in order of appearance.
330 // * Note that in JLS3, the types may include both enum declarations
331 // * and annotation type declarations introduced in J2SE 1.5.
332 // * For JLS2, the elements are always <code>TypeDeclaration</code>.
335 // * @return the live list of top-level type declaration
336 // * nodes (elementType: <code>AbstractTypeDeclaration</code>)
338 // public List types() {
339 // return this.types;
343 // * Finds the corresponding AST node in the given compilation unit from
344 // * which the given binding originated. Returns <code>null</code> if the
345 // * binding does not correspond to any node in this compilation unit.
346 // * This method always returns <code>null</code> if bindings were not requested
347 // * when this AST was built.
349 // * The following table indicates the expected node type for the various
350 // * different kinds of bindings:
353 // * <li>package - a <code>PackageDeclaration</code></li>
354 // * <li>class or interface - a <code>TypeDeclaration</code> or a
355 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
356 // * <li>primitive type - none</li>
357 // * <li>array type - none</li>
358 // * <li>field - a <code>VariableDeclarationFragment</code> in a
359 // * <code>FieldDeclaration</code> </li>
360 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
361 // * a <code>VariableDeclarationFragment</code> in a
362 // * <code>VariableDeclarationStatement</code> or
363 // * <code>VariableDeclarationExpression</code></li>
364 // * <li>method - a <code>MethodDeclaration</code> </li>
365 // * <li>constructor - a <code>MethodDeclaration</code> </li>
366 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
367 // * <li>annotation type member - an <code>AnnotationTypeMemberDeclaration</code></li>
368 // * <li>enum type - an <code>EnumDeclaration</code></li>
369 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
373 // * Each call to {@link ASTParser#createAST(IProgressMonitor)} with a request for bindings
374 // * gives rise to separate universe of binding objects. This method always returns
375 // * <code>null</code> when the binding object comes from a different AST.
376 // * Use <code>findDeclaringNode(binding.getKey())</code> when the binding comes
377 // * from a different AST.
380 // * @param binding the binding
381 // * @return the corresponding node where the given binding is declared,
382 // * or <code>null</code> if the binding does not correspond to a node in this
383 // * compilation unit or if bindings were not requested when this AST was built
384 // * @see #findDeclaringNode(String)
386 // public ASTNode findDeclaringNode(IBinding binding) {
387 // return this.ast.getBindingResolver().findDeclaringNode(binding);
391 // * Finds the corresponding AST node in the given compilation unit from
392 // * which the binding with the given key originated. Returns
393 // * <code>null</code> if the corresponding node cannot be determined.
394 // * This method always returns <code>null</code> if bindings were not requested
395 // * when this AST was built.
397 // * The following table indicates the expected node type for the various
398 // * different kinds of binding keys:
401 // * <li>package - a <code>PackageDeclaration</code></li>
402 // * <li>class or interface - a <code>TypeDeclaration</code> or a
403 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
404 // * <li>primitive type - none</li>
405 // * <li>array type - none</li>
406 // * <li>field - a <code>VariableDeclarationFragment</code> in a
407 // * <code>FieldDeclaration</code> </li>
408 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
409 // * a <code>VariableDeclarationFragment</code> in a
410 // * <code>VariableDeclarationStatement</code> or
411 // * <code>VariableDeclarationExpression</code></li>
412 // * <li>method - a <code>MethodDeclaration</code> </li>
413 // * <li>constructor - a <code>MethodDeclaration</code> </li>
414 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
415 // * <li>annotation type member - an <code>AnnotationTypeMemberDeclaration</code></li>
416 // * <li>enum type - an <code>EnumDeclaration</code></li>
417 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
421 // * Note that as explained in {@link IBinding#getKey() IBinding.getkey}
422 // * there may be no keys for finding the declaring node for local variables,
423 // * local or anonymous classes, etc.
426 // * @param key the binding key, or <code>null</code>
427 // * @return the corresponding node where a binding with the given
428 // * key is declared, or <code>null</code> if the key is <code>null</code>
429 // * or if the key does not correspond to a node in this compilation unit
430 // * or if bindings were not requested when this AST was built
431 // * @see IBinding#getKey()
434 // public ASTNode findDeclaringNode(String key) {
435 // return this.ast.getBindingResolver().findDeclaringNode(key);
439 // * Returns the internal comment mapper.
441 // * @return the comment mapper, or <code>null</code> if none.
444 // DefaultCommentMapper getCommentMapper() {
445 // return this.commentMapper;
449 // * Initializes the internal comment mapper with the given
452 // * @param scanner the scanner
455 // void initCommentMapper(Scanner scanner) {
456 // this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
457 // this.commentMapper.initialize(this, scanner);
461 // * Returns the extended start position of the given node. Unlike
462 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
463 // * the extended source range may include comments and whitespace
464 // * immediately before or after the normal source range for the node.
466 // * @param node the node
467 // * @return the 0-based character index, or <code>-1</code>
468 // * if no source position information is recorded for this node
469 // * @see #getExtendedLength(ASTNode)
472 // public int getExtendedStartPosition(ASTNode node) {
473 // if (this.commentMapper == null) {
476 // return this.commentMapper.getExtendedStartPosition(node);
481 // * Returns the extended source length 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 a (possibly 0) length, or <code>0</code>
488 // * if no source position information is recorded for this node
489 // * @see #getExtendedStartPosition(ASTNode)
492 // public int getExtendedLength(ASTNode node) {
493 // if (this.commentMapper == null) {
496 // return this.commentMapper.getExtendedLength(node);
501 // * Returns the line number corresponding to the given source character
502 // * position in the original source string. The initial line of the
503 // * compilation unit is numbered 1, and each line extends through the
504 // * last character of the end-of-line delimiter. The very last line extends
505 // * through the end of the source string and has no line delimiter.
506 // * For example, the source string <code>class A\n{\n}</code> has 3 lines
507 // * corresponding to inclusive character ranges [0,7], [8,9], and [10,10].
508 // * Returns 1 for a character position that does not correspond to any
509 // * source line, or if no line number information is available for this
510 // * compilation unit.
512 // * @param position a 0-based character position, possibly
513 // * negative or out of range
514 // * @return the 1-based line number, or <code>1</code> if the character
515 // * position does not correspond to a source line in the original
516 // * source file or if line number information is not known for this
517 // * compilation unit
520 // public int lineNumber(int position) {
521 // int length = lineEndTable.length;
522 // if (length == 0) {
523 // // no line number info
527 // if (position <= lineEndTable[low]) {
528 // // position illegal or before the first line delimiter
531 // // assert position > lineEndTable[low+1] && low == 0
532 // int hi = length - 1;
533 // if (position > lineEndTable[hi]) {
534 // // position beyond the last line separator
535 // if (position >= getStartPosition() + getLength()) {
536 // // this is beyond the end of the source length
539 // return length + 1;
542 // // assert lineEndTable[low] < position <= lineEndTable[hi]
543 // // && low == 0 && hi == length - 1 && low < hi
545 // // binary search line end table
547 // // invariant lineEndTable[low] < position <= lineEndTable[hi]
548 // // && 0 <= low < hi <= length - 1
549 // // reducing measure hi - low
550 // if (low + 1 == hi) {
551 // // assert lineEndTable[low] < position <= lineEndTable[low+1]
552 // // position is on line low+1 (line number is low+2)
555 // // assert hi - low >= 2, so average is truly in between
556 // int mid = (low + hi) / 2;
557 // // assert 0 <= low < mid < hi <= length - 1
558 // if (position <= lineEndTable[mid]) {
559 // // assert lineEndTable[low] < position <= lineEndTable[mid]
560 // // && 0 <= low < mid < hi <= length - 1
563 // // position > lineEndTable[mid]
564 // // assert lineEndTable[mid] < position <= lineEndTable[hi]
565 // // && 0 <= low < mid < hi <= length - 1
568 // // in both cases, invariant reachieved with reduced measure
573 // * Returns the list of messages reported by the compiler during the parsing
574 // * or the type checking of this compilation unit. This list might be a subset of
575 // * errors detected and reported by a Java compiler.
577 // * This list of messages is suitable for simple clients that do little
578 // * more than log the messages or display them to the user. Clients that
579 // * need further details should call <code>getProblems</code> to get
580 // * compiler problem objects.
583 // * @return the list of messages, possibly empty
584 // * @see #getProblems()
587 // public Message[] getMessages() {
588 // if (this.messages == null) {
589 // int problemLength = this.problems.length;
590 // if (problemLength == 0) {
591 // this.messages = EMPTY_MESSAGES;
593 // this.messages = new Message[problemLength];
594 // for (int i = 0; i < problemLength; i++) {
595 // IProblem problem = this.problems[i];
596 // int start = problem.getSourceStart();
597 // int end = problem.getSourceEnd();
598 // messages[i] = new Message(problem.getMessage(), start, end - start + 1);
602 // return this.messages;
606 // * Returns the list of detailed problem reports noted by the compiler
607 // * during the parsing or the type checking of this compilation unit. This
608 // * list might be a subset of errors detected and reported by a Java
611 // * Simple clients that do little more than log the messages or display
612 // * them to the user should probably call <code>getMessages</code> instead.
615 // * @return the list of detailed problem objects, possibly empty
616 // * @see #getMessages()
620 // public IProblem[] getProblems() {
621 // return this.problems;
625 // * Sets the array of problems reported by the compiler during the parsing or
626 // * name resolution of this compilation unit.
628 // * @param problems the list of problems
630 // void setProblems(IProblem[] problems) {
631 // if (problems == null) {
632 // throw new IllegalArgumentException();
634 // this.problems = problems;
638 // * Returns a list of the comments encountered while parsing
639 // * this compilation unit.
641 // * Since the Java language allows comments to appear most anywhere
642 // * in the source text, it is problematic to locate comments in relation
643 // * to the structure of an AST. The one exception is doc comments
644 // * which, by convention, immediately precede type, field, and
645 // * method declarations; these comments are located in the AST
646 // * by {@link BodyDeclaration#getJavadoc BodyDeclaration.getJavadoc}.
647 // * Other comments do not show up in the AST. The table of comments
648 // * is provided for clients that need to find the source ranges of
649 // * all comments in the original source string. It includes entries
650 // * for comments of all kinds (line, block, and doc), arranged in order
651 // * of increasing source position.
653 // * Note on comment parenting: The {@link ASTNode#getParent() getParent()}
654 // * of a doc comment associated with a body declaration is the body
655 // * declaration node; for these comment nodes
656 // * {@link ASTNode#getRoot() getRoot()} will return the compilation unit
657 // * (assuming an unmodified AST) reflecting the fact that these nodes
658 // * are property located in the AST for the compilation unit.
659 // * However, for other comment nodes, {@link ASTNode#getParent() getParent()}
660 // * will return <code>null</code>, and {@link ASTNode#getRoot() getRoot()}
661 // * will return the comment node itself, indicating that these comment nodes
662 // * are not directly connected to the AST for the compilation unit. The
663 // * {@link Comment#getAlternateRoot Comment.getAlternateRoot}
664 // * method provides a way to navigate from a comment to its compilation
668 // * A note on visitors: The only comment nodes that will be visited when
669 // * visiting a compilation unit are the doc comments parented by body
670 // * declarations. To visit all comments in normal reading order, iterate
671 // * over the comment table and call {@link ASTNode#accept(ASTVisitor) accept}
672 // * on each element.
675 // * Clients cannot modify the resulting list.
678 // * @return an unmodifiable list of comments in increasing order of source
679 // * start position, or <code>null</code> if comment information
680 // * for this compilation unit is not available
684 // public List getCommentList() {
685 // return this.optionalCommentList;
689 // * Sets the list of the comments encountered while parsing
690 // * this compilation unit.
692 // * @param commentTable a list of comments in increasing order
693 // * of source start position, or <code>null</code> if comment
694 // * information for this compilation unit is not available
695 // * @exception IllegalArgumentException if the comment table is
696 // * not in increasing order of source position
697 // * @see #getCommentList()
701 // void setCommentTable(Comment[] commentTable) {
702 // // double check table to ensure that all comments have
703 // // source positions and are in strictly increasing order
704 // if (commentTable == null) {
705 // this.optionalCommentList = null;
706 // this.optionalCommentTable = null;
708 // int nextAvailablePosition = 0;
709 // for (int i = 0; i < commentTable.length; i++) {
710 // Comment comment = commentTable[i];
711 // if (comment == null) {
712 // throw new IllegalArgumentException();
714 // int start = comment.getStartPosition();
715 // int length = comment.getLength();
716 // if (start < 0 || length < 0 || start < nextAvailablePosition) {
717 // throw new IllegalArgumentException();
719 // nextAvailablePosition = comment.getStartPosition() + comment.getLength();
721 // this.optionalCommentTable = commentTable;
722 // List commentList = Arrays.asList(commentTable);
723 // // protect the list from further modification
724 // this.optionalCommentList = Collections.unmodifiableList(commentList);
729 // /* (omit javadoc for this method)
730 // * Method declared on ASTNode.
732 // void appendDebugString(StringBuffer buffer) {
733 // buffer.append("CompilationUnit"); //$NON-NLS-1$
734 // // include the type names
735 // buffer.append("["); //$NON-NLS-1$
736 // for (Iterator it = types().iterator(); it.hasNext(); ) {
737 // AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
738 // buffer.append(d.getName().getIdentifier());
739 // if (it.hasNext()) {
740 // buffer.append(","); //$NON-NLS-1$
743 // buffer.append("]"); //$NON-NLS-1$
746 // /* (omit javadoc for this method)
747 // * Method declared on ASTNode.
750 // int size = BASE_NODE_SIZE + 8 * 4;
751 // if (this.lineEndTable != null) {
752 // size += HEADERS + 4 * this.lineEndTable.length;
754 // if (this.optionalCommentTable != null) {
755 // size += HEADERS + 4 * this.optionalCommentTable.length;
757 // // ignore the space taken up by optionalCommentList
761 // /* (omit javadoc for this method)
762 // * Method declared on ASTNode.
765 // int size = memSize();
766 // if (this.optionalPackageDeclaration != null) {
767 // size += getPackage().treeSize();
769 // size += this.imports.listSize();
770 // size += this.types.listSize();
771 // // include disconnected comments
772 // if (this.optionalCommentList != null) {
773 // for (int i = 0; i < this.optionalCommentList.size(); i++) {
774 // Comment comment = (Comment) this.optionalCommentList.get(i);
775 // if (comment != null && comment.getParent() == null) {
776 // size += comment.treeSize();
784 // * Enables the recording of changes to this compilation
785 // * unit and its descendents. The compilation unit must have
786 // * been created by <code>ASTParser</code> and still be in
787 // * its original state. Once recording is on,
788 // * arbitrary changes to the subtree rooted at this compilation
789 // * unit are recorded internally. Once the modification has
790 // * been completed, call <code>rewrite</code> to get an object
791 // * representing the corresponding edits to the original
792 // * source code string.
794 // * @exception IllegalArgumentException if this compilation unit is
795 // * marked as unmodifiable, or if this compilation unit has already
796 // * been tampered with, or recording has already been enabled
799 // public void recordModifications() {
800 // getAST().recordModifications(this);
804 // * Converts all modifications recorded for this compilation
805 // * unit into an object representing the corresponding text
806 // * edits to the given document containing the original source
807 // * code for this compilation unit.
809 // * The compilation unit must have been created by
810 // * <code>ASTParser</code> from the source code string in the
811 // * given document, and recording must have been turned
812 // * on with a prior call to <code>recordModifications</code>
813 // * while the AST was still in its original state.
816 // * Calling this methods does not discard the modifications
817 // * on record. Subsequence modifications made to the AST
818 // * are added to the ones already on record. If this method
819 // * is called again later, the resulting text edit object will
820 // * accurately reflect the net cumulative affect of all those
824 // * @param document original document containing source code
825 // * for this compilation unit
826 // * @param options the table of formatter options
827 // * (key type: <code>String</code>; value type: <code>String</code>);
828 // * or <code>null</code> to use the standard global options
829 // * {@link JavaCore#getOptions() JavaCore.getOptions()}.
830 // * @return text edit object describing the changes to the
831 // * document corresponding to the recorded AST modifications
832 // * @exception IllegalArgumentException if the document passed is
833 // * <code>null</code> or does not correspond to this AST
834 // * @exception IllegalStateException if <code>recordModifications</code>
835 // * was not called to enable recording
836 // * @see #recordModifications()
839 // public TextEdit rewrite(IDocument document, Map options) {
840 // return getAST().rewrite(document, options);