3m9 compatible;
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / CompilationUnit.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.core.dom;
13
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Map;
19
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;
24
25 /**
26  * Java compilation unit AST node type. This is the type of the root of an AST.
27  * <p>
28  * The source range for this type of node is ordinarily the entire source file,
29  * including leading and trailing whitespace and comments.
30  * </p>
31  * For JLS2:
32  * <pre>
33  * CompilationUnit:
34  *    [ PackageDeclaration ]
35  *        { ImportDeclaration }
36  *        { TypeDeclaration | <b>;</b> }
37  * </pre>
38  * For JLS3, the kinds of type declarations
39  * grew to include enum and annotation type declarations:
40  * <pre>
41  * CompilationUnit:
42  *    [ PackageDeclaration ]
43  *        { ImportDeclaration }
44  *        { TypeDeclaration | EnumDeclaration | AnnotationTypeDeclaration | <b>;</b> }
45  * </pre>
46  * 
47  * @since 2.0
48  */
49 public class CompilationUnit  {
50
51 //      /**
52 //       * The "package" structural property of this node type.
53 //       * 
54 //       * @since 3.0
55 //       */
56 //      public static final ChildPropertyDescriptor PACKAGE_PROPERTY = 
57 //              new ChildPropertyDescriptor(CompilationUnit.class, "package", PackageDeclaration.class, OPTIONAL, NO_CYCLE_RISK); //$NON-NLS-1$
58 //      
59 //      /**
60 //       * The "imports" structural property of this node type.
61 //       * 
62 //       * @since 3.0
63 //       */
64 //      public static final ChildListPropertyDescriptor IMPORTS_PROPERTY =
65 //              new ChildListPropertyDescriptor(CompilationUnit.class, "imports", ImportDeclaration.class, NO_CYCLE_RISK); //$NON-NLS-1$
66 //      
67 //      /**
68 //       * The "types" structural property of this node type.
69 //       * 
70 //       * @since 3.0
71 //       */
72 //      public static final ChildListPropertyDescriptor TYPES_PROPERTY =
73 //              new ChildListPropertyDescriptor(CompilationUnit.class, "types", AbstractTypeDeclaration.class, CYCLE_RISK); //$NON-NLS-1$
74 //      
75 //      /**
76 //       * A list of property descriptors (element type: 
77 //       * {@link StructuralPropertyDescriptor}),
78 //       * or null if uninitialized.
79 //       * @since 3.0
80 //       */
81 //      private static final List PROPERTY_DESCRIPTORS;
82 //      
83 //      static {
84 //              createPropertyList(CompilationUnit.class);
85 //              addProperty(PACKAGE_PROPERTY);
86 //              addProperty(IMPORTS_PROPERTY);
87 //              addProperty(TYPES_PROPERTY);
88 //              PROPERTY_DESCRIPTORS = reapPropertyList();
89 //      }
90 //
91 //      /**
92 //       * Returns a list of structural property descriptors for this node type.
93 //       * Clients must not modify the result.
94 //       * 
95 //       * @param apiLevel the API level; one of the
96 //       * <code>AST.JLS&ast;</code> constants
97 //
98 //       * @return a list of property descriptors (element type: 
99 //       * {@link StructuralPropertyDescriptor})
100 //       * @since 3.0
101 //       */
102 //      public static List propertyDescriptors(int apiLevel) {
103 //              return PROPERTY_DESCRIPTORS;
104 //      }
105 //                      
106 //      /**
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.
110 //       * @since 3.0
111 //       */
112 //      Comment[] optionalCommentTable = null;
113 //      
114 //      /**
115 //       * The comment list (element type: <code>Comment</code>, 
116 //       * or <code>null</code> if none; initially <code>null</code>.
117 //       * @since 3.0
118 //       */
119 //      private List optionalCommentList = null;
120 //      
121 //      /**
122 //       * The package declaration, or <code>null</code> if none; initially
123 //       * <code>null</code>.
124 //       */
125 //      private PackageDeclaration optionalPackageDeclaration = null;
126 //      
127 //      /**
128 //       * The list of import declarations in textual order order; 
129 //       * initially none (elementType: <code>ImportDeclaration</code>).
130 //       */
131 //      private ASTNode.NodeList imports =
132 //              new ASTNode.NodeList(IMPORTS_PROPERTY);
133 //      
134 //      /**
135 //       * The list of type declarations in textual order order; 
136 //       * initially none (elementType: <code>AbstractTypeDeclaration</code>)
137 //       */
138 //      private ASTNode.NodeList types =
139 //              new ASTNode.NodeList(TYPES_PROPERTY);
140 //      
141 //      /**
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).
148 //       */
149 //      private int[] lineEndTable = new int[0];
150 //
151 //      /**
152 //       * Canonical empty list of messages.
153 //       */
154 //      private static final Message[] EMPTY_MESSAGES = new Message[0];
155 //
156 //      /**
157 //       * Canonical empty list of problems.
158 //       */
159 //      private static final IProblem[] EMPTY_PROBLEMS = new IProblem[0];
160 //
161 //      /**
162 //       * Messages reported by the compiler during parsing or name resolution.
163 //       */
164 //      private Message[] messages;
165 //      
166 //      /**
167 //       * Problems reported by the compiler during parsing or name resolution.
168 //       */
169 //      private IProblem[] problems = EMPTY_PROBLEMS;
170 //      
171 //      /**
172 //       * The comment mapper, or <code>null</code> in none; 
173 //       * initially <code>null</code>.
174 //       * @since 3.0
175 //       */
176 //      private DefaultCommentMapper commentMapper = null;
177 //      
178 //      /**
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}.
185 //       * 
186 //       * @param lineEndtable the line end table
187 //       */
188 //      void setLineEndTable(int[] lineEndTable) {
189 //              if (lineEndTable == null) {
190 //                      throw new NullPointerException();
191 //              }
192 //              // alternate root is *not* considered a structural property
193 //              // but we protect them nevertheless
194 //              checkModifiable();
195 //              this.lineEndTable = lineEndTable;
196 //      }
197 //
198 //      /**
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.
202 //       * <p>
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.
206 //       * </p>
207 //       * 
208 //       * @param ast the AST that is to own this node
209 //       */
210 //      CompilationUnit(AST ast) {
211 //              super(ast);
212 //      }
213 //
214 //      /* (omit javadoc for this method)
215 //       * Method declared on ASTNode.
216 //       * @since 3.0
217 //       */
218 //      final List internalStructuralPropertiesForType(int apiLevel) {
219 //              return propertyDescriptors(apiLevel);
220 //      }
221 //      
222 //      /* (omit javadoc for this method)
223 //       * Method declared on ASTNode.
224 //       */
225 //      final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) {
226 //              if (property == PACKAGE_PROPERTY) {
227 //                      if (get) {
228 //                              return getPackage();
229 //                      } else {
230 //                              setPackage((PackageDeclaration) child);
231 //                              return null;
232 //                      }
233 //              }
234 //              // allow default implementation to flag the error
235 //              return super.internalGetSetChildProperty(property, get, child);
236 //      }
237 //      
238 //      /* (omit javadoc for this method)
239 //       * Method declared on ASTNode.
240 //       */
241 //      final List internalGetChildListProperty(ChildListPropertyDescriptor property) {
242 //              if (property == IMPORTS_PROPERTY) {
243 //                      return imports();
244 //              }
245 //              if (property == TYPES_PROPERTY) {
246 //                      return types();
247 //              }
248 //              // allow default implementation to flag the error
249 //              return super.internalGetChildListProperty(property);
250 //      }
251 //      
252 //      /* (omit javadoc for this method)
253 //       * Method declared on ASTNode.
254 //       */
255 //      final int getNodeType0() {
256 //              return COMPILATION_UNIT;
257 //      }
258 //
259 //      /* (omit javadoc for this method)
260 //       * Method declared on ASTNode.
261 //       */
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()));
270 //              return result;
271 //      }
272 //
273 //      /* (omit javadoc for this method)
274 //       * Method declared on ASTNode.
275 //       */
276 //      final boolean subtreeMatch0(ASTMatcher matcher, Object other) {
277 //              // dispatch to correct overloaded match method
278 //              return matcher.match(this, other);
279 //      }
280 //
281 //      /* (omit javadoc for this method)
282 //       * Method declared on ASTNode.
283 //       */
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);
291 //              }
292 //              visitor.endVisit(this);
293 //      }
294 //      
295 //      /**
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.
299 //       * 
300 //       * @return the package declaration node, or <code>null</code> if none
301 //       */ 
302 //      public PackageDeclaration getPackage() {
303 //              return this.optionalPackageDeclaration;
304 //      }
305 //      
306 //      /**
307 //       * Sets or clears the package declaration of this compilation unit 
308 //       * node to the given package declaration node.
309 //       * 
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:
314 //       * <ul>
315 //       * <li>the node belongs to a different AST</li>
316 //       * <li>the node already has a parent</li>
317 //       * </ul>
318 //       */ 
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);
324 //      }
325 //
326 //      /**
327 //       * Returns the live list of nodes for the import declarations of this 
328 //       * compilation unit, in order of appearance.
329 //       * 
330 //       * @return the live list of import declaration nodes
331 //       *    (elementType: <code>ImportDeclaration</code>)
332 //       */ 
333 //      public List imports() {
334 //              return this.imports;
335 //      }
336 //      
337 //      /**
338 //       * Returns the live list of nodes for the top-level type declarations of this 
339 //       * compilation unit, in order of appearance.
340 //     * <p>
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>.
344 //     * </p>
345 //       * 
346 //       * @return the live list of top-level type declaration
347 //       *    nodes (elementType: <code>AbstractTypeDeclaration</code>)
348 //       */ 
349 //      public List types() {
350 //              return this.types;
351 //      }
352 //
353 //      /**
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.
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 <code>AnnotationTypeMemberDeclaration</code></li>
379 //     * <li>enum type - an <code>EnumDeclaration</code></li>
380 //     * <li>enum constant - an <code>EnumConstantDeclaration</code></li>
381 //       * </ul>
382 //       * </p>
383 //       * <p>
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.
389 //       * </p>
390 //       * 
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)
396 //       */
397 //      public ASTNode findDeclaringNode(IBinding binding) {
398 //              return this.ast.getBindingResolver().findDeclaringNode(binding);
399 //      }
400 //
401 //      /**
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.
407 //       * <p>
408 //       * The following table indicates the expected node type for the various
409 //       * different kinds of binding keys:
410 //       * <ul>
411 //       * <li></li>
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>
429 //       * </ul>
430 //       * </p>
431 //       * <p>
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.
435 //       * </p>
436 //       * 
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()
443 //       * @since 2.1
444 //       */
445 //      public ASTNode findDeclaringNode(String key) {
446 //              return this.ast.getBindingResolver().findDeclaringNode(key);
447 //      }
448 //      
449 //      /**
450 //       * Returns the internal comment mapper.
451 //       * 
452 //       * @return the comment mapper, or <code>null</code> if none.
453 //       * @since 3.0
454 //       */
455 //      DefaultCommentMapper getCommentMapper() {
456 //              return this.commentMapper;
457 //      }
458 //
459 //      /**
460 //       * Initializes the internal comment mapper with the given
461 //       * scanner.
462 //       * 
463 //       * @param scanner the scanner
464 //       * @since 3.0
465 //       */
466 //      void initCommentMapper(Scanner scanner) {
467 //              this.commentMapper = new DefaultCommentMapper(this.optionalCommentTable);
468 //              this.commentMapper.initialize(this, scanner);
469 //      }
470 //
471 //      /**
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.
476 //       * 
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)
481 //       * @since 3.0
482 //       */
483 //      public int getExtendedStartPosition(ASTNode node) {
484 //              if (this.commentMapper == null) {
485 //                      return -1;
486 //              } else {
487 //                      return this.commentMapper.getExtendedStartPosition(node);
488 //              }
489 //      }
490 //
491 //      /**
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.
496 //       * 
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)
501 //       * @since 3.0
502 //       */
503 //      public int getExtendedLength(ASTNode node) {
504 //              if (this.commentMapper == null) {
505 //                      return 0;
506 //              } else {
507 //                      return this.commentMapper.getExtendedLength(node);
508 //              }
509 //      }
510 //              
511 //      /**
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.
522 //       * 
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
529 //       * @see ASTParser
530 //       */
531 //      public int lineNumber(int position) {
532 //              int length = lineEndTable.length;
533 //              if (length == 0) {
534 //                      // no line number info
535 //                      return 1;
536 //              }
537 //              int low = 0;
538 //              if (position <= lineEndTable[low]) {
539 //                      // position illegal or before the first line delimiter
540 //                      return 1;
541 //              }
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
548 //                              return 1;
549 //                      } else {
550 //                              return length + 1;
551 //                      }
552 //              }
553 //              // assert lineEndTable[low]  < position <= lineEndTable[hi]
554 //              // && low == 0 && hi == length - 1 && low < hi
555 //              
556 //              // binary search line end table
557 //              while (true) {
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)
564 //                              return low + 2;
565 //                      }
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
572 //                              hi = mid;
573 //                      } else {
574 //                              // position > lineEndTable[mid]
575 //                              // assert lineEndTable[mid] < position <= lineEndTable[hi]
576 //                              // && 0 <= low < mid < hi <= length - 1
577 //                              low = mid;
578 //                      }
579 //                      // in both cases, invariant reachieved with reduced measure
580 //              }
581 //      }
582 //
583 //      /**
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.
587 //       * <p>
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.
592 //       * </p>
593 //       *
594 //       * @return the list of messages, possibly empty
595 //       * @see #getProblems()
596 //       * @see ASTParser
597 //       */
598 //      public Message[] getMessages() {
599 //              if (this.messages == null) {
600 //                      int problemLength = this.problems.length;
601 //                      if (problemLength == 0) {
602 //                              this.messages = EMPTY_MESSAGES;
603 //                      } else {
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);
610 //                              }
611 //                      }
612 //              }
613 //              return this.messages;
614 //      }
615 //
616 //      /**
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
620 //       * compiler.
621 //       * <p>
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.
624 //       * </p>
625 //       * 
626 //       * @return the list of detailed problem objects, possibly empty
627 //       * @see #getMessages()
628 //       * @see ASTParser
629 //       * @since 2.1
630 //       */
631 //      public IProblem[] getProblems() {
632 //              return this.problems;
633 //      }
634 //
635 //      /**
636 //       * Sets the array of problems reported by the compiler during the parsing or
637 //       * name resolution of this compilation unit.
638 //       * 
639 //       * @param problems the list of problems
640 //       */
641 //      void setProblems(IProblem[] problems) {
642 //              if (problems == null) {
643 //                      throw new IllegalArgumentException();
644 //              }
645 //              this.problems = problems;
646 //      }
647 //              
648 //      /**
649 //       * Returns a list of the comments encountered while parsing
650 //       * this compilation unit.
651 //       * <p>
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. 
663 //       * </p>
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
676 //       * unit.
677 //       * </p>
678 //       * <p>
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.
684 //       * </p>
685 //       * <p>
686 //       * Clients cannot modify the resulting list.
687 //       * </p>
688 //       * 
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
692 //       * @see ASTParser
693 //       * @since 3.0
694 //       */
695 //      public List getCommentList() {
696 //              return this.optionalCommentList;
697 //      }
698 //      
699 //      /**
700 //       * Sets the list of the comments encountered while parsing
701 //       * this compilation unit.
702 //       * 
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()
709 //       * @see ASTParser
710 //       * @since 3.0
711 //       */
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;
718 //              } else {
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();
724 //                              }
725 //                              int start = comment.getStartPosition();
726 //                              int length = comment.getLength();
727 //                              if (start < 0 || length < 0 || start < nextAvailablePosition) {
728 //                                      throw new IllegalArgumentException();
729 //                              }
730 //                              nextAvailablePosition = comment.getStartPosition() + comment.getLength();
731 //                      }
732 //                      this.optionalCommentTable = commentTable;
733 //                      List commentList = Arrays.asList(commentTable);
734 //                      // protect the list from further modification
735 //                      this.optionalCommentList = Collections.unmodifiableList(commentList);
736 //              }
737 //      }
738 //      
739 //      
740 //      /* (omit javadoc for this method)
741 //       * Method declared on ASTNode.
742 //       */
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$
752 //                      }
753 //              }
754 //              buffer.append("]"); //$NON-NLS-1$
755 //      }
756 //              
757 //      /* (omit javadoc for this method)
758 //       * Method declared on ASTNode.
759 //       */
760 //      int memSize() {
761 //              int size = BASE_NODE_SIZE + 8 * 4;
762 //              if (this.lineEndTable != null) {
763 //                      size += HEADERS + 4 * this.lineEndTable.length;
764 //              }
765 //              if (this.optionalCommentTable != null) {
766 //                      size += HEADERS + 4 * this.optionalCommentTable.length;
767 //              }
768 //              // ignore the space taken up by optionalCommentList
769 //              return size;
770 //      }
771 //      
772 //      /* (omit javadoc for this method)
773 //       * Method declared on ASTNode.
774 //       */
775 //      int treeSize() {
776 //              int size = memSize();
777 //              if (this.optionalPackageDeclaration != null) {
778 //                      size += getPackage().treeSize();
779 //              }
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();
788 //                              }
789 //                      }
790 //              }
791 //              return size;
792 //      }
793 //      
794 //      /**
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.
804 //       *
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
808 //       * @since 3.0
809 //       */
810 //      public void recordModifications() {
811 //              getAST().recordModifications(this);
812 //      }
813 //      
814 //      /**
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.
819 //       * <p>
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.
825 //       * </p>
826 //       * <p>
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
832 //       * changes.
833 //       * </p>
834 //       * 
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()
848 //       * @since 3.0
849 //       */
850 //      public TextEdit rewrite(IDocument document, Map options) {
851 //              return getAST().rewrite(document, options);
852 //      }
853 }
854