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;
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.Iterator;
17 import java.util.List;
20 import net.sourceforge.phpdt.core.compiler.IProblem;
21 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.text.edits.TextEdit;
26 * Java compilation unit AST node type. This is the type of the root of an AST.
28 * The source range for this type of node is ordinarily the entire source file,
29 * including leading and trailing whitespace and comments.
34 * [ PackageDeclaration ]
35 * { ImportDeclaration }
36 * { TypeDeclaration | <b>;</b> }
38 * For JLS3, the kinds of type declarations
39 * grew to include enum and annotation type declarations:
42 * [ PackageDeclaration ]
43 * { ImportDeclaration }
44 * { TypeDeclaration | EnumDeclaration | AnnotationTypeDeclaration | <b>;</b> }
49 public class CompilationUnit {
52 // * The "package" structural property of this node type.
56 // public static final ChildPropertyDescriptor PACKAGE_PROPERTY =
57 // new ChildPropertyDescriptor(CompilationUnit.class, "package", PackageDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
60 // * The "imports" structural property of this node type.
64 // public static final ChildListPropertyDescriptor IMPORTS_PROPERTY =
65 // new ChildListPropertyDescriptor(CompilationUnit.class, "imports", ImportDeclaration.class, NO_CYCLE_RISK); //$NON-NLS-1$
68 // * The "types" structural property of this node type.
72 // public static final ChildListPropertyDescriptor TYPES_PROPERTY =
73 // new ChildListPropertyDescriptor(CompilationUnit.class, "types", AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
76 // * A list of property descriptors (element type:
77 // * {@link StructuralPropertyDescriptor}),
78 // * or null if uninitialized.
81 // private static final List PROPERTY_DESCRIPTORS;
84 // createPropertyList(CompilationUnit.class);
85 // addProperty(PACKAGE_PROPERTY);
86 // addProperty(IMPORTS_PROPERTY);
87 // addProperty(TYPES_PROPERTY);
88 // PROPERTY_DESCRIPTORS = reapPropertyList();
92 // * Returns a list of structural property descriptors for this node type.
93 // * Clients must not modify the result.
95 // * @param apiLevel the API level; one of the
96 // * <code>AST.JLS*</code> constants
98 // * @return a list of property descriptors (element type:
99 // * {@link StructuralPropertyDescriptor})
102 // public static List propertyDescriptors(int apiLevel) {
103 // return PROPERTY_DESCRIPTORS;
107 // * The comment table, or <code>null</code> if none; initially
108 // * <code>null</code>. This array is the storage underlying
109 // * the <code>optionalCommentList</code> ArrayList.
112 // Comment[] optionalCommentTable = null;
115 // * The comment list (element type: <code>Comment</code>,
116 // * or <code>null</code> if none; initially <code>null</code>.
119 // private List optionalCommentList = null;
122 // * The package declaration, or <code>null</code> if none; initially
123 // * <code>null</code>.
125 // private PackageDeclaration optionalPackageDeclaration = null;
128 // * The list of import declarations in textual order order;
129 // * initially none (elementType: <code>ImportDeclaration</code>).
131 // private ASTNode.NodeList imports =
132 // new ASTNode.NodeList(IMPORTS_PROPERTY);
135 // * The list of type declarations in textual order order;
136 // * initially none (elementType: <code>AbstractTypeDeclaration</code>)
138 // private ASTNode.NodeList types =
139 // new ASTNode.NodeList(TYPES_PROPERTY);
142 // * Line end table. If <code>lineEndTable[i] == p</code> then the
143 // * line number <code>i+1</code> ends at character position
144 // * <code>p</code>. Except for the last line, the positions are that
145 // * of the last character of the line delimiter.
146 // * For example, the source string <code>A\nB\nC</code> has
147 // * line end table {1, 3} (if \n is one character).
149 // private int[] lineEndTable = new int[0];
152 // * Canonical empty list of messages.
154 // private static final Message[] EMPTY_MESSAGES = new Message[0];
157 // * Canonical empty list of problems.
159 // private static final IProblem[] EMPTY_PROBLEMS = new IProblem[0];
162 // * Messages reported by the compiler during parsing or name resolution.
164 // private Message[] messages;
167 // * Problems reported by the compiler during parsing or name resolution.
169 // private IProblem[] problems = EMPTY_PROBLEMS;
172 // * The comment mapper, or <code>null</code> in none;
173 // * initially <code>null</code>.
176 // private DefaultCommentMapper commentMapper = null;
179 // * Sets the line end table for this compilation unit.
180 // * If <code>lineEndTable[i] == p</code> then line number <code>i+1</code>
181 // * ends at character position <code>p</code>. Except for the last line, the
182 // * positions are that of (the last character of) the line delimiter.
183 // * For example, the source string <code>A\nB\nC</code> has
184 // * line end table {1, 3, 4}.
186 // * @param lineEndtable the line end table
188 // void setLineEndTable(int[] lineEndTable) {
189 // if (lineEndTable == null) {
190 // throw new NullPointerException();
192 // // alternate root is *not* considered a structural property
193 // // but we protect them nevertheless
194 // checkModifiable();
195 // this.lineEndTable = lineEndTable;
199 // * Creates a new AST node for a compilation owned by the given AST.
200 // * The compilation unit initially has no package declaration, no
201 // * import declarations, and no type declarations.
203 // * N.B. This constructor is package-private; all subclasses must be
204 // * declared in the same package; clients are unable to declare
205 // * additional subclasses.
208 // * @param ast the AST that is to own this node
210 // CompilationUnit(AST ast) {
214 // /* (omit javadoc for this method)
215 // * Method declared on ASTNode.
218 // final List internalStructuralPropertiesForType(int apiLevel) {
219 // return propertyDescriptors(apiLevel);
222 // /* (omit javadoc for this method)
223 // * Method declared on ASTNode.
225 // final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
226 // if (property == PACKAGE_PROPERTY) {
228 // return getPackage();
230 // setPackage((PackageDeclaration) child);
234 // // allow default implementation to flag the error
235 // return super.internalGetSetChildProperty(property, get, child);
238 // /* (omit javadoc for this method)
239 // * Method declared on ASTNode.
241 // final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
242 // if (property == IMPORTS_PROPERTY) {
245 // if (property == TYPES_PROPERTY) {
248 // // allow default implementation to flag the error
249 // return super.internalGetChildListProperty(property);
252 // /* (omit javadoc for this method)
253 // * Method declared on ASTNode.
255 // final int getNodeType0() {
256 // return COMPILATION_UNIT;
259 // /* (omit javadoc for this method)
260 // * Method declared on ASTNode.
262 // ASTNode clone0(AST target) {
263 // CompilationUnit result = new CompilationUnit(target);
264 // // n.b do not copy line number table or messages
265 // result.setSourceRange(this.getStartPosition(), this.getLength());
266 // result.setPackage(
267 // (PackageDeclaration) ASTNode.copySubtree(target, getPackage()));
268 // result.imports().addAll(ASTNode.copySubtrees(target, imports()));
269 // result.types().addAll(ASTNode.copySubtrees(target, types()));
273 // /* (omit javadoc for this method)
274 // * Method declared on ASTNode.
276 // final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
277 // // dispatch to correct overloaded match method
278 // return matcher.match(this, other);
281 // /* (omit javadoc for this method)
282 // * Method declared on ASTNode.
284 // void accept0(ASTVisitor visitor) {
285 // boolean visitChildren = visitor.visit(this);
286 // if (visitChildren) {
287 // // visit children in normal left to right reading order
288 // acceptChild(visitor, getPackage());
289 // acceptChildren(visitor, this.imports);
290 // acceptChildren(visitor, this.types);
292 // visitor.endVisit(this);
296 // * Returns the node for the package declaration of this compilation
297 // * unit, or <code>null</code> if this compilation unit is in the
298 // * default package.
300 // * @return the package declaration node, or <code>null</code> if none
302 // public PackageDeclaration getPackage() {
303 // return this.optionalPackageDeclaration;
307 // * Sets or clears the package declaration of this compilation unit
308 // * node to the given package declaration node.
310 // * @param pkgDecl the new package declaration node, or
311 // * <code>null</code> if this compilation unit does not have a package
312 // * declaration (that is in the default package)
313 // * @exception IllegalArgumentException if:
315 // * <li>the node belongs to a different AST</li>
316 // * <li>the node already has a parent</li>
319 // public void setPackage(PackageDeclaration pkgDecl) {
320 // ASTNode oldChild = this.optionalPackageDeclaration;
321 // preReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
322 // this.optionalPackageDeclaration = pkgDecl;
323 // postReplaceChild(oldChild, pkgDecl, PACKAGE_PROPERTY);
327 // * Returns the live list of nodes for the import declarations of this
328 // * compilation unit, in order of appearance.
330 // * @return the live list of import declaration nodes
331 // * (elementType: <code>ImportDeclaration</code>)
333 // public List imports() {
334 // return this.imports;
338 // * Returns the live list of nodes for the top-level type declarations of this
339 // * compilation unit, in order of appearance.
341 // * Note that in JLS3, the types may include both enum declarations
342 // * and annotation type declarations introduced in J2SE 1.5.
343 // * For JLS2, the elements are always <code>TypeDeclaration</code>.
346 // * @return the live list of top-level type declaration
347 // * nodes (elementType: <code>AbstractTypeDeclaration</code>)
349 // public List types() {
350 // return this.types;
354 // * Finds the corresponding AST node in the given compilation unit from
355 // * which the given binding originated. Returns <code>null</code> if the
356 // * binding does not correspond to any node in this compilation unit.
357 // * This method always returns <code>null</code> if bindings were not requested
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 <code>AnnotationTypeMemberDeclaration</code></li>
379 // * <li>enum type - an <code>EnumDeclaration</code></li>
380 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
384 // * Each call to {@link ASTParser#createAST(IProgressMonitor)} with a request for bindings
385 // * gives rise to separate universe of binding objects. This method always returns
386 // * <code>null</code> when the binding object comes from a different AST.
387 // * Use <code>findDeclaringNode(binding.getKey())</code> when the binding comes
388 // * from a different AST.
391 // * @param binding the binding
392 // * @return the corresponding node where the given binding is declared,
393 // * or <code>null</code> if the binding does not correspond to a node in this
394 // * compilation unit or if bindings were not requested when this AST was built
395 // * @see #findDeclaringNode(String)
397 // public ASTNode findDeclaringNode(IBinding binding) {
398 // return this.ast.getBindingResolver().findDeclaringNode(binding);
402 // * Finds the corresponding AST node in the given compilation unit from
403 // * which the binding with the given key originated. Returns
404 // * <code>null</code> if the corresponding node cannot be determined.
405 // * This method always returns <code>null</code> if bindings were not requested
406 // * when this AST was built.
408 // * The following table indicates the expected node type for the various
409 // * different kinds of binding keys:
412 // * <li>package - a <code>PackageDeclaration</code></li>
413 // * <li>class or interface - a <code>TypeDeclaration</code> or a
414 // * <code>AnonymousClassDeclaration</code> (for anonymous classes)</li>
415 // * <li>primitive type - none</li>
416 // * <li>array type - none</li>
417 // * <li>field - a <code>VariableDeclarationFragment</code> in a
418 // * <code>FieldDeclaration</code> </li>
419 // * <li>local variable - a <code>SingleVariableDeclaration</code>, or
420 // * a <code>VariableDeclarationFragment</code> in a
421 // * <code>VariableDeclarationStatement</code> or
422 // * <code>VariableDeclarationExpression</code></li>
423 // * <li>method - a <code>MethodDeclaration</code> </li>
424 // * <li>constructor - a <code>MethodDeclaration</code> </li>
425 // * <li>annotation type - an <code>AnnotationTypeDeclaration</code></li>
426 // * <li>annotation type member - an <code>AnnotationTypeMemberDeclaration</code></li>
427 // * <li>enum type - an <code>EnumDeclaration</code></li>
428 // * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
432 // * Note that as explained in {@link IBinding#getKey() IBinding.getkey}
433 // * there may be no keys for finding the declaring node for local variables,
434 // * local or anonymous classes, etc.
437 // * @param key the binding key, or <code>null</code>
438 // * @return the corresponding node where a binding with the given
439 // * key is declared, or <code>null</code> if the key is <code>null</code>
440 // * or if the key does not correspond to a node in this compilation unit
441 // * or if bindings were not requested when this AST was built
442 // * @see IBinding#getKey()
445 // public ASTNode findDeclaringNode(String key) {
446 // return this.ast.getBindingResolver().findDeclaringNode(key);
450 // * Returns the internal comment mapper.
452 // * @return the comment mapper, or <code>null</code> if none.
455 // DefaultCommentMapper getCommentMapper() {
456 // return this.commentMapper;
460 // * Initializes the internal comment mapper with the given
463 // * @param scanner the scanner
466 // void initCommentMapper(Scanner scanner) {
467 // this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
468 // this.commentMapper.initialize(this, scanner);
472 // * Returns the extended start position of the given node. Unlike
473 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
474 // * the extended source range may include comments and whitespace
475 // * immediately before or after the normal source range for the node.
477 // * @param node the node
478 // * @return the 0-based character index, or <code>-1</code>
479 // * if no source position information is recorded for this node
480 // * @see #getExtendedLength(ASTNode)
483 // public int getExtendedStartPosition(ASTNode node) {
484 // if (this.commentMapper == null) {
487 // return this.commentMapper.getExtendedStartPosition(node);
492 // * Returns the extended source length of the given node. Unlike
493 // * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()()},
494 // * the extended source range may include comments and whitespace
495 // * immediately before or after the normal source range for the node.
497 // * @param node the node
498 // * @return a (possibly 0) length, or <code>0</code>
499 // * if no source position information is recorded for this node
500 // * @see #getExtendedStartPosition(ASTNode)
503 // public int getExtendedLength(ASTNode node) {
504 // if (this.commentMapper == null) {
507 // return this.commentMapper.getExtendedLength(node);
512 // * Returns the line number corresponding to the given source character
513 // * position in the original source string. The initial line of the
514 // * compilation unit is numbered 1, and each line extends through the
515 // * last character of the end-of-line delimiter. The very last line extends
516 // * through the end of the source string and has no line delimiter.
517 // * For example, the source string <code>class A\n{\n}</code> has 3 lines
518 // * corresponding to inclusive character ranges [0,7], [8,9], and [10,10].
519 // * Returns 1 for a character position that does not correspond to any
520 // * source line, or if no line number information is available for this
521 // * compilation unit.
523 // * @param position a 0-based character position, possibly
524 // * negative or out of range
525 // * @return the 1-based line number, or <code>1</code> if the character
526 // * position does not correspond to a source line in the original
527 // * source file or if line number information is not known for this
528 // * compilation unit
531 // public int lineNumber(int position) {
532 // int length = lineEndTable.length;
533 // if (length == 0) {
534 // // no line number info
538 // if (position <= lineEndTable[low]) {
539 // // position illegal or before the first line delimiter
542 // // assert position > lineEndTable[low+1] && low == 0
543 // int hi = length - 1;
544 // if (position > lineEndTable[hi]) {
545 // // position beyond the last line separator
546 // if (position >= getStartPosition() + getLength()) {
547 // // this is beyond the end of the source length
550 // return length + 1;
553 // // assert lineEndTable[low] < position <= lineEndTable[hi]
554 // // && low == 0 && hi == length - 1 && low < hi
556 // // binary search line end table
558 // // invariant lineEndTable[low] < position <= lineEndTable[hi]
559 // // && 0 <= low < hi <= length - 1
560 // // reducing measure hi - low
561 // if (low + 1 == hi) {
562 // // assert lineEndTable[low] < position <= lineEndTable[low+1]
563 // // position is on line low+1 (line number is low+2)
566 // // assert hi - low >= 2, so average is truly in between
567 // int mid = (low + hi) / 2;
568 // // assert 0 <= low < mid < hi <= length - 1
569 // if (position <= lineEndTable[mid]) {
570 // // assert lineEndTable[low] < position <= lineEndTable[mid]
571 // // && 0 <= low < mid < hi <= length - 1
574 // // position > lineEndTable[mid]
575 // // assert lineEndTable[mid] < position <= lineEndTable[hi]
576 // // && 0 <= low < mid < hi <= length - 1
579 // // in both cases, invariant reachieved with reduced measure
584 // * Returns the list of messages reported by the compiler during the parsing
585 // * or the type checking of this compilation unit. This list might be a subset of
586 // * errors detected and reported by a Java compiler.
588 // * This list of messages is suitable for simple clients that do little
589 // * more than log the messages or display them to the user. Clients that
590 // * need further details should call <code>getProblems</code> to get
591 // * compiler problem objects.
594 // * @return the list of messages, possibly empty
595 // * @see #getProblems()
598 // public Message[] getMessages() {
599 // if (this.messages == null) {
600 // int problemLength = this.problems.length;
601 // if (problemLength == 0) {
602 // this.messages = EMPTY_MESSAGES;
604 // this.messages = new Message[problemLength];
605 // for (int i = 0; i < problemLength; i++) {
606 // IProblem problem = this.problems[i];
607 // int start = problem.getSourceStart();
608 // int end = problem.getSourceEnd();
609 // messages[i] = new Message(problem.getMessage(), start, end - start + 1);
613 // return this.messages;
617 // * Returns the list of detailed problem reports noted by the compiler
618 // * during the parsing or the type checking of this compilation unit. This
619 // * list might be a subset of errors detected and reported by a Java
622 // * Simple clients that do little more than log the messages or display
623 // * them to the user should probably call <code>getMessages</code> instead.
626 // * @return the list of detailed problem objects, possibly empty
627 // * @see #getMessages()
631 // public IProblem[] getProblems() {
632 // return this.problems;
636 // * Sets the array of problems reported by the compiler during the parsing or
637 // * name resolution of this compilation unit.
639 // * @param problems the list of problems
641 // void setProblems(IProblem[] problems) {
642 // if (problems == null) {
643 // throw new IllegalArgumentException();
645 // this.problems = problems;
649 // * Returns a list of the comments encountered while parsing
650 // * this compilation unit.
652 // * Since the Java language allows comments to appear most anywhere
653 // * in the source text, it is problematic to locate comments in relation
654 // * to the structure of an AST. The one exception is doc comments
655 // * which, by convention, immediately precede type, field, and
656 // * method declarations; these comments are located in the AST
657 // * by {@link BodyDeclaration#getJavadoc BodyDeclaration.getJavadoc}.
658 // * Other comments do not show up in the AST. The table of comments
659 // * is provided for clients that need to find the source ranges of
660 // * all comments in the original source string. It includes entries
661 // * for comments of all kinds (line, block, and doc), arranged in order
662 // * of increasing source position.
664 // * Note on comment parenting: The {@link ASTNode#getParent() getParent()}
665 // * of a doc comment associated with a body declaration is the body
666 // * declaration node; for these comment nodes
667 // * {@link ASTNode#getRoot() getRoot()} will return the compilation unit
668 // * (assuming an unmodified AST) reflecting the fact that these nodes
669 // * are property located in the AST for the compilation unit.
670 // * However, for other comment nodes, {@link ASTNode#getParent() getParent()}
671 // * will return <code>null</code>, and {@link ASTNode#getRoot() getRoot()}
672 // * will return the comment node itself, indicating that these comment nodes
673 // * are not directly connected to the AST for the compilation unit. The
674 // * {@link Comment#getAlternateRoot Comment.getAlternateRoot}
675 // * method provides a way to navigate from a comment to its compilation
679 // * A note on visitors: The only comment nodes that will be visited when
680 // * visiting a compilation unit are the doc comments parented by body
681 // * declarations. To visit all comments in normal reading order, iterate
682 // * over the comment table and call {@link ASTNode#accept(ASTVisitor) accept}
683 // * on each element.
686 // * Clients cannot modify the resulting list.
689 // * @return an unmodifiable list of comments in increasing order of source
690 // * start position, or <code>null</code> if comment information
691 // * for this compilation unit is not available
695 // public List getCommentList() {
696 // return this.optionalCommentList;
700 // * Sets the list of the comments encountered while parsing
701 // * this compilation unit.
703 // * @param commentTable a list of comments in increasing order
704 // * of source start position, or <code>null</code> if comment
705 // * information for this compilation unit is not available
706 // * @exception IllegalArgumentException if the comment table is
707 // * not in increasing order of source position
708 // * @see #getCommentList()
712 // void setCommentTable(Comment[] commentTable) {
713 // // double check table to ensure that all comments have
714 // // source positions and are in strictly increasing order
715 // if (commentTable == null) {
716 // this.optionalCommentList = null;
717 // this.optionalCommentTable = null;
719 // int nextAvailablePosition = 0;
720 // for (int i = 0; i < commentTable.length; i++) {
721 // Comment comment = commentTable[i];
722 // if (comment == null) {
723 // throw new IllegalArgumentException();
725 // int start = comment.getStartPosition();
726 // int length = comment.getLength();
727 // if (start < 0 || length < 0 || start < nextAvailablePosition) {
728 // throw new IllegalArgumentException();
730 // nextAvailablePosition = comment.getStartPosition() + comment.getLength();
732 // this.optionalCommentTable = commentTable;
733 // List commentList = Arrays.asList(commentTable);
734 // // protect the list from further modification
735 // this.optionalCommentList = Collections.unmodifiableList(commentList);
740 // /* (omit javadoc for this method)
741 // * Method declared on ASTNode.
743 // void appendDebugString(StringBuffer buffer) {
744 // buffer.append("CompilationUnit"); //$NON-NLS-1$
745 // // include the type names
746 // buffer.append("["); //$NON-NLS-1$
747 // for (Iterator it = types().iterator(); it.hasNext(); ) {
748 // AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
749 // buffer.append(d.getName().getIdentifier());
750 // if (it.hasNext()) {
751 // buffer.append(","); //$NON-NLS-1$
754 // buffer.append("]"); //$NON-NLS-1$
757 // /* (omit javadoc for this method)
758 // * Method declared on ASTNode.
761 // int size = BASE_NODE_SIZE + 8 * 4;
762 // if (this.lineEndTable != null) {
763 // size += HEADERS + 4 * this.lineEndTable.length;
765 // if (this.optionalCommentTable != null) {
766 // size += HEADERS + 4 * this.optionalCommentTable.length;
768 // // ignore the space taken up by optionalCommentList
772 // /* (omit javadoc for this method)
773 // * Method declared on ASTNode.
776 // int size = memSize();
777 // if (this.optionalPackageDeclaration != null) {
778 // size += getPackage().treeSize();
780 // size += this.imports.listSize();
781 // size += this.types.listSize();
782 // // include disconnected comments
783 // if (this.optionalCommentList != null) {
784 // for (int i = 0; i < this.optionalCommentList.size(); i++) {
785 // Comment comment = (Comment) this.optionalCommentList.get(i);
786 // if (comment != null && comment.getParent() == null) {
787 // size += comment.treeSize();
795 // * Enables the recording of changes to this compilation
796 // * unit and its descendents. The compilation unit must have
797 // * been created by <code>ASTParser</code> and still be in
798 // * its original state. Once recording is on,
799 // * arbitrary changes to the subtree rooted at this compilation
800 // * unit are recorded internally. Once the modification has
801 // * been completed, call <code>rewrite</code> to get an object
802 // * representing the corresponding edits to the original
803 // * source code string.
805 // * @exception IllegalArgumentException if this compilation unit is
806 // * marked as unmodifiable, or if this compilation unit has already
807 // * been tampered with, or recording has already been enabled
810 // public void recordModifications() {
811 // getAST().recordModifications(this);
815 // * Converts all modifications recorded for this compilation
816 // * unit into an object representing the corresponding text
817 // * edits to the given document containing the original source
818 // * code for this compilation unit.
820 // * The compilation unit must have been created by
821 // * <code>ASTParser</code> from the source code string in the
822 // * given document, and recording must have been turned
823 // * on with a prior call to <code>recordModifications</code>
824 // * while the AST was still in its original state.
827 // * Calling this methods does not discard the modifications
828 // * on record. Subsequence modifications made to the AST
829 // * are added to the ones already on record. If this method
830 // * is called again later, the resulting text edit object will
831 // * accurately reflect the net cumulative affect of all those
835 // * @param document original document containing source code
836 // * for this compilation unit
837 // * @param options the table of formatter options
838 // * (key type: <code>String</code>; value type: <code>String</code>);
839 // * or <code>null</code> to use the standard global options
840 // * {@link JavaCore#getOptions() JavaCore.getOptions()}.
841 // * @return text edit object describing the changes to the
842 // * document corresponding to the recorded AST modifications
843 // * @exception IllegalArgumentException if the document passed is
844 // * <code>null</code> or does not correspond to this AST
845 // * @exception IllegalStateException if <code>recordModifications</code>
846 // * was not called to enable recording
847 // * @see #recordModifications()
850 // public TextEdit rewrite(IDocument document, Map options) {
851 // return getAST().rewrite(document, options);