A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / CompilationUnit.java
1 package net.sourceforge.phpdt.core.dom;
2
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
9  *
10  * Contributors:
11  *     IBM Corporation - initial API and implementation
12  *******************************************************************************/
13
14 /**
15  * Java compilation unit AST node type. This is the type of the root of an AST.
16  * <p>
17  * The source range for this type of node is ordinarily the entire source file,
18  * including leading and trailing whitespace and comments.
19  * </p>
20  * For JLS2:
21  * 
22  * <pre>
23  *  CompilationUnit:
24  *     [ PackageDeclaration ]
25  *         { ImportDeclaration }
26  *         { TypeDeclaration | &lt;b&gt;;&lt;/b&gt; }
27  * </pre>
28  * 
29  * For JLS3, the kinds of type declarations grew to include enum and annotation
30  * type declarations:
31  * 
32  * <pre>
33  *  CompilationUnit:
34  *     [ PackageDeclaration ]
35  *         { ImportDeclaration }
36  *         { TypeDeclaration | EnumDeclaration | AnnotationTypeDeclaration | &lt;b&gt;;&lt;/b&gt; }
37  * </pre>
38  * 
39  * @since 2.0
40  */
41 public class CompilationUnit {
42
43         // /**
44         // * The "package" structural property of this node type.
45         // *
46         // * @since 3.0
47         // */
48         // public static final ChildPropertyDescriptor PACKAGE_PROPERTY =
49         // new ChildPropertyDescriptor(CompilationUnit.class, "package",
50         // PackageDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
51         //
52         // /**
53         // * The "imports" structural property of this node type.
54         // *
55         // * @since 3.0
56         // */
57         // public static final ChildListPropertyDescriptor IMPORTS_PROPERTY =
58         // new ChildListPropertyDescriptor(CompilationUnit.class, "imports",
59         // ImportDeclaration.class, NO_CYCLE_RISK); //$NON-NLS-1$
60         //
61         // /**
62         // * The "types" structural property of this node type.
63         // *
64         // * @since 3.0
65         // */
66         // public static final ChildListPropertyDescriptor TYPES_PROPERTY =
67         // new ChildListPropertyDescriptor(CompilationUnit.class, "types",
68         // AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
69         //
70         // /**
71         // * A list of property descriptors (element type:
72         // * {@link StructuralPropertyDescriptor}),
73         // * or null if uninitialized.
74         // * @since 3.0
75         // */
76         // private static final List PROPERTY_DESCRIPTORS;
77         //
78         // static {
79         // createPropertyList(CompilationUnit.class);
80         // addProperty(PACKAGE_PROPERTY);
81         // addProperty(IMPORTS_PROPERTY);
82         // addProperty(TYPES_PROPERTY);
83         // PROPERTY_DESCRIPTORS = reapPropertyList();
84         // }
85         //
86         // /**
87         // * Returns a list of structural property descriptors for this node type.
88         // * Clients must not modify the result.
89         // *
90         // * @param apiLevel the API level; one of the
91         // * <code>AST.JLS&ast;</code> constants
92         //
93         // * @return a list of property descriptors (element type:
94         // * {@link StructuralPropertyDescriptor})
95         // * @since 3.0
96         // */
97         // public static List propertyDescriptors(int apiLevel) {
98         // return PROPERTY_DESCRIPTORS;
99         // }
100         //
101         // /**
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.
105         // * @since 3.0
106         // */
107         // Comment[] optionalCommentTable = null;
108         //
109         // /**
110         // * The comment list (element type: <code>Comment</code>,
111         // * or <code>null</code> if none; initially <code>null</code>.
112         // * @since 3.0
113         // */
114         // private List optionalCommentList = null;
115         //
116         // /**
117         // * The package declaration, or <code>null</code> if none; initially
118         // * <code>null</code>.
119         // */
120         // private PackageDeclaration optionalPackageDeclaration = null;
121         //
122         // /**
123         // * The list of import declarations in textual order order;
124         // * initially none (elementType: <code>ImportDeclaration</code>).
125         // */
126         // private ASTNode.NodeList imports =
127         // new ASTNode.NodeList(IMPORTS_PROPERTY);
128         //
129         // /**
130         // * The list of type declarations in textual order order;
131         // * initially none (elementType: <code>AbstractTypeDeclaration</code>)
132         // */
133         // private ASTNode.NodeList types =
134         // new ASTNode.NodeList(TYPES_PROPERTY);
135         //
136         // /**
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).
143         // */
144         // private int[] lineEndTable = new int[0];
145         //
146         // /**
147         // * Canonical empty list of messages.
148         // */
149         // private static final Message[] EMPTY_MESSAGES = new Message[0];
150         //
151         // /**
152         // * Canonical empty list of problems.
153         // */
154         // private static final IProblem[] EMPTY_PROBLEMS = new IProblem[0];
155         //
156         // /**
157         // * Messages reported by the compiler during parsing or name resolution.
158         // */
159         // private Message[] messages;
160         //
161         // /**
162         // * Problems reported by the compiler during parsing or name resolution.
163         // */
164         // private IProblem[] problems = EMPTY_PROBLEMS;
165         //
166         // /**
167         // * The comment mapper, or <code>null</code> in none;
168         // * initially <code>null</code>.
169         // * @since 3.0
170         // */
171         // private DefaultCommentMapper commentMapper = null;
172         //
173         // /**
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,
177         // the
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}.
181         // *
182         // * @param lineEndtable the line end table
183         // */
184         // void setLineEndTable(int[] lineEndTable) {
185         // if (lineEndTable == null) {
186         // throw new NullPointerException();
187         // }
188         // // alternate root is *not* considered a structural property
189         // // but we protect them nevertheless
190         // checkModifiable();
191         // this.lineEndTable = lineEndTable;
192         // }
193         //
194         // /**
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.
198         // * <p>
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.
202         // * </p>
203         // *
204         // * @param ast the AST that is to own this node
205         // */
206         // CompilationUnit(AST ast) {
207         // super(ast);
208         // }
209         //
210         // /* (omit javadoc for this method)
211         // * Method declared on ASTNode.
212         // * @since 3.0
213         // */
214         // final List internalStructuralPropertiesForType(int apiLevel) {
215         // return propertyDescriptors(apiLevel);
216         // }
217         //
218         // /* (omit javadoc for this method)
219         // * Method declared on ASTNode.
220         // */
221         // final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor
222         // property, boolean get, ASTNode child) {
223         // if (property == PACKAGE_PROPERTY) {
224         // if (get) {
225         // return getPackage();
226         // } else {
227         // setPackage((PackageDeclaration) child);
228         // return null;
229         // }
230         // }
231         // // allow default implementation to flag the error
232         // return super.internalGetSetChildProperty(property, get, child);
233         // }
234         //
235         // /* (omit javadoc for this method)
236         // * Method declared on ASTNode.
237         // */
238         // final List internalGetChildListProperty(ChildListPropertyDescriptor
239         // property) {
240         // if (property == IMPORTS_PROPERTY) {
241         // return imports();
242         // }
243         // if (property == TYPES_PROPERTY) {
244         // return types();
245         // }
246         // // allow default implementation to flag the error
247         // return super.internalGetChildListProperty(property);
248         // }
249         //
250         // /* (omit javadoc for this method)
251         // * Method declared on ASTNode.
252         // */
253         // final int getNodeType0() {
254         // return COMPILATION_UNIT;
255         // }
256         //
257         // /* (omit javadoc for this method)
258         // * Method declared on ASTNode.
259         // */
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()));
268         // return result;
269         // }
270         //
271         // /* (omit javadoc for this method)
272         // * Method declared on ASTNode.
273         // */
274         // final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
275         // // dispatch to correct overloaded match method
276         // return matcher.match(this, other);
277         // }
278         //
279         // /* (omit javadoc for this method)
280         // * Method declared on ASTNode.
281         // */
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);
289         // }
290         // visitor.endVisit(this);
291         // }
292         //
293         // /**
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.
297         // *
298         // * @return the package declaration node, or <code>null</code> if none
299         // */
300         // public PackageDeclaration getPackage() {
301         // return this.optionalPackageDeclaration;
302         // }
303         //
304         // /**
305         // * Sets or clears the package declaration of this compilation unit
306         // * node to the given package declaration node.
307         // *
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:
312         // * <ul>
313         // * <li>the node belongs to a different AST</li>
314         // * <li>the node already has a parent</li>
315         // * </ul>
316         // */
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);
322         // }
323         //
324         // /**
325         // * Returns the live list of nodes for the import declarations of this
326         // * compilation unit, in order of appearance.
327         // *
328         // * @return the live list of import declaration nodes
329         // * (elementType: <code>ImportDeclaration</code>)
330         // */
331         // public List imports() {
332         // return this.imports;
333         // }
334         //
335         // /**
336         // * Returns the live list of nodes for the top-level type declarations of
337         // this
338         // * compilation unit, in order of appearance.
339         // * <p>
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>.
343         // * </p>
344         // *
345         // * @return the live list of top-level type declaration
346         // * nodes (elementType: <code>AbstractTypeDeclaration</code>)
347         // */
348         // public List types() {
349         // return this.types;
350         // }
351         //
352         // /**
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
357         // requested
358         // * when this AST was built.
359         // * <p>
360         // * The following table indicates the expected node type for the various
361         // * different kinds of bindings:
362         // * <ul>
363         // * <li></li>
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>
382         // * </ul>
383         // * </p>
384         // * <p>
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
388         // returns
389         // * <code>null</code> when the binding object comes from a different AST.
390         // * Use <code>findDeclaringNode(binding.getKey())</code> when the binding
391         // comes
392         // * from a different AST.
393         // * </p>
394         // *
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
398         // this
399         // * compilation unit or if bindings were not requested when this AST was
400         // built
401         // * @see #findDeclaringNode(String)
402         // */
403         // public ASTNode findDeclaringNode(IBinding binding) {
404         // return this.ast.getBindingResolver().findDeclaringNode(binding);
405         // }
406         //
407         // /**
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
412         // requested
413         // * when this AST was built.
414         // * <p>
415         // * The following table indicates the expected node type for the various
416         // * different kinds of binding keys:
417         // * <ul>
418         // * <li></li>
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>
437         // * </ul>
438         // * </p>
439         // * <p>
440         // * Note that as explained in {@link IBinding#getKey() IBinding.getkey}
441         // * there may be no keys for finding the declaring node for local
442         // variables,
443         // * local or anonymous classes, etc.
444         // * </p>
445         // *
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()
452         // * @since 2.1
453         // */
454         // public ASTNode findDeclaringNode(String key) {
455         // return this.ast.getBindingResolver().findDeclaringNode(key);
456         // }
457         //
458         // /**
459         // * Returns the internal comment mapper.
460         // *
461         // * @return the comment mapper, or <code>null</code> if none.
462         // * @since 3.0
463         // */
464         // DefaultCommentMapper getCommentMapper() {
465         // return this.commentMapper;
466         // }
467         //
468         // /**
469         // * Initializes the internal comment mapper with the given
470         // * scanner.
471         // *
472         // * @param scanner the scanner
473         // * @since 3.0
474         // */
475         // void initCommentMapper(Scanner scanner) {
476         // this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
477         // this.commentMapper.initialize(this, scanner);
478         // }
479         //
480         // /**
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.
485         // *
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)
490         // * @since 3.0
491         // */
492         // public int getExtendedStartPosition(ASTNode node) {
493         // if (this.commentMapper == null) {
494         // return -1;
495         // } else {
496         // return this.commentMapper.getExtendedStartPosition(node);
497         // }
498         // }
499         //
500         // /**
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.
505         // *
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)
510         // * @since 3.0
511         // */
512         // public int getExtendedLength(ASTNode node) {
513         // if (this.commentMapper == null) {
514         // return 0;
515         // } else {
516         // return this.commentMapper.getExtendedLength(node);
517         // }
518         // }
519         //
520         // /**
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.
531         // *
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
538         // * @see ASTParser
539         // */
540         // public int lineNumber(int position) {
541         // int length = lineEndTable.length;
542         // if (length == 0) {
543         // // no line number info
544         // return 1;
545         // }
546         // int low = 0;
547         // if (position <= lineEndTable[low]) {
548         // // position illegal or before the first line delimiter
549         // return 1;
550         // }
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
557         // return 1;
558         // } else {
559         // return length + 1;
560         // }
561         // }
562         // // assert lineEndTable[low] < position <= lineEndTable[hi]
563         // // && low == 0 && hi == length - 1 && low < hi
564         //
565         // // binary search line end table
566         // while (true) {
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)
573         // return low + 2;
574         // }
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
581         // hi = mid;
582         // } else {
583         // // position > lineEndTable[mid]
584         // // assert lineEndTable[mid] < position <= lineEndTable[hi]
585         // // && 0 <= low < mid < hi <= length - 1
586         // low = mid;
587         // }
588         // // in both cases, invariant reachieved with reduced measure
589         // }
590         // }
591         //
592         // /**
593         // * Returns the list of messages reported by the compiler during the
594         // parsing
595         // * or the type checking of this compilation unit. This list might be a
596         // subset of
597         // * errors detected and reported by a Java compiler.
598         // * <p>
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.
603         // * </p>
604         // *
605         // * @return the list of messages, possibly empty
606         // * @see #getProblems()
607         // * @see ASTParser
608         // */
609         // public Message[] getMessages() {
610         // if (this.messages == null) {
611         // int problemLength = this.problems.length;
612         // if (problemLength == 0) {
613         // this.messages = EMPTY_MESSAGES;
614         // } else {
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);
621         // }
622         // }
623         // }
624         // return this.messages;
625         // }
626         //
627         // /**
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
631         // * compiler.
632         // * <p>
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.
635         // * </p>
636         // *
637         // * @return the list of detailed problem objects, possibly empty
638         // * @see #getMessages()
639         // * @see ASTParser
640         // * @since 2.1
641         // */
642         // public IProblem[] getProblems() {
643         // return this.problems;
644         // }
645         //
646         // /**
647         // * Sets the array of problems reported by the compiler during the parsing
648         // or
649         // * name resolution of this compilation unit.
650         // *
651         // * @param problems the list of problems
652         // */
653         // void setProblems(IProblem[] problems) {
654         // if (problems == null) {
655         // throw new IllegalArgumentException();
656         // }
657         // this.problems = problems;
658         // }
659         //
660         // /**
661         // * Returns a list of the comments encountered while parsing
662         // * this compilation unit.
663         // * <p>
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.
675         // * </p>
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()
683         // getParent()}
684         // * will return <code>null</code>, and {@link ASTNode#getRoot() getRoot()}
685         // * will return the comment node itself, indicating that these comment
686         // nodes
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
690         // * unit.
691         // * </p>
692         // * <p>
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)
697         // accept}
698         // * on each element.
699         // * </p>
700         // * <p>
701         // * Clients cannot modify the resulting list.
702         // * </p>
703         // *
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
707         // * @see ASTParser
708         // * @since 3.0
709         // */
710         // public List getCommentList() {
711         // return this.optionalCommentList;
712         // }
713         //
714         // /**
715         // * Sets the list of the comments encountered while parsing
716         // * this compilation unit.
717         // *
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()
724         // * @see ASTParser
725         // * @since 3.0
726         // */
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;
733         // } else {
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();
739         // }
740         // int start = comment.getStartPosition();
741         // int length = comment.getLength();
742         // if (start < 0 || length < 0 || start < nextAvailablePosition) {
743         // throw new IllegalArgumentException();
744         // }
745         // nextAvailablePosition = comment.getStartPosition() + comment.getLength();
746         // }
747         // this.optionalCommentTable = commentTable;
748         // List commentList = Arrays.asList(commentTable);
749         // // protect the list from further modification
750         // this.optionalCommentList = Collections.unmodifiableList(commentList);
751         // }
752         // }
753         //
754         //
755         // /* (omit javadoc for this method)
756         // * Method declared on ASTNode.
757         // */
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$
767         // }
768         // }
769         // buffer.append("]"); //$NON-NLS-1$
770         // }
771         //
772         // /* (omit javadoc for this method)
773         // * Method declared on ASTNode.
774         // */
775         // int memSize() {
776         // int size = BASE_NODE_SIZE + 8 * 4;
777         // if (this.lineEndTable != null) {
778         // size += HEADERS + 4 * this.lineEndTable.length;
779         // }
780         // if (this.optionalCommentTable != null) {
781         // size += HEADERS + 4 * this.optionalCommentTable.length;
782         // }
783         // // ignore the space taken up by optionalCommentList
784         // return size;
785         // }
786         //
787         // /* (omit javadoc for this method)
788         // * Method declared on ASTNode.
789         // */
790         // int treeSize() {
791         // int size = memSize();
792         // if (this.optionalPackageDeclaration != null) {
793         // size += getPackage().treeSize();
794         // }
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();
803         // }
804         // }
805         // }
806         // return size;
807         // }
808         //
809         // /**
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.
819         // *
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
823         // * @since 3.0
824         // */
825         // public void recordModifications() {
826         // getAST().recordModifications(this);
827         // }
828         //
829         // /**
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.
834         // * <p>
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.
840         // * </p>
841         // * <p>
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
847         // * changes.
848         // * </p>
849         // *
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()
863         // * @since 3.0
864         // */
865         // public TextEdit rewrite(IDocument document, Map options) {
866         // return getAST().rewrite(document, options);
867         // }
868 }