View | Details | Raw Unified | Return to bug 27134 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java (-3 / +7 lines)
Lines 544-550 Link Here
544
											currentPosition++;
544
											currentPosition++;
545
									} //jump over the \\
545
									} //jump over the \\
546
								}
546
								}
547
								recordComment(false);
547
								recordComment(TokenNameCOMMENT_LINE);
548
								if (startPosition <= cursorLocation && cursorLocation < currentPosition-1){
548
								if (startPosition <= cursorLocation && cursorLocation < currentPosition-1){
549
									throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_COMMENT);
549
									throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_COMMENT);
550
								}
550
								}
Lines 556-562 Link Here
556
									return TokenNameCOMMENT_LINE;
556
									return TokenNameCOMMENT_LINE;
557
								}
557
								}
558
							} catch (IndexOutOfBoundsException e) {
558
							} catch (IndexOutOfBoundsException e) {
559
								recordComment(false);
559
								recordComment(TokenNameCOMMENT_LINE);
560
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition-1);
560
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition-1);
561
								if (tokenizeComments) {
561
								if (tokenizeComments) {
562
									this.currentPosition--; // reset one character behind
562
									this.currentPosition--; // reset one character behind
Lines 650-663 Link Here
650
											currentPosition++;
650
											currentPosition++;
651
									} //jump over the \\
651
									} //jump over the \\
652
								}
652
								}
653
								recordComment(isJavadoc);
653
								int token = isJavadoc ? TokenNameCOMMENT_JAVADOC : TokenNameCOMMENT_BLOCK;
654
								recordComment(token);
654
								if (startPosition <= cursorLocation && cursorLocation < currentPosition-1){
655
								if (startPosition <= cursorLocation && cursorLocation < currentPosition-1){
655
									throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_COMMENT);
656
									throw new InvalidCursorLocation(InvalidCursorLocation.NO_COMPLETION_INSIDE_COMMENT);
656
								}
657
								}
657
								if (tokenizeComments) {
658
								if (tokenizeComments) {
659
									/*
658
									if (isJavadoc)
660
									if (isJavadoc)
659
										return TokenNameCOMMENT_JAVADOC;
661
										return TokenNameCOMMENT_JAVADOC;
660
									return TokenNameCOMMENT_BLOCK;
662
									return TokenNameCOMMENT_BLOCK;
663
									*/
664
									return token;
661
								}
665
								}
662
							} catch (IndexOutOfBoundsException e) {
666
							} catch (IndexOutOfBoundsException e) {
663
								throw new InvalidInputException(UNTERMINATED_COMMENT);
667
								throw new InvalidInputException(UNTERMINATED_COMMENT);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (+1 lines)
Lines 23-28 Link Here
23
	public ImportReference currentPackage;
23
	public ImportReference currentPackage;
24
	public ImportReference[] imports;
24
	public ImportReference[] imports;
25
	public TypeDeclaration[] types;
25
	public TypeDeclaration[] types;
26
	public int[][] comments;
26
27
27
	public boolean ignoreFurtherInvestigation = false;	// once pointless to investigate due to errors
28
	public boolean ignoreFurtherInvestigation = false;	// once pointless to investigate due to errors
28
	public boolean ignoreMethodBodies = false;
29
	public boolean ignoreMethodBodies = false;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java (-1 / +1 lines)
Lines 529-535 Link Here
529
					if (iToken == 0) {
529
					if (iToken == 0) {
530
						return null;
530
						return null;
531
					}
531
					}
532
					if ((iToken % 2) == 0) { // dots must be followed by an identifier
532
					if ((iToken % 2) == 0) { // cannot leave on a dot
533
						throw new InvalidInputException();
533
						throw new InvalidInputException();
534
					}
534
					}
535
					break nextToken;
535
					break nextToken;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-7 / +19 lines)
Lines 23-28 Link Here
23
 * The mirror implementation is using the backward compatible ITerminalSymbols constant 
23
 * The mirror implementation is using the backward compatible ITerminalSymbols constant 
24
 * definitions (stable with 2.0), whereas the internal implementation uses TerminalTokens 
24
 * definitions (stable with 2.0), whereas the internal implementation uses TerminalTokens 
25
 * which constant values reflect the latest parser generation state.
25
 * which constant values reflect the latest parser generation state.
26
 * @see org.eclipse.jdt.core.compiler.ITerminalSymbols
27
 * @see org.eclipse.jdt.internal.core.util.PublicScanner
26
 */
28
 */
27
public class Scanner implements TerminalTokens {
29
public class Scanner implements TerminalTokens {
28
30
Lines 395-401 Link Here
395
}
397
}
396
	
398
	
397
public final char[] getRawTokenSourceEnd() {
399
public final char[] getRawTokenSourceEnd() {
398
	int length = this.eofPosition - this.currentPosition;
400
	int length = this.eofPosition - this.currentPosition - 1;
399
	char[] sourceEnd = new char[length];
401
	char[] sourceEnd = new char[length];
400
	System.arraycopy(source, this.currentPosition, sourceEnd, 0, length);
402
	System.arraycopy(source, this.currentPosition, sourceEnd, 0, length);
401
	return sourceEnd;	
403
	return sourceEnd;	
Lines 1312-1318 Link Here
1312
										}
1314
										}
1313
									}
1315
									}
1314
							   	}
1316
							   	}
1315
								recordComment(false);
1317
								recordComment(TokenNameCOMMENT_LINE);
1316
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1318
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1317
								if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1319
								if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1318
									checkNonExternalizedString();
1320
									checkNonExternalizedString();
Lines 1331-1337 Link Here
1331
								}
1333
								}
1332
							} catch (IndexOutOfBoundsException e) {
1334
							} catch (IndexOutOfBoundsException e) {
1333
								currentPosition--;
1335
								currentPosition--;
1334
								recordComment(false);
1336
								recordComment(TokenNameCOMMENT_LINE);
1335
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1337
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1336
								if (tokenizeComments) {
1338
								if (tokenizeComments) {
1337
									return TokenNameCOMMENT_LINE;
1339
									return TokenNameCOMMENT_LINE;
Lines 1386-1391 Link Here
1386
									if (source[currentPosition] == '\\')
1388
									if (source[currentPosition] == '\\')
1387
										currentPosition++; //jump over the \\
1389
										currentPosition++; //jump over the \\
1388
								}
1390
								}
1391
								
1392
								// In case of /**/ set back to non-javadoc comment
1393
								if (currentCharacter == '/') {
1394
									isJavadoc = false;
1395
								}
1396
								
1389
								//loop until end of comment */
1397
								//loop until end of comment */
1390
								while ((currentCharacter != '/') || (!star)) {
1398
								while ((currentCharacter != '/') || (!star)) {
1391
									if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1399
									if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
Lines 1414-1425 Link Here
1414
											currentPosition++;
1422
											currentPosition++;
1415
									} //jump over the \\
1423
									} //jump over the \\
1416
								}
1424
								}
1417
								recordComment(isJavadoc);
1425
								int token = isJavadoc ? TokenNameCOMMENT_JAVADOC : TokenNameCOMMENT_BLOCK;
1426
								recordComment(token);
1418
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1427
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1419
								if (tokenizeComments) {
1428
								if (tokenizeComments) {
1429
									/*
1420
									if (isJavadoc)
1430
									if (isJavadoc)
1421
										return TokenNameCOMMENT_JAVADOC;
1431
										return TokenNameCOMMENT_JAVADOC;
1422
									return TokenNameCOMMENT_BLOCK;
1432
									return TokenNameCOMMENT_BLOCK;
1433
									*/
1434
									return token;
1423
								}
1435
								}
1424
							} catch (IndexOutOfBoundsException e) {
1436
							} catch (IndexOutOfBoundsException e) {
1425
								throw new InvalidInputException(UNTERMINATED_COMMENT);
1437
								throw new InvalidInputException(UNTERMINATED_COMMENT);
Lines 2217-2233 Link Here
2217
		}
2229
		}
2218
	}
2230
	}
2219
}
2231
}
2220
public final void recordComment(boolean isJavadoc) {
2232
public void recordComment(int token) {
2221
2233
2222
	// a new comment is recorded
2234
	// a new comment is recorded
2223
	try {
2235
	try {
2224
		this.commentStops[++this.commentPtr] = isJavadoc ? this.currentPosition : -this.currentPosition;
2236
		this.commentStops[++this.commentPtr] = (token==TokenNameCOMMENT_JAVADOC) ? this.currentPosition : -this.currentPosition;
2225
	} catch (IndexOutOfBoundsException e) {
2237
	} catch (IndexOutOfBoundsException e) {
2226
		int oldStackLength = this.commentStops.length;
2238
		int oldStackLength = this.commentStops.length;
2227
		int[] oldStack = this.commentStops;
2239
		int[] oldStack = this.commentStops;
2228
		this.commentStops = new int[oldStackLength + 30];
2240
		this.commentStops = new int[oldStackLength + 30];
2229
		System.arraycopy(oldStack, 0, this.commentStops, 0, oldStackLength);
2241
		System.arraycopy(oldStack, 0, this.commentStops, 0, oldStackLength);
2230
		this.commentStops[this.commentPtr] = isJavadoc ? this.currentPosition : -this.currentPosition;
2242
		this.commentStops[this.commentPtr] = (token==TokenNameCOMMENT_JAVADOC) ? this.currentPosition : -this.currentPosition;
2231
		//grows the positions buffers too
2243
		//grows the positions buffers too
2232
		int[] old = this.commentStarts;
2244
		int[] old = this.commentStarts;
2233
		this.commentStarts = new int[oldStackLength + 30];
2245
		this.commentStarts = new int[oldStackLength + 30];
(-)dom/org/eclipse/jdt/core/dom/AST.java (-84 / +974 lines)
Lines 14-33 Link Here
14
import java.util.Map;
14
import java.util.Map;
15
15
16
import org.eclipse.jdt.core.*;
16
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.IJavaProject;
20
import org.eclipse.jdt.core.JavaCore;
21
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.core.compiler.CharOperation;
23
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
18
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
24
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
19
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
25
import org.eclipse.jdt.internal.compiler.parser.Scanner;
26
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
20
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
27
import org.eclipse.jdt.internal.core.*;
21
import org.eclipse.jdt.internal.core.*;
28
import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
29
import org.eclipse.jdt.internal.core.JavaModelManager;
30
import org.eclipse.jdt.internal.core.NameLookup;
31
22
32
/**
23
/**
33
 * Umbrella owner and abstract syntax tree node factory.
24
 * Umbrella owner and abstract syntax tree node factory.
Lines 69-75 Link Here
69
 * subclassed.
60
 * subclassed.
70
 * </p>
61
 * </p>
71
 * 
62
 * 
72
 * @see #parseCompilationUnit(ICompilationUnit, boolean)
63
 * @see #parseCompilationUnit(char[]) and other similar methods
73
 * @see ASTNode
64
 * @see ASTNode
74
 * @since 2.0
65
 * @since 2.0
75
 */
66
 */
Lines 85-93 Link Here
85
	 * Java Scanner used to validate preconditions for the creation of specific nodes
76
	 * Java Scanner used to validate preconditions for the creation of specific nodes
86
	 * like CharacterLiteral, NumberLiteral, StringLiteral or SimpleName.
77
	 * like CharacterLiteral, NumberLiteral, StringLiteral or SimpleName.
87
	 */
78
	 */
88
	Scanner scanner;
79
	DOMScanner scanner;
89
80
90
	/**
81
	/**
82
	 * Flags to set options while DOM parsing.
83
	 */
84
	public final static int ResolveBindings = 0x00000001;
85
	
86
	/**
87
	 * 
88
	 */
89
	public final static int InsideComments  = 0x00000002;
90
	
91
	/**
91
	 * Creates a new, empty abstract syntax tree using default options.
92
	 * Creates a new, empty abstract syntax tree using default options.
92
	 * 
93
	 * 
93
	 * @see JavaCore#getDefaultOptions()
94
	 * @see JavaCore#getDefaultOptions()
Lines 116-122 Link Here
116
	 * @see JavaCore#getDefaultOptions()
117
	 * @see JavaCore#getDefaultOptions()
117
	 */
118
	 */
118
	public AST(Map options) {
119
	public AST(Map options) {
119
		this.scanner = new Scanner(
120
		this.scanner = new DOMScanner(
120
			true /*comment*/, 
121
			true /*comment*/, 
121
			true /*whitespace*/, 
122
			true /*whitespace*/, 
122
			false /*nls*/, 
123
			false /*nls*/, 
Lines 151-157 Link Here
151
	 *    this AST
152
	 *    this AST
152
	 */
153
	 */
153
	public long modificationCount() {
154
	public long modificationCount() {
154
		return modCount;
155
		return this.modCount;
155
	}
156
	}
156
157
157
	/**
158
	/**
Lines 181-187 Link Here
181
	 */
182
	 */
182
	void modifying() {
183
	void modifying() {
183
		// increase the modification count
184
		// increase the modification count
184
		modCount++;	
185
		this.modCount++;	
185
	}
186
	}
186
187
187
	/**
188
	/**
Lines 235-250 Link Here
235
	 * @return the compilation unit node
236
	 * @return the compilation unit node
236
	 * @exception IllegalArgumentException if the given Java element does not 
237
	 * @exception IllegalArgumentException if the given Java element does not 
237
	 * exist or if its source string cannot be obtained
238
	 * exist or if its source string cannot be obtained
239
	 * @deprecated Use #parseCompilationUnit(CompilationUnit, int)
240
	 */
241
	public static CompilationUnit parseCompilationUnit(
242
		ICompilationUnit unit,
243
		boolean resolveBindings) {
244
245
		return parseCompilationUnit(unit, resolveBindings?ResolveBindings:0);
246
	}
247
248
	/**
249
	 * Parses the source string of the given Java model compilation unit element
250
	 * and creates and returns a corresponding abstract syntax tree. The source 
251
	 * string is obtained from the Java model element using
252
	 * <code>ICompilationUnit.getSource()</code>.
253
	 * <p>
254
	 * The returned compilation unit node is the root node of a new AST.
255
	 * Each node in the subtree carries source range(s) information relating back
256
	 * to positions in the source string (the source string is not remembered
257
	 * with the AST).
258
	 * The source range usually begins at the first character of the first token 
259
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
260
	 * included. The source range usually extends through the last character of
261
	 * the last token corresponding to the node; trailing whitespace and
262
	 * comments are <b>not</b> included. There are a handful of exceptions
263
	 * (including compilation units and the various body declarations); the
264
	 * specification for these node type spells out the details.
265
	 * Source ranges nest properly: the source range for a child is always
266
	 * within the source range of its parent, and the source ranges of sibling
267
	 * nodes never overlap.
268
	 * If a syntax error is detected while parsing, the relevant node(s) of the
269
	 * tree will be flagged as <code>MALFORMED</code>.
270
	 * </p>
271
	 * <p>
272
	 * Several options are available while parsing the compilation unit:
273
	 *<ul>
274
	 *<li>- <code>ResolveBindings</code>
275
	 * 		When this flag is set, the various names and types appearing in
276
	 * 		the compilation unit can be resolved to "bindings" by calling
277
	 * 		the <code>resolveBinding</code> methods. These bindings draw
278
	 * 		connections between the different parts of a program, and generally
279
	 * 		afford a more powerful vantage point for clients who wish to
280
	 * 		analyze a program's structure more deeply. These bindings come
281
	 * 		at a considerable cost in both time and space, however, and should
282
	 * 		not be requested frivolously. The additional space is not reclaimed
283
	 * 		until the AST, all its nodes, and all its bindings become garbage.
284
	 * 		So it is very important to not retain any of these objects longer
285
	 * 		than absolutely necessary. Bindings are resolved at the time the
286
	 * 		AST is created. Subsequent modifications to the AST do not affect
287
	 * 		the bindings returned by <code>resolveBinding</code> methods in
288
	 * 		any way; these methods return the same binding as before the AST
289
	 * 		was modified (including modifications that rearrange subtrees by
290
	 * 		reparenting nodes).
291
	 * 		When this flag is not set, the analysis does not go beyond parsing
292
	 * 		and building the tree, and all <code>resolveBinding</code> methods
293
	 * 		return <code>null</code> from the  outset.
294
	 * </li>
295
	 * <li>- <code>InsideComments</code>
296
	 * 		When this flag is set, all comments of the compilation unit are stored
297
	 * 		and parsed to identify possible Javadoc tags.
298
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
299
	 * 		There are three different kind of comments: line, block and javadoc.
300
	 * 		Javadoc comments are those which were already defined since version 2.0,
301
	 * 		but they are now structured and not only a flat text.
302
	 * 		@see Javadoc for more details on this AST node structure
303
	 * </li>
304
	 * </ul>
305
	 * Use OR operator to set several options simultaneously. For example, to set
306
	 * both bindings resolution and comments, set options parameter to:
307
	 * <code>ResolveBindings | InsideComments</code>
308
	 * </p>
309
	 * 
310
	 * @param unit the Java model compilation unit whose source code is to be parsed
311
	 * @param options an integer which sets parse options. 
312
	 * @return the compilation unit node
313
	 * @exception IllegalArgumentException if the given Java element does not 
314
	 * exist or if its source string cannot be obtained
238
	 * @see ASTNode#getFlags()
315
	 * @see ASTNode#getFlags()
239
	 * @see ASTNode#MALFORMED
316
	 * @see ASTNode#MALFORMED
240
	 * @see ASTNode#getStartPosition()
317
	 * @see ASTNode#getStartPosition()
241
	 * @see ASTNode#getLength()
318
	 * @see ASTNode#getLength()
319
	 * @since 3.0
242
	 */
320
	 */
243
	public static CompilationUnit parseCompilationUnit(
321
	public static CompilationUnit parseCompilationUnit(ICompilationUnit unit, int options) {
244
		ICompilationUnit unit,
245
		boolean resolveBindings) {
246
322
247
		return parseCompilationUnit(unit, resolveBindings, DefaultWorkingCopyOwner.PRIMARY);
323
		return parseCompilationUnit(unit, options, DefaultWorkingCopyOwner.PRIMARY);
248
	}
324
	}
249
	
325
	
250
	/**
326
	/**
Lines 311-321 Link Here
311
	 * @see ASTNode#getStartPosition()
387
	 * @see ASTNode#getStartPosition()
312
	 * @see ASTNode#getLength()
388
	 * @see ASTNode#getLength()
313
	 * @see WorkingCopyOwner
389
	 * @see WorkingCopyOwner
390
	 * @deprecated Use #parseCompilationUnit(CompilationUnit, int, WorkingCopyOwner)
391
	 * @since 3.0
392
	 * TODO (frederic) remove for 3.0
393
	 */
394
	public static CompilationUnit parseCompilationUnit(
395
			ICompilationUnit unit,
396
			boolean resolveBindings,
397
			WorkingCopyOwner owner) {
398
		return parseCompilationUnit(unit, resolveBindings?ResolveBindings:0, owner);
399
	}
400
401
	/**
402
	 * Parses the source string of the given Java model compilation unit element
403
	 * and creates and returns a corresponding abstract syntax tree. The source 
404
	 * string is obtained from the Java model element using
405
	 * <code>ICompilationUnit.getSource()</code>.
406
	 * <p>
407
	 * The returned compilation unit node is the root node of a new AST.
408
	 * Each node in the subtree carries source range(s) information relating back
409
	 * to positions in the source string (the source string is not remembered
410
	 * with the AST).
411
	 * The source range usually begins at the first character of the first token 
412
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
413
	 * included. The source range usually extends through the last character of
414
	 * the last token corresponding to the node; trailing whitespace and
415
	 * comments are <b>not</b> included. There are a handful of exceptions
416
	 * (including compilation units and the various body declarations); the
417
	 * specification for these node type spells out the details.
418
	 * Source ranges nest properly: the source range for a child is always
419
	 * within the source range of its parent, and the source ranges of sibling
420
	 * nodes never overlap.
421
	 * If a syntax error is detected while parsing, the relevant node(s) of the
422
	 * tree will be flagged as <code>MALFORMED</code>.
423
	 * </p>
424
	 * <p>
425
	 * Several options are available while parsing the compilation unit:
426
	 *<ul>
427
	 *<li>- <code>ResolveBindings</code>
428
	 * 		When this flag is set, the various names and types appearing in
429
	 * 		the compilation unit can be resolved to "bindings" by calling
430
	 * 		the <code>resolveBinding</code> methods. These bindings draw
431
	 * 		connections between the different parts of a program, and generally
432
	 * 		afford a more powerful vantage point for clients who wish to
433
	 * 		analyze a program's structure more deeply. These bindings come
434
	 * 		at a considerable cost in both time and space, however, and should
435
	 * 		not be requested frivolously. The additional space is not reclaimed
436
	 * 		until the AST, all its nodes, and all its bindings become garbage.
437
	 * 		So it is very important to not retain any of these objects longer
438
	 * 		than absolutely necessary. Bindings are resolved at the time the
439
	 * 		AST is created. Subsequent modifications to the AST do not affect
440
	 * 		the bindings returned by <code>resolveBinding</code> methods in
441
	 * 		any way; these methods return the same binding as before the AST
442
	 * 		was modified (including modifications that rearrange subtrees by
443
	 * 		reparenting nodes).
444
	 * 		When this flag is not set, the analysis does not go beyond parsing
445
	 * 		and building the tree, and all <code>resolveBinding</code> methods
446
	 * 		return <code>null</code> from the  outset.
447
	 * </li>
448
	 * <li>- <code>InsideComments</code>
449
	 * 		When this flag is set, all comments of the compilation unit are stored
450
	 * 		and parsed to identify possible Javadoc tags.
451
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
452
	 * 		There are three different kind of comments: line, block and javadoc.
453
	 * 		Javadoc comments are those which were already defined since version 2.0,
454
	 * 		but they are now structured and not only a flat text.
455
	 * 		@see Javadoc for more details on this AST node structure
456
	 * </li>
457
	 * </ul>
458
	 * Use OR operator to set several options simultaneously. For example, to set
459
	 * both bindings resolution and comments, set options parameter to:
460
	 * <code>ResolveBindings | InsideComments</code>
461
	 * </p>
462
	 * <p>
463
	 * When bindings are created, instead of considering compilation units on disk only
464
	 * one can supply a <code>WorkingCopyOwner</code>. Working copies owned 
465
	 * by this owner take precedence over the underlying compilation units when looking
466
	 * up names and drawing the connections.
467
	 * </p>
468
	 * 
469
	 * @param unit the Java model compilation unit whose source code is to be parsed
470
	 * @param options an integer which sets parse options. 
471
	 * @param owner the owner of working copies that take precedence over underlying 
472
	 *   compilation units
473
	 * @return the compilation unit node
474
	 * @exception IllegalArgumentException if the given Java element does not 
475
	 * exist or if its source string cannot be obtained
476
	 * @see ASTNode#getFlags()
477
	 * @see ASTNode#MALFORMED
478
	 * @see ASTNode#getStartPosition()
479
	 * @see ASTNode#getLength()
480
	 * @see WorkingCopyOwner
314
	 * @since 3.0
481
	 * @since 3.0
315
	 */
482
	 */
316
	public static CompilationUnit parseCompilationUnit(
483
	public static CompilationUnit parseCompilationUnit(
317
		ICompilationUnit unit,
484
		ICompilationUnit unit,
318
		boolean resolveBindings,
485
		int options,
319
		WorkingCopyOwner owner) {
486
		WorkingCopyOwner owner) {
320
				
487
				
321
		if (unit == null) {
488
		if (unit == null) {
Lines 333-339 Link Here
333
			throw new IllegalArgumentException();
500
			throw new IllegalArgumentException();
334
		}
501
		}
335
502
336
		if (resolveBindings) {
503
		if ((options & ResolveBindings) == ResolveBindings) {
337
			NameLookup lookup = null;
504
			NameLookup lookup = null;
338
			CompilationUnitDeclaration compilationUnitDeclaration = null;
505
			CompilationUnitDeclaration compilationUnitDeclaration = null;
339
			try {
506
			try {
Lines 345-351 Link Here
345
				
512
				
346
				// parse and resolve
513
				// parse and resolve
347
				compilationUnitDeclaration = CompilationUnitResolver.resolve(unit, false/*don't cleanup*/, source);
514
				compilationUnitDeclaration = CompilationUnitResolver.resolve(unit, false/*don't cleanup*/, source);
348
				ASTConverter converter = new ASTConverter(unit.getJavaProject().getOptions(true), true);
515
				ASTConverter converter = new ASTConverter(unit.getJavaProject().getOptions(true), options);
349
				AST ast = new AST();
516
				AST ast = new AST();
350
				BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
517
				BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
351
				ast.setBindingResolver(resolver);
518
				ast.setBindingResolver(resolver);
Lines 370-376 Link Here
370
				}
537
				}
371
			}
538
			}
372
		} else {
539
		} else {
373
			return parseCompilationUnit(source);
540
			return parseCompilationUnit(source, options);
374
		}
541
		}
375
	}
542
	}
376
543
Lines 431-444 Link Here
431
	 * @see ASTNode#getStartPosition()
598
	 * @see ASTNode#getStartPosition()
432
	 * @see ASTNode#getLength()
599
	 * @see ASTNode#getLength()
433
	 * @since 2.1
600
	 * @since 2.1
601
	 * @deprecated Use #parseCompilationUnit(IClassFile, int)
434
	 */
602
	 */
435
	public static CompilationUnit parseCompilationUnit(
603
	public static CompilationUnit parseCompilationUnit(
436
		IClassFile classFile,
604
		IClassFile classFile,
437
		boolean resolveBindings) {
605
		boolean resolveBindings) {
438
			
606
			
439
		return parseCompilationUnit(classFile, resolveBindings, DefaultWorkingCopyOwner.PRIMARY);
607
		return parseCompilationUnit(classFile, resolveBindings?ResolveBindings:0);
440
	}
608
	}
441
	
609
610
	/**
611
	 * Parses the source string corresponding to the given Java class file
612
	 * element and creates and returns a corresponding abstract syntax tree.
613
	 * The source string is obtained from the Java model element using
614
	 * <code>IClassFile.getSource()</code>, and is only available for a class
615
	 * files with attached source.
616
	 * <p>
617
	 * The returned compilation unit node is the root node of a new AST.
618
	 * Each node in the subtree carries source range(s) information relating back
619
	 * to positions in the source string (the source string is not remembered
620
	 * with the AST).
621
	 * The source range usually begins at the first character of the first token 
622
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
623
	 * included. The source range usually extends through the last character of
624
	 * the last token corresponding to the node; trailing whitespace and
625
	 * comments are <b>not</b> included. There are a handful of exceptions
626
	 * (including compilation units and the various body declarations); the
627
	 * specification for these node type spells out the details.
628
	 * Source ranges nest properly: the source range for a child is always
629
	 * within the source range of its parent, and the source ranges of sibling
630
	 * nodes never overlap.
631
	 * If a syntax error is detected while parsing, the relevant node(s) of the
632
	 * tree will be flagged as <code>MALFORMED</code>.
633
	 * </p>
634
	 * <p>
635
	 * Several options are available while parsing the compilation unit:
636
	 *<ul>
637
	 *<li>- <code>ResolveBindings</code>
638
	 * 		When this flag is set, the various names and types appearing in
639
	 * 		the compilation unit can be resolved to "bindings" by calling
640
	 * 		the <code>resolveBinding</code> methods. These bindings draw
641
	 * 		connections between the different parts of a program, and generally
642
	 * 		afford a more powerful vantage point for clients who wish to
643
	 * 		analyze a program's structure more deeply. These bindings come
644
	 * 		at a considerable cost in both time and space, however, and should
645
	 * 		not be requested frivolously. The additional space is not reclaimed
646
	 * 		until the AST, all its nodes, and all its bindings become garbage.
647
	 * 		So it is very important to not retain any of these objects longer
648
	 * 		than absolutely necessary. Bindings are resolved at the time the
649
	 * 		AST is created. Subsequent modifications to the AST do not affect
650
	 * 		the bindings returned by <code>resolveBinding</code> methods in
651
	 * 		any way; these methods return the same binding as before the AST
652
	 * 		was modified (including modifications that rearrange subtrees by
653
	 * 		reparenting nodes).
654
	 * 		When this flag is not set, the analysis does not go beyond parsing
655
	 * 		and building the tree, and all <code>resolveBinding</code> methods
656
	 * 		return <code>null</code> from the  outset.
657
	 * </li>
658
	 * <li>- <code>InsideComments</code>
659
	 * 		When this flag is set, all comments of the compilation unit are stored
660
	 * 		and parsed to identify possible Javadoc tags.
661
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
662
	 * 		There are three different kind of comments: line, block and javadoc.
663
	 * 		Javadoc comments are those which were already defined since version 2.0,
664
	 * 		but they are now structured and not only a flat text.
665
	 * 		@see Javadoc for more details on this AST node structure
666
	 * </li>
667
	 * </ul>
668
	 * Use OR operator to set several options simultaneously. For example, to set
669
	 * both bindings resolution and comments, set options parameter to:
670
	 * <code>ResolveBindings | InsideComments</code>
671
	 * </p>
672
	 * 
673
	 * @param classFile the Java model compilation unit whose source code is to be parsed
674
	 * @param options an integer which sets parse options. 
675
	 * @return the compilation unit node
676
	 * @exception IllegalArgumentException if the given Java element does not 
677
	 * exist or if its source string cannot be obtained
678
	 * @see ASTNode#getFlags()
679
	 * @see ASTNode#MALFORMED
680
	 * @see ASTNode#getStartPosition()
681
	 * @see ASTNode#getLength()
682
	 * @since 3.0
683
	 */
684
	public static CompilationUnit parseCompilationUnit(IClassFile classFile, int options) {
685
		
686
		return parseCompilationUnit(classFile, options, DefaultWorkingCopyOwner.PRIMARY);
687
	}
688
442
	/**
689
	/**
443
	 * Parses the source string corresponding to the given Java class file
690
	 * Parses the source string corresponding to the given Java class file
444
	 * element and creates and returns a corresponding abstract syntax tree.
691
	 * element and creates and returns a corresponding abstract syntax tree.
Lines 505-514 Link Here
505
	 * @see ASTNode#getLength()
752
	 * @see ASTNode#getLength()
506
	 * @see WorkingCopyOwner
753
	 * @see WorkingCopyOwner
507
	 * @since 3.0
754
	 * @since 3.0
755
	 * @deprecated Use #parseCompilationUnit(IClassFile, int, WorkingCopyOwner)
756
	 * TODO (frederic) remove for 3.0
757
	 */
758
	public static CompilationUnit parseCompilationUnit(
759
			IClassFile classFile,
760
			boolean resolveBindings,
761
			WorkingCopyOwner owner) {
762
		return parseCompilationUnit(classFile, resolveBindings?ResolveBindings:0, owner);
763
	}
764
765
	/**
766
	 * Parses the source string corresponding to the given Java class file
767
	 * element and creates and returns a corresponding abstract syntax tree.
768
	 * The source string is obtained from the Java model element using
769
	 * <code>IClassFile.getSource()</code>, and is only available for a class
770
	 * files with attached source.
771
	 * <p>
772
	 * The returned compilation unit node is the root node of a new AST.
773
	 * Each node in the subtree carries source range(s) information relating back
774
	 * to positions in the source string (the source string is not remembered
775
	 * with the AST).
776
	 * The source range usually begins at the first character of the first token 
777
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
778
	 * included. The source range usually extends through the last character of
779
	 * the last token corresponding to the node; trailing whitespace and
780
	 * comments are <b>not</b> included. There are a handful of exceptions
781
	 * (including compilation units and the various body declarations); the
782
	 * specification for these node type spells out the details.
783
	 * Source ranges nest properly: the source range for a child is always
784
	 * within the source range of its parent, and the source ranges of sibling
785
	 * nodes never overlap.
786
	 * If a syntax error is detected while parsing, the relevant node(s) of the
787
	 * tree will be flagged as <code>MALFORMED</code>.
788
	 * </p>
789
	 * <p>
790
	 * Several options are available while parsing the compilation unit:
791
	 *<ul>
792
	 *<li>- <code>ResolveBindings</code>
793
	 * 		When this flag is set, the various names and types appearing in
794
	 * 		the compilation unit can be resolved to "bindings" by calling
795
	 * 		the <code>resolveBinding</code> methods. These bindings draw
796
	 * 		connections between the different parts of a program, and generally
797
	 * 		afford a more powerful vantage point for clients who wish to
798
	 * 		analyze a program's structure more deeply. These bindings come
799
	 * 		at a considerable cost in both time and space, however, and should
800
	 * 		not be requested frivolously. The additional space is not reclaimed
801
	 * 		until the AST, all its nodes, and all its bindings become garbage.
802
	 * 		So it is very important to not retain any of these objects longer
803
	 * 		than absolutely necessary. Bindings are resolved at the time the
804
	 * 		AST is created. Subsequent modifications to the AST do not affect
805
	 * 		the bindings returned by <code>resolveBinding</code> methods in
806
	 * 		any way; these methods return the same binding as before the AST
807
	 * 		was modified (including modifications that rearrange subtrees by
808
	 * 		reparenting nodes).
809
	 * 		When this flag is not set, the analysis does not go beyond parsing
810
	 * 		and building the tree, and all <code>resolveBinding</code> methods
811
	 * 		return <code>null</code> from the  outset.
812
	 * </li>
813
	 * <li>- <code>InsideComments</code>
814
	 * 		When this flag is set, all comments of the compilation unit are stored
815
	 * 		and parsed to identify possible Javadoc tags.
816
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
817
	 * 		There are three different kind of comments: line, block and javadoc.
818
	 * 		Javadoc comments are those which were already defined since version 2.0,
819
	 * 		but they are now structured and not only a flat text.
820
	 * 		@see Javadoc for more details on this AST node structure
821
	 * </li>
822
	 * </ul>
823
	 * Use OR operator to set several options simultaneously. For example, to set
824
	 * both bindings resolution and comments, set options parameter to:
825
	 * <code>ResolveBindings | InsideComments</code>
826
	 * </p>
827
	 * <p>
828
	 * When bindings are created, instead of considering compilation units on disk only
829
	 * one can supply a <code>WorkingCopyOwner</code>. Working copies owned 
830
	 * by this owner take precedence over the underlying compilation units when looking
831
	 * up names and drawing the connections.
832
	 * </p>
833
	 * 
834
	 * @param classFile the Java model compilation unit whose source code is to be parsed
835
	 * @param options an integer which sets parse options. 
836
	 * @param owner the owner of working copies that take precedence over underlying 
837
	 *   compilation units
838
	 * @return the compilation unit node
839
	 * @exception IllegalArgumentException if the given Java element does not 
840
	 * exist or if its source string cannot be obtained
841
	 * @see ASTNode#getFlags()
842
	 * @see ASTNode#MALFORMED
843
	 * @see ASTNode#getStartPosition()
844
	 * @see ASTNode#getLength()
845
	 * @see WorkingCopyOwner
846
	 * @since 3.0
508
	 */
847
	 */
509
	public static CompilationUnit parseCompilationUnit(
848
	public static CompilationUnit parseCompilationUnit(
510
		IClassFile classFile,
849
		IClassFile classFile,
511
		boolean resolveBindings,
850
		int options,
512
		WorkingCopyOwner owner) {
851
		WorkingCopyOwner owner) {
513
			
852
			
514
		if (classFile == null) {
853
		if (classFile == null) {
Lines 528-534 Link Here
528
			throw new IllegalArgumentException();
867
			throw new IllegalArgumentException();
529
		}
868
		}
530
		source = sourceString.toCharArray();
869
		source = sourceString.toCharArray();
531
		if (!resolveBindings) {
870
		if ((options & ResolveBindings) == 0) {
532
			return AST.parseCompilationUnit(source);
871
			return AST.parseCompilationUnit(source);
533
		}
872
		}
534
		StringBuffer buffer = new StringBuffer(SuffixConstants.SUFFIX_STRING_java);
873
		StringBuffer buffer = new StringBuffer(SuffixConstants.SUFFIX_STRING_java);
Lines 553-584 Link Here
553
					buffer.toString(),
892
					buffer.toString(),
554
					project,
893
					project,
555
					false/*don't cleanup*/);
894
					false/*don't cleanup*/);
556
			ASTConverter converter = new ASTConverter(project.getOptions(true), true);
895
			ASTConverter converter = new ASTConverter(project.getOptions(true), options);
557
			AST ast = new AST();
896
			AST ast = new AST();
558
			BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
897
			BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
559
			ast.setBindingResolver(resolver);
898
			ast.setBindingResolver(resolver);
560
			converter.setAST(ast);
899
			converter.setAST(ast);
561
		
900
		
562
			CompilationUnit cu = converter.convert(compilationUnitDeclaration, source);
901
			CompilationUnit cu = converter.convert(compilationUnitDeclaration, source);
563
			cu.setLineEndTable(compilationUnitDeclaration.compilationResult.lineSeparatorPositions);
902
			cu.setLineEndTable(compilationUnitDeclaration.compilationResult.lineSeparatorPositions);
564
			resolver.storeModificationCount(ast.modificationCount());
903
			resolver.storeModificationCount(ast.modificationCount());
565
			return cu;
904
			return cu;
566
		} catch(JavaModelException e) {
905
		} catch(JavaModelException e) {
567
			/* if a JavaModelException is thrown trying to retrieve the name environment
906
			/* if a JavaModelException is thrown trying to retrieve the name environment
568
			 * then we simply do a parsing without creating bindings.
907
			 * then we simply do a parsing without creating bindings.
569
			 * Therefore all binding resolution will return null.
908
			 * Therefore all binding resolution will return null.
570
			 */
909
			 */
571
			return parseCompilationUnit(source);			
910
			return parseCompilationUnit(source);			
572
		} finally {
911
		} finally {
573
			if (compilationUnitDeclaration != null) {
912
			if (compilationUnitDeclaration != null) {
574
				compilationUnitDeclaration.cleanUp();
913
				compilationUnitDeclaration.cleanUp();
575
			}
914
			}
576
			if (lookup != null) {
915
			if (lookup != null) {
577
				lookup.setUnitsToLookInside(null);
916
				lookup.setUnitsToLookInside(null);
578
			}
917
			}
579
		}
918
		}
919
	}
920
	
921
	/**
922
	 * Parses the given string as the hypothetical contents of the named
923
	 * compilation unit and creates and returns a corresponding abstract syntax tree.
924
	 * <p>
925
	 * The returned compilation unit node is the root node of a new AST.
926
	 * Each node in the subtree carries source range(s) information relating back
927
	 * to positions in the given source string (the given source string itself
928
	 * is not remembered with the AST).
929
	 * The source range usually begins at the first character of the first token 
930
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
931
	 * included. The source range usually extends through the last character of
932
	 * the last token corresponding to the node; trailing whitespace and
933
	 * comments are <b>not</b> included. There are a handful of exceptions
934
	 * (including compilation units and the various body declarations); the
935
	 * specification for these node type spells out the details.
936
	 * Source ranges nest properly: the source range for a child is always
937
	 * within the source range of its parent, and the source ranges of sibling
938
	 * nodes never overlap.
939
	 * If a syntax error is detected while parsing, the relevant node(s) of the
940
	 * tree will be flagged as <code>MALFORMED</code>.
941
	 * </p>
942
	 * <p>
943
	 * If the given project is not <code>null</code>, the various names
944
	 * and types appearing in the compilation unit can be resolved to "bindings"
945
	 * by calling the <code>resolveBinding</code> methods. These bindings 
946
	 * draw connections between the different parts of a program, and 
947
	 * generally afford a more powerful vantage point for clients who wish to
948
	 * analyze a program's structure more deeply. These bindings come at a 
949
	 * considerable cost in both time and space, however, and should not be
950
	 * requested frivolously. The additional space is not reclaimed until the 
951
	 * AST, all its nodes, and all its bindings become garbage. So it is very
952
	 * important to not retain any of these objects longer than absolutely
953
	 * necessary. Bindings are resolved at the time the AST is created. Subsequent
954
	 * modifications to the AST do not affect the bindings returned by
955
	 * <code>resolveBinding</code> methods in any way; these methods return the
956
	 * same binding as before the AST was modified (including modifications
957
	 * that rearrange subtrees by reparenting nodes).
958
	 * If the given project is <code>null</code>, the analysis 
959
	 * does not go beyond parsing and building the tree, and all 
960
	 * <code>resolveBinding</code> methods return <code>null</code> from the 
961
	 * outset.
962
	 * </p>
963
	 * <p>
964
	 * The name of the compilation unit must be supplied for resolving bindings.
965
	 * This name should include the ".java" suffix and match the name of the main
966
	 * (public) class or interface declared in the source. For example, if the source
967
	 * declares a public class named "Foo", the name of the compilation should be
968
	 * "Foo.java". For the purposes of resolving bindings, types declared in the
969
	 * source string hide types by the same name available through the classpath
970
	 * of the given project.
971
	 * </p>
972
	 * 
973
	 * @param source the string to be parsed as a Java compilation unit
974
	 * @param unitName the name of the compilation unit that would contain the source
975
	 *    string, or <code>null</code> if <code>javaProject</code> is also <code>null</code>
976
	 * @param project the Java project used to resolve names, or 
977
	 *    <code>null</code> if bindings are not resolved
978
	 * @return the compilation unit node
979
	 * @see ASTNode#getFlags()
980
	 * @see ASTNode#MALFORMED
981
	 * @see ASTNode#getStartPosition()
982
	 * @see ASTNode#getLength()
983
	 * @deprecated Use #parseCompilationUnit(char(], int, String, JavaProject)
984
	 */
985
	public static CompilationUnit parseCompilationUnit(
986
			char[] source,
987
			String unitName,
988
			IJavaProject project) {
989
		
990
		return parseCompilationUnit(source, unitName, project, DefaultWorkingCopyOwner.PRIMARY);
991
	}
992
	
993
	/**
994
	 * Parses the given string as the hypothetical contents of the named
995
	 * compilation unit and creates and returns a corresponding abstract syntax tree.
996
	 * <p>
997
	 * The returned compilation unit node is the root node of a new AST.
998
	 * Each node in the subtree carries source range(s) information relating back
999
	 * to positions in the given source string (the given source string itself
1000
	 * is not remembered with the AST).
1001
	 * The source range usually begins at the first character of the first token 
1002
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
1003
	 * included. The source range usually extends through the last character of
1004
	 * the last token corresponding to the node; trailing whitespace and
1005
	 * comments are <b>not</b> included. There are a handful of exceptions
1006
	 * (including compilation units and the various body declarations); the
1007
	 * specification for these node type spells out the details.
1008
	 * Source ranges nest properly: the source range for a child is always
1009
	 * within the source range of its parent, and the source ranges of sibling
1010
	 * nodes never overlap.
1011
	 * If a syntax error is detected while parsing, the relevant node(s) of the
1012
	 * tree will be flagged as <code>MALFORMED</code>.
1013
	 * </p>
1014
	 * <p>
1015
	 * If the given project is not <code>null</code>, the various names
1016
	 * and types appearing in the compilation unit can be resolved to "bindings"
1017
	 * by calling the <code>resolveBinding</code> methods. These bindings 
1018
	 * draw connections between the different parts of a program, and 
1019
	 * generally afford a more powerful vantage point for clients who wish to
1020
	 * analyze a program's structure more deeply. These bindings come at a 
1021
	 * considerable cost in both time and space, however, and should not be
1022
	 * requested frivolously. The additional space is not reclaimed until the 
1023
	 * AST, all its nodes, and all its bindings become garbage. So it is very
1024
	 * important to not retain any of these objects longer than absolutely
1025
	 * necessary. Bindings are resolved at the time the AST is created. Subsequent
1026
	 * modifications to the AST do not affect the bindings returned by
1027
	 * <code>resolveBinding</code> methods in any way; these methods return the
1028
	 * same binding as before the AST was modified (including modifications
1029
	 * that rearrange subtrees by reparenting nodes).
1030
	 * If the given project is <code>null</code>, the analysis 
1031
	 * does not go beyond parsing and building the tree, and all 
1032
	 * <code>resolveBinding</code> methods return <code>null</code> from the 
1033
	 * outset.
1034
	 * </p>
1035
	 * <p>
1036
	 * Several options are available while parsing the compilation unit:
1037
	 *<ul>
1038
	 *<li>- <code>ResolveBindings</code>
1039
	 * 		When this flag is set, the various names and types appearing in
1040
	 * 		the compilation unit can be resolved to "bindings" by calling
1041
	 * 		the <code>resolveBinding</code> methods. These bindings draw
1042
	 * 		connections between the different parts of a program, and generally
1043
	 * 		afford a more powerful vantage point for clients who wish to
1044
	 * 		analyze a program's structure more deeply. These bindings come
1045
	 * 		at a considerable cost in both time and space, however, and should
1046
	 * 		not be requested frivolously. The additional space is not reclaimed
1047
	 * 		until the AST, all its nodes, and all its bindings become garbage.
1048
	 * 		So it is very important to not retain any of these objects longer
1049
	 * 		than absolutely necessary. Bindings are resolved at the time the
1050
	 * 		AST is created. Subsequent modifications to the AST do not affect
1051
	 * 		the bindings returned by <code>resolveBinding</code> methods in
1052
	 * 		any way; these methods return the same binding as before the AST
1053
	 * 		was modified (including modifications that rearrange subtrees by
1054
	 * 		reparenting nodes).
1055
	 * 		When this flag is not set, the analysis does not go beyond parsing
1056
	 * 		and building the tree, and all <code>resolveBinding</code> methods
1057
	 * 		return <code>null</code> from the  outset.
1058
	 * </li>
1059
	 * <li>- <code>InsideComments</code>
1060
	 * 		When this flag is set, all comments of the compilation unit are stored
1061
	 * 		and parsed to identify possible Javadoc tags.
1062
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
1063
	 * 		There are three different kind of comments: line, block and javadoc.
1064
	 * 		Javadoc comments are those which were already defined since version 2.0,
1065
	 * 		but they are now structured and not only a flat text.
1066
	 * 		@see Javadoc for more details on this AST node structure
1067
	 * </li>
1068
	 * </ul>
1069
	 * Use OR operator to set several options simultaneously. For example, to set
1070
	 * both bindings resolution and comments, set options parameter to:
1071
	 * <code>ResolveBindings | InsideComments</code>.
1072
	 * Note that if the given project is <code>null</code>, bindings won't be
1073
	 * resolved even if resolve binding option is set.
1074
	 * </p>
1075
	 * <p>
1076
	 * The name of the compilation unit must be supplied for resolving bindings.
1077
	 * This name should include the ".java" suffix and match the name of the main
1078
	 * (public) class or interface declared in the source. For example, if the source
1079
	 * declares a public class named "Foo", the name of the compilation should be
1080
	 * "Foo.java". For the purposes of resolving bindings, types declared in the
1081
	 * source string hide types by the same name available through the classpath
1082
	 * of the given project.
1083
	 * </p>
1084
	 * 
1085
	 * @param source the string to be parsed as a Java compilation unit
1086
	 * @param options an integer which sets parse options. 
1087
	 * @param unitName the name of the compilation unit that would contain the source
1088
	 *    string, or <code>null</code> if <code>javaProject</code> is also <code>null</code>
1089
	 * @param project the Java project used to resolve names, or 
1090
	 *    <code>null</code> if bindings are not resolved
1091
	 * @return the compilation unit node
1092
	 * @see ASTNode#getFlags()
1093
	 * @see ASTNode#MALFORMED
1094
	 * @see ASTNode#getStartPosition()
1095
	 * @see ASTNode#getLength()
1096
	 * @since 3.0
1097
	 */
1098
	public static CompilationUnit parseCompilationUnit(
1099
			char[] source,
1100
			int options,
1101
			String unitName,
1102
			IJavaProject project) {
1103
		
1104
		return parseCompilationUnit(source, options, unitName, project, DefaultWorkingCopyOwner.PRIMARY);
580
	}
1105
	}
581
			
1106
582
	/**
1107
	/**
583
	 * Parses the given string as the hypothetical contents of the named
1108
	 * Parses the given string as the hypothetical contents of the named
584
	 * compilation unit and creates and returns a corresponding abstract syntax tree.
1109
	 * compilation unit and creates and returns a corresponding abstract syntax tree.
Lines 622-627 Link Here
622
	 * outset.
1147
	 * outset.
623
	 * </p>
1148
	 * </p>
624
	 * <p>
1149
	 * <p>
1150
	 * When bindings are created, instead of considering compilation units on disk only
1151
	 * one can supply a <code>WorkingCopyOwner</code>. Working copies owned 
1152
	 * by this owner take precedence over the underlying compilation units when looking
1153
	 * up names and drawing the connections.
1154
	 * </p>
1155
	 * <p>
625
	 * The name of the compilation unit must be supplied for resolving bindings.
1156
	 * The name of the compilation unit must be supplied for resolving bindings.
626
	 * This name should include the ".java" suffix and match the name of the main
1157
	 * This name should include the ".java" suffix and match the name of the main
627
	 * (public) class or interface declared in the source. For example, if the source
1158
	 * (public) class or interface declared in the source. For example, if the source
Lines 636-655 Link Here
636
	 *    string, or <code>null</code> if <code>javaProject</code> is also <code>null</code>
1167
	 *    string, or <code>null</code> if <code>javaProject</code> is also <code>null</code>
637
	 * @param project the Java project used to resolve names, or 
1168
	 * @param project the Java project used to resolve names, or 
638
	 *    <code>null</code> if bindings are not resolved
1169
	 *    <code>null</code> if bindings are not resolved
1170
	 * @param owner the owner of working copies that take precedence over underlying 
1171
	 *   compilation units
639
	 * @return the compilation unit node
1172
	 * @return the compilation unit node
640
	 * @see ASTNode#getFlags()
1173
	 * @see ASTNode#getFlags()
641
	 * @see ASTNode#MALFORMED
1174
	 * @see ASTNode#MALFORMED
642
	 * @see ASTNode#getStartPosition()
1175
	 * @see ASTNode#getStartPosition()
643
	 * @see ASTNode#getLength()
1176
	 * @see ASTNode#getLength()
1177
	 * @see WorkingCopyOwner
1178
	 * @since 3.0
1179
	 * @deprecated Use #parseCompilationUnit(char(], int, String, JavaProject, WorkingCopyOwner)
1180
	 * TODO (frederic) remove for 3.0
644
	 */
1181
	 */
645
	public static CompilationUnit parseCompilationUnit(
1182
	public static CompilationUnit parseCompilationUnit(
646
		char[] source,
1183
			char[] source,
647
		String unitName,
1184
			String unitName,
648
		IJavaProject project) {
1185
			IJavaProject project,
649
		
1186
			WorkingCopyOwner owner) {
650
		return parseCompilationUnit(source, unitName, project, DefaultWorkingCopyOwner.PRIMARY);
1187
		return parseCompilationUnit(source, ResolveBindings, unitName, project, owner);
651
	}
1188
	}
652
				
1189
653
	/**
1190
	/**
654
	 * Parses the given string as the hypothetical contents of the named
1191
	 * Parses the given string as the hypothetical contents of the named
655
	 * compilation unit and creates and returns a corresponding abstract syntax tree.
1192
	 * compilation unit and creates and returns a corresponding abstract syntax tree.
Lines 672-696 Link Here
672
	 * tree will be flagged as <code>MALFORMED</code>.
1209
	 * tree will be flagged as <code>MALFORMED</code>.
673
	 * </p>
1210
	 * </p>
674
	 * <p>
1211
	 * <p>
675
	 * If the given project is not <code>null</code>, the various names
1212
	 * Several options are available while parsing the compilation unit:
676
	 * and types appearing in the compilation unit can be resolved to "bindings"
1213
	 *<ul>
677
	 * by calling the <code>resolveBinding</code> methods. These bindings 
1214
	 *<li>- <code>ResolveBindings</code>
678
	 * draw connections between the different parts of a program, and 
1215
	 * 		When this flag is set, the various names and types appearing in
679
	 * generally afford a more powerful vantage point for clients who wish to
1216
	 * 		the compilation unit can be resolved to "bindings" by calling
680
	 * analyze a program's structure more deeply. These bindings come at a 
1217
	 * 		the <code>resolveBinding</code> methods. These bindings draw
681
	 * considerable cost in both time and space, however, and should not be
1218
	 * 		connections between the different parts of a program, and generally
682
	 * requested frivolously. The additional space is not reclaimed until the 
1219
	 * 		afford a more powerful vantage point for clients who wish to
683
	 * AST, all its nodes, and all its bindings become garbage. So it is very
1220
	 * 		analyze a program's structure more deeply. These bindings come
684
	 * important to not retain any of these objects longer than absolutely
1221
	 * 		at a considerable cost in both time and space, however, and should
685
	 * necessary. Bindings are resolved at the time the AST is created. Subsequent
1222
	 * 		not be requested frivolously. The additional space is not reclaimed
686
	 * modifications to the AST do not affect the bindings returned by
1223
	 * 		until the AST, all its nodes, and all its bindings become garbage.
687
	 * <code>resolveBinding</code> methods in any way; these methods return the
1224
	 * 		So it is very important to not retain any of these objects longer
688
	 * same binding as before the AST was modified (including modifications
1225
	 * 		than absolutely necessary. Bindings are resolved at the time the
689
	 * that rearrange subtrees by reparenting nodes).
1226
	 * 		AST is created. Subsequent modifications to the AST do not affect
690
	 * If the given project is <code>null</code>, the analysis 
1227
	 * 		the bindings returned by <code>resolveBinding</code> methods in
691
	 * does not go beyond parsing and building the tree, and all 
1228
	 * 		any way; these methods return the same binding as before the AST
692
	 * <code>resolveBinding</code> methods return <code>null</code> from the 
1229
	 * 		was modified (including modifications that rearrange subtrees by
693
	 * outset.
1230
	 * 		reparenting nodes).
1231
	 * 		When this flag is not set, the analysis does not go beyond parsing
1232
	 * 		and building the tree, and all <code>resolveBinding</code> methods
1233
	 * 		return <code>null</code> from the  outset.
1234
	 * </li>
1235
	 * <li>- <code>InsideComments</code>
1236
	 * 		When this flag is set, all comments of the compilation unit are stored
1237
	 * 		and parsed to identify possible Javadoc tags.
1238
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
1239
	 * 		There are three different kind of comments: line, block and javadoc.
1240
	 * 		Javadoc comments are those which were already defined since version 2.0,
1241
	 * 		but they are now structured and not only a flat text.
1242
	 * 		@see Javadoc for more details on this AST node structure
1243
	 * </li>
1244
	 * </ul>
1245
	 * Use OR operator to set several options simultaneously. For example, to set
1246
	 * both bindings resolution and comments, set options parameter to:
1247
	 * <code>ResolveBindings | InsideComments</code>.
1248
	 * Note that if the given project is <code>null</code>, bindings won't be
1249
	 * resolved even if resolve binding option is set.
694
	 * </p>
1250
	 * </p>
695
	 * <p>
1251
	 * <p>
696
	 * When bindings are created, instead of considering compilation units on disk only
1252
	 * When bindings are created, instead of considering compilation units on disk only
Lines 709-714 Link Here
709
	 * </p>
1265
	 * </p>
710
	 * 
1266
	 * 
711
	 * @param source the string to be parsed as a Java compilation unit
1267
	 * @param source the string to be parsed as a Java compilation unit
1268
	 * @param options an integer which sets parse options. 
712
	 * @param unitName the name of the compilation unit that would contain the source
1269
	 * @param unitName the name of the compilation unit that would contain the source
713
	 *    string, or <code>null</code> if <code>javaProject</code> is also <code>null</code>
1270
	 *    string, or <code>null</code> if <code>javaProject</code> is also <code>null</code>
714
	 * @param project the Java project used to resolve names, or 
1271
	 * @param project the Java project used to resolve names, or 
Lines 725-730 Link Here
725
	 */
1282
	 */
726
	public static CompilationUnit parseCompilationUnit(
1283
	public static CompilationUnit parseCompilationUnit(
727
		char[] source,
1284
		char[] source,
1285
		int options,
728
		String unitName,
1286
		String unitName,
729
		IJavaProject project,
1287
		IJavaProject project,
730
		WorkingCopyOwner owner) {
1288
		WorkingCopyOwner owner) {
Lines 759-765 Link Here
759
					unitName,
1317
					unitName,
760
					project,
1318
					project,
761
					false/*don't cleanup*/);
1319
					false/*don't cleanup*/);
762
			ASTConverter converter = new ASTConverter(project.getOptions(true), true);
1320
			ASTConverter converter = new ASTConverter(project.getOptions(true), (ResolveBindings | options));
763
			AST ast = new AST();
1321
			AST ast = new AST();
764
			BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
1322
			BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
765
			ast.setBindingResolver(resolver);
1323
			ast.setBindingResolver(resolver);
Lines 784-790 Link Here
784
			}
1342
			}
785
		}
1343
		}
786
	}
1344
	}
787
	  	
1345
788
	/**
1346
	/**
789
	 * Parses the given string as a Java compilation unit and creates and 
1347
	 * Parses the given string as a Java compilation unit and creates and 
790
	 * returns a corresponding abstract syntax tree.
1348
	 * returns a corresponding abstract syntax tree.
Lines 819-831 Link Here
819
	 * @see ASTNode#getLength()
1377
	 * @see ASTNode#getLength()
820
	 */
1378
	 */
821
	public static CompilationUnit parseCompilationUnit(char[] source) {
1379
	public static CompilationUnit parseCompilationUnit(char[] source) {
1380
		return parseCompilationUnit(source, 0); // No bindings, no comments
1381
	}
1382
1383
	/**
1384
	 * Parses the given string as a Java compilation unit and creates and 
1385
	 * returns a corresponding abstract syntax tree.
1386
	 * <p>
1387
	 * The returned compilation unit node is the root node of a new AST.
1388
	 * Each node in the subtree carries source range(s) information relating back
1389
	 * to positions in the given source string (the given source string itself
1390
	 * is not remembered with the AST). 
1391
	 * The source range usually begins at the first character of the first token 
1392
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
1393
	 * included. The source range usually extends through the last character of
1394
	 * the last token corresponding to the node; trailing whitespace and
1395
	 * comments are <b>not</b> included. There are a handful of exceptions
1396
	 * (including compilation units and the various body declarations); the
1397
	 * specification for these node type spells out the details.
1398
	 * Source ranges nest properly: the source range for a child is always
1399
	 * within the source range of its parent, and the source ranges of sibling
1400
	 * nodes never overlap.
1401
	 * If a syntax error is detected while parsing, the relevant node(s) of the
1402
	 * tree will be flagged as <code>MALFORMED</code>.
1403
	 * </p>
1404
	 * <p>
1405
	 * Several options are available while parsing the source:
1406
	 *<ul>
1407
	 *<li>- <code>ResolveBindings</code>
1408
	 * 		When this flag is set, the various names and types appearing in
1409
	 * 		the compilation unit can be resolved to "bindings" by calling
1410
	 * 		the <code>resolveBinding</code> methods. These bindings draw
1411
	 * 		connections between the different parts of a program, and generally
1412
	 * 		afford a more powerful vantage point for clients who wish to
1413
	 * 		analyze a program's structure more deeply. These bindings come
1414
	 * 		at a considerable cost in both time and space, however, and should
1415
	 * 		not be requested frivolously. The additional space is not reclaimed
1416
	 * 		until the AST, all its nodes, and all its bindings become garbage.
1417
	 * 		So it is very important to not retain any of these objects longer
1418
	 * 		than absolutely necessary. Bindings are resolved at the time the
1419
	 * 		AST is created. Subsequent modifications to the AST do not affect
1420
	 * 		the bindings returned by <code>resolveBinding</code> methods in
1421
	 * 		any way; these methods return the same binding as before the AST
1422
	 * 		was modified (including modifications that rearrange subtrees by
1423
	 * 		reparenting nodes).
1424
	 * 		When this flag is not set, the analysis does not go beyond parsing
1425
	 * 		and building the tree, and all <code>resolveBinding</code> methods
1426
	 * 		return <code>null</code> from the  outset.
1427
	 * </li>
1428
	 * <li>- <code>InsideComments</code>
1429
	 * 		When this flag is set, all comments of the compilation unit are stored
1430
	 * 		and parsed to identify possible Javadoc tags.
1431
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
1432
	 * 		There are three different kind of comments: line, block and javadoc.
1433
	 * 		Javadoc comments are those which were already defined since version 2.0,
1434
	 * 		but they are now structured and not only a flat text.
1435
	 * 		@see Javadoc for more details on this AST node structure
1436
	 * </li>
1437
	 * </ul>
1438
	 * Use OR operator to set several options simultaneously. For example, to set
1439
	 * both bindings resolution and comments, set options parameter to:
1440
	 * <code>ResolveBindings | InsideComments</code>.
1441
	 * </p>
1442
	 * 
1443
	 * @param source the string to be parsed as a Java compilation unit
1444
	 * @param options an integer which sets parse options. 
1445
	 * @return CompilationUnit
1446
	 * @see ASTNode#getFlags()
1447
	 * @see ASTNode#MALFORMED
1448
	 * @see ASTNode#getStartPosition()
1449
	 * @see ASTNode#getLength()
1450
	 */
1451
	public static CompilationUnit parseCompilationUnit(char[] source, int options) {
822
		if (source == null) {
1452
		if (source == null) {
823
			throw new IllegalArgumentException();
1453
			throw new IllegalArgumentException();
824
		}
1454
		}
825
		CompilationUnitDeclaration compilationUnitDeclaration = 
1455
		CompilationUnitDeclaration compilationUnitDeclaration = 
826
			CompilationUnitResolver.parse(source, JavaCore.getOptions()); // no better custom options
1456
			CompilationUnitResolver.parse(source, JavaCore.getOptions()); // no better custom options
827
1457
828
		ASTConverter converter = new ASTConverter(JavaCore.getOptions(), false);
1458
		ASTConverter converter = new ASTConverter(JavaCore.getOptions(), options);
829
		AST ast = new AST();
1459
		AST ast = new AST();
830
		ast.setBindingResolver(new BindingResolver());
1460
		ast.setBindingResolver(new BindingResolver());
831
		converter.setAST(ast);
1461
		converter.setAST(ast);
Lines 926-940 Link Here
926
	 * @see ASTNode#getStartPosition()
1556
	 * @see ASTNode#getStartPosition()
927
	 * @see ASTNode#getLength()
1557
	 * @see ASTNode#getLength()
928
	 * @since 3.0
1558
	 * @since 3.0
1559
	 * @deprecated Use parsePartialCompilationUnit(ICompilationUnit, int, int)
1560
	 * TODO (frederic) remove for 3.0
929
	 */
1561
	 */
930
	public static CompilationUnit parsePartialCompilationUnit(
1562
	public static CompilationUnit parsePartialCompilationUnit(
931
		ICompilationUnit unit,
1563
		ICompilationUnit unit,
932
		int position,
1564
		int position,
933
		boolean resolveBindings) {
1565
		boolean resolveBindings) {
934
			return parsePartialCompilationUnit(unit, position, resolveBindings, DefaultWorkingCopyOwner.PRIMARY);
1566
			return parsePartialCompilationUnit(
1567
				unit,
1568
				position,
1569
				resolveBindings?ResolveBindings:0);
935
	}
1570
	}
936
1571
937
	/**
1572
	/**
1573
	 * Parses the source string of the given Java model compilation unit element
1574
	 * and creates and returns an abridged abstract syntax tree. This method
1575
	 * differs from
1576
	 * {@link #parseCompilationUnit(ICompilationUnit,boolean)
1577
	 * parseCompilationUnit(ICompilationUnit,boolean)} only in 
1578
	 * that the resulting AST does not have nodes for the entire compilation
1579
	 * unit. Rather, the AST is only fleshed out for the node that include
1580
	 * the given source position. This kind of limited AST is sufficient for
1581
	 * certain purposes but totally unsuitable for others. In places where it
1582
	 * can be used, the limited AST offers the advantage of being smaller and
1583
	 * faster to faster to construct.
1584
	 * </p>
1585
	 * <p>
1586
	 * The resulting AST always includes nodes for all of the compilation unit's
1587
	 * package, import, and top-level type declarations. It also always contains
1588
	 * nodes for all the body declarations for those top-level types, as well
1589
	 * as body declarations for any member types. However, some of the body
1590
	 * declarations may be abridged. In particular, the statements ordinarily
1591
	 * found in the body of a method declaration node will not be included
1592
	 * (the block will be empty) unless the source position falls somewhere
1593
	 * within the source range of that method declaration node. The same is true
1594
	 * for initializer declarations; the statements ordinarily found in the body
1595
	 * of initializer node will not be included unless the source position falls
1596
	 * somewhere within the source range of that initializer declaration node.
1597
	 * Field declarations are never abridged. Note that the AST for the body of
1598
	 * that one unabridged method (or initializer) is 100% complete; it has all
1599
	 * its statements, including any local or anonymous type declarations 
1600
	 * embedded within them. When the the given position is not located within
1601
	 * the source range of any body declaration of a top-level type, the AST
1602
	 * returned is a skeleton that includes nodes for all and only the major
1603
	 * declarations; this kind of AST is still quite useful because it contains
1604
	 * all the constructs that introduce names visible to the world outside the
1605
	 * compilation unit.
1606
	 * </p>
1607
	 * <p>
1608
	 * In all other respects, this method works the same as
1609
	 * {@link #parseCompilationUnit(ICompilationUnit,boolean)
1610
	 * parseCompilationUnit(ICompilationUnit,boolean)}.
1611
	 * The source string is obtained from the Java model element using
1612
	 * <code>ICompilationUnit.getSource()</code>.
1613
	 * </p>
1614
	 * <p>
1615
	 * The returned compilation unit node is the root node of a new AST.
1616
	 * Each node in the subtree carries source range(s) information relating back
1617
	 * to positions in the source string (the source string is not remembered
1618
	 * with the AST).
1619
	 * The source range usually begins at the first character of the first token 
1620
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
1621
	 * included. The source range usually extends through the last character of
1622
	 * the last token corresponding to the node; trailing whitespace and
1623
	 * comments are <b>not</b> included.
1624
	 * If a syntax error is detected while parsing, the relevant node(s) of the
1625
	 * tree will be flagged as <code>MALFORMED</code>.
1626
	 * </p>
1627
	 * <p>
1628
	 * Several options are available while parsing the source:
1629
	 *<ul>
1630
	 *<li>- <code>ResolveBindings</code>
1631
	 * 		When this flag is set, the various names and types appearing in
1632
	 * 		the compilation unit can be resolved to "bindings" by calling
1633
	 * 		the <code>resolveBinding</code> methods. These bindings draw
1634
	 * 		connections between the different parts of a program, and generally
1635
	 * 		afford a more powerful vantage point for clients who wish to
1636
	 * 		analyze a program's structure more deeply. These bindings come
1637
	 * 		at a considerable cost in both time and space, however, and should
1638
	 * 		not be requested frivolously. The additional space is not reclaimed
1639
	 * 		until the AST, all its nodes, and all its bindings become garbage.
1640
	 * 		So it is very important to not retain any of these objects longer
1641
	 * 		than absolutely necessary. Bindings are resolved at the time the
1642
	 * 		AST is created. Subsequent modifications to the AST do not affect
1643
	 * 		the bindings returned by <code>resolveBinding</code> methods in
1644
	 * 		any way; these methods return the same binding as before the AST
1645
	 * 		was modified (including modifications that rearrange subtrees by
1646
	 * 		reparenting nodes).
1647
	 * 		When this flag is not set, the analysis does not go beyond parsing
1648
	 * 		and building the tree, and all <code>resolveBinding</code> methods
1649
	 * 		return <code>null</code> from the  outset.
1650
	 * </li>
1651
	 * <li>- <code>InsideComments</code>
1652
	 * 		When this flag is set, all comments of the compilation unit are stored
1653
	 * 		and parsed to identify possible Javadoc tags.
1654
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
1655
	 * 		There are three different kind of comments: line, block and javadoc.
1656
	 * 		Javadoc comments are those which were already defined since version 2.0,
1657
	 * 		but they are now structured and not only a flat text.
1658
	 * 		@see Javadoc for more details on this AST node structure
1659
	 * </li>
1660
	 * </ul>
1661
	 * Use OR operator to set several options simultaneously. For example, to set
1662
	 * both bindings resolution and comments, set options parameter to:
1663
	 * <code>ResolveBindings | InsideComments</code>.
1664
	 * </p>
1665
	 * 
1666
	 * @param unit the Java model compilation unit whose source code is to be parsed
1667
	 * @param position a position into the corresponding body declaration
1668
	 * @param options an integer which sets parse options. 
1669
	 * @return the abridged compilation unit node
1670
	 * @exception IllegalArgumentException if the given Java element does not 
1671
	 * exist or if its source string cannot be obtained
1672
	 * @see ASTNode#getFlags()
1673
	 * @see ASTNode#MALFORMED
1674
	 * @see ASTNode#getStartPosition()
1675
	 * @see ASTNode#getLength()
1676
	 * @since 3.0
1677
	 */
1678
	public static CompilationUnit parsePartialCompilationUnit(
1679
			ICompilationUnit unit,
1680
			int position,
1681
			int options) {
1682
		return parsePartialCompilationUnit(unit, position, options, DefaultWorkingCopyOwner.PRIMARY);
1683
	}
1684
938
	/**
1685
	/**
939
	 * Parses the source string of the given Java model compilation unit element
1686
	 * Parses the source string of the given Java model compilation unit element
940
	 * and creates and returns an abridged abstract syntax tree. This method
1687
	 * and creates and returns an abridged abstract syntax tree. This method
Lines 1032-1042 Link Here
1032
	 * @see ASTNode#getStartPosition()
1779
	 * @see ASTNode#getStartPosition()
1033
	 * @see ASTNode#getLength()
1780
	 * @see ASTNode#getLength()
1034
	 * @since 3.0
1781
	 * @since 3.0
1782
	 * @deprecated Use parsePartialCompilationUnit(ICompilationUnit, int, int, WorkingCopyOwner)
1783
	 * TODO (frederic) remove for 3.0
1784
	 */
1785
	public static CompilationUnit parsePartialCompilationUnit(
1786
			ICompilationUnit unit,
1787
			int position,
1788
			boolean resolveBindings,
1789
			WorkingCopyOwner owner) {
1790
		return parsePartialCompilationUnit(
1791
			unit,
1792
			position,
1793
			resolveBindings ? ResolveBindings : 0,
1794
			DefaultWorkingCopyOwner.PRIMARY);
1795
	}	
1796
	/**
1797
	 * Parses the source string of the given Java model compilation unit element
1798
	 * and creates and returns an abridged abstract syntax tree. This method
1799
	 * differs from
1800
	 * {@link #parseCompilationUnit(ICompilationUnit,boolean,WorkingCopyOwner)
1801
	 * parseCompilationUnit(ICompilationUnit,boolean,WorkingCopyOwner)} only in 
1802
	 * that the resulting AST does not have nodes for the entire compilation
1803
	 * unit. Rather, the AST is only fleshed out for the node that include
1804
	 * the given source position. This kind of limited AST is sufficient for
1805
	 * certain purposes but totally unsuitable for others. In places where it
1806
	 * can be used, the limited AST offers the advantage of being smaller and
1807
	 * faster to faster to construct.
1808
	 * </p>
1809
	 * <p>
1810
	 * The resulting AST always includes nodes for all of the compilation unit's
1811
	 * package, import, and top-level type declarations. It also always contains
1812
	 * nodes for all the body declarations for those top-level types, as well
1813
	 * as body declarations for any member types. However, some of the body
1814
	 * declarations may be abridged. In particular, the statements ordinarily
1815
	 * found in the body of a method declaration node will not be included
1816
	 * (the block will be empty) unless the source position falls somewhere
1817
	 * within the source range of that method declaration node. The same is true
1818
	 * for initializer declarations; the statements ordinarily found in the body
1819
	 * of initializer node will not be included unless the source position falls
1820
	 * somewhere within the source range of that initializer declaration node.
1821
	 * Field declarations are never abridged. Note that the AST for the body of
1822
	 * that one unabridged method (or initializer) is 100% complete; it has all
1823
	 * its statements, including any local or anonymous type declarations 
1824
	 * embedded within them. When the the given position is not located within
1825
	 * the source range of any body declaration of a top-level type, the AST
1826
	 * returned is a skeleton that includes nodes for all and only the major
1827
	 * declarations; this kind of AST is still quite useful because it contains
1828
	 * all the constructs that introduce names visible to the world outside the
1829
	 * compilation unit.
1830
	 * </p>
1831
	 * <p>
1832
	 * In all other respects, this method works the same as
1833
	 * {@link #parseCompilationUnit(ICompilationUnit,boolean,WorkingCopyOwner)
1834
	 * parseCompilationUnit(ICompilationUnit,boolean,WorkingCopyOwner)}.
1835
	 * The source string is obtained from the Java model element using
1836
	 * <code>ICompilationUnit.getSource()</code>.
1837
	 * </p>
1838
	 * <p>
1839
	 * The returned compilation unit node is the root node of a new AST.
1840
	 * Each node in the subtree carries source range(s) information relating back
1841
	 * to positions in the source string (the source string is not remembered
1842
	 * with the AST).
1843
	 * The source range usually begins at the first character of the first token 
1844
	 * corresponding to the node; leading whitespace and comments are <b>not</b>
1845
	 * included. The source range usually extends through the last character of
1846
	 * the last token corresponding to the node; trailing whitespace and
1847
	 * comments are <b>not</b> included.
1848
	 * If a syntax error is detected while parsing, the relevant node(s) of the
1849
	 * tree will be flagged as <code>MALFORMED</code>.
1850
	 * </p>
1851
	 * <p>
1852
	 * Several options are available while parsing the source:
1853
	 *<ul>
1854
	 *<li>- <code>ResolveBindings</code>
1855
	 * 		When this flag is set, the various names and types appearing in
1856
	 * 		the compilation unit can be resolved to "bindings" by calling
1857
	 * 		the <code>resolveBinding</code> methods. These bindings draw
1858
	 * 		connections between the different parts of a program, and generally
1859
	 * 		afford a more powerful vantage point for clients who wish to
1860
	 * 		analyze a program's structure more deeply. These bindings come
1861
	 * 		at a considerable cost in both time and space, however, and should
1862
	 * 		not be requested frivolously. The additional space is not reclaimed
1863
	 * 		until the AST, all its nodes, and all its bindings become garbage.
1864
	 * 		So it is very important to not retain any of these objects longer
1865
	 * 		than absolutely necessary. Bindings are resolved at the time the
1866
	 * 		AST is created. Subsequent modifications to the AST do not affect
1867
	 * 		the bindings returned by <code>resolveBinding</code> methods in
1868
	 * 		any way; these methods return the same binding as before the AST
1869
	 * 		was modified (including modifications that rearrange subtrees by
1870
	 * 		reparenting nodes).
1871
	 * 		When this flag is not set, the analysis does not go beyond parsing
1872
	 * 		and building the tree, and all <code>resolveBinding</code> methods
1873
	 * 		return <code>null</code> from the  outset.
1874
	 * </li>
1875
	 * <li>- <code>InsideComments</code>
1876
	 * 		When this flag is set, all comments of the compilation unit are stored
1877
	 * 		and parsed to identify possible Javadoc tags.
1878
	 * 		Comments are stored in a list <code>comments</code> of <code>Comment</code>.
1879
	 * 		There are three different kind of comments: line, block and javadoc.
1880
	 * 		Javadoc comments are those which were already defined since version 2.0,
1881
	 * 		but they are now structured and not only a flat text.
1882
	 * 		@see Javadoc for more details on this AST node structure
1883
	 * </li>
1884
	 * </ul>
1885
	 * Use OR operator to set several options simultaneously. For example, to set
1886
	 * both bindings resolution and comments, set options parameter to:
1887
	 * <code>ResolveBindings | InsideComments</code>.
1888
	 * </p>
1889
	 * <p>
1890
	 * When bindings are created, instead of considering compilation units on disk only
1891
	 * one can supply a <code>WorkingCopyOwner</code>. Working copies owned 
1892
	 * by this owner take precedence over the underlying compilation units when looking
1893
	 * up names and drawing the connections.
1894
	 * </p>
1895
	 * 
1896
	 * @param unit the Java model compilation unit whose source code is to be parsed
1897
	 * @param position a position into the corresponding body declaration
1898
	 * @param options an integer which sets parse options. 
1899
	 * @param owner the owner of working copies that take precedence over underlying 
1900
	 *   compilation units
1901
	 * @return the abridged compilation unit node
1902
	 * @exception IllegalArgumentException if the given Java element does not 
1903
	 * exist or the source range is null or if its source string cannot be obtained
1904
	 * @see ASTNode#getFlags()
1905
	 * @see ASTNode#MALFORMED
1906
	 * @see ASTNode#getStartPosition()
1907
	 * @see ASTNode#getLength()
1908
	 * @since 3.0
1035
	 */
1909
	 */
1036
	public static CompilationUnit parsePartialCompilationUnit(
1910
	public static CompilationUnit parsePartialCompilationUnit(
1037
		ICompilationUnit unit,
1911
		ICompilationUnit unit,
1038
		int position,
1912
		int position,
1039
		boolean resolveBindings,
1913
		int options,
1040
		WorkingCopyOwner owner) {
1914
		WorkingCopyOwner owner) {
1041
				
1915
				
1042
		if (unit == null) {
1916
		if (unit == null) {
Lines 1056-1063 Link Here
1056
1930
1057
		NodeSearcher searcher = new NodeSearcher(position);
1931
		NodeSearcher searcher = new NodeSearcher(position);
1058
1932
1059
		final Map options = unit.getJavaProject().getOptions(true);
1933
		final Map javaOptions = unit.getJavaProject().getOptions(true);
1060
		if (resolveBindings) {
1934
		if ((options & ResolveBindings) == ResolveBindings) {
1061
			NameLookup lookup = null;
1935
			NameLookup lookup = null;
1062
			CompilationUnitDeclaration compilationUnitDeclaration = null;
1936
			CompilationUnitDeclaration compilationUnitDeclaration = null;
1063
			try {
1937
			try {
Lines 1074-1080 Link Here
1074
					false/*don't cleanup*/,
1948
					false/*don't cleanup*/,
1075
					source);
1949
					source);
1076
				
1950
				
1077
				ASTConverter converter = new ASTConverter(options, true);
1951
				ASTConverter converter = new ASTConverter(javaOptions, options);
1078
				AST ast = new AST();
1952
				AST ast = new AST();
1079
				BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
1953
				BindingResolver resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope);
1080
				ast.setBindingResolver(resolver);
1954
				ast.setBindingResolver(resolver);
Lines 1092-1100 Link Here
1092
				CompilationUnitDeclaration compilationUnitDeclaration2 = CompilationUnitResolver.parse(
1966
				CompilationUnitDeclaration compilationUnitDeclaration2 = CompilationUnitResolver.parse(
1093
					source,
1967
					source,
1094
					searcher,
1968
					searcher,
1095
					options);
1969
					javaOptions);
1096
				
1970
				
1097
				ASTConverter converter = new ASTConverter(options, false);
1971
				ASTConverter converter = new ASTConverter(javaOptions, options^ResolveBindings);
1098
				AST ast = new AST();
1972
				AST ast = new AST();
1099
				final BindingResolver resolver = new BindingResolver();
1973
				final BindingResolver resolver = new BindingResolver();
1100
				ast.setBindingResolver(resolver);
1974
				ast.setBindingResolver(resolver);
Lines 1116-1124 Link Here
1116
			CompilationUnitDeclaration compilationUnitDeclaration = CompilationUnitResolver.parse(
1990
			CompilationUnitDeclaration compilationUnitDeclaration = CompilationUnitResolver.parse(
1117
				source,
1991
				source,
1118
				searcher,
1992
				searcher,
1119
				options);
1993
				javaOptions);
1120
			
1994
			
1121
			ASTConverter converter = new ASTConverter(options, false);
1995
			ASTConverter converter = new ASTConverter(javaOptions, options);
1122
			AST ast = new AST();
1996
			AST ast = new AST();
1123
			final BindingResolver resolver = new BindingResolver();
1997
			final BindingResolver resolver = new BindingResolver();
1124
			ast.setBindingResolver(resolver);
1998
			ast.setBindingResolver(resolver);
Lines 1143-1149 Link Here
1143
	 * @return the binding resolver for this AST
2017
	 * @return the binding resolver for this AST
1144
	 */
2018
	 */
1145
	BindingResolver getBindingResolver() {
2019
	BindingResolver getBindingResolver() {
1146
		return resolver;
2020
		return this.resolver;
1147
	}
2021
	}
1148
2022
1149
	/** 
2023
	/** 
Lines 1496-1503 Link Here
1496
	 * 
2370
	 * 
1497
	 * @return a new unparented Javadoc comment node
2371
	 * @return a new unparented Javadoc comment node
1498
	 */
2372
	 */
2373
	public Comment newComment() {
2374
		Comment result = new Comment(this);
2375
		return result;
2376
	}
1499
	public Javadoc newJavadoc() {
2377
	public Javadoc newJavadoc() {
1500
		Javadoc result = new Javadoc(this);
2378
		Javadoc result = new Javadoc(this);
2379
		return result;
2380
	}
2381
	public JavadocEmbeddedTag newJavadocEmbeddedTag() {
2382
		JavadocEmbeddedTag result = new JavadocEmbeddedTag(this);
2383
		return result;
2384
	}
2385
	public JavadocTag newJavadocTag() {
2386
		JavadocTag result = new JavadocTag(this);
2387
		return result;
2388
	}
2389
	public JavadocArgument newJavadocArgument() {
2390
		JavadocArgument result = new JavadocArgument(this);
1501
		return result;
2391
		return result;
1502
	}
2392
	}
1503
	
2393
	
(-)dom/org/eclipse/jdt/core/dom/ASTConverter.java (-95 / +144 lines)
Lines 33-65 Link Here
33
33
34
	private AST ast;
34
	private AST ast;
35
	private char[] compilationUnitSource;
35
	private char[] compilationUnitSource;
36
	private Scanner scanner;
36
	private DOMScanner scanner;
37
	private boolean resolveBindings;
37
	//private boolean resolveBindings;
38
	private int options;
38
	private Set pendingThisExpressionScopeResolution;
39
	private Set pendingThisExpressionScopeResolution;
39
	private Set pendingNameScopeResolution;	
40
	private Set pendingNameScopeResolution;	
40
	
41
	
41
	public ASTConverter(Map options, boolean resolveBindings) {
42
	/**
42
		this.resolveBindings = resolveBindings;
43
	 * @deprecated
43
		scanner = new Scanner(
44
	 */
44
					true /*comment*/,
45
	public ASTConverter(Map compilerOptions, boolean resolveBindings) {
45
					false /*whitespace*/,
46
		this(compilerOptions, resolveBindings ? AST.ResolveBindings : 0);
46
					false /*nls*/,
47
	}
47
					JavaCore.VERSION_1_4.equals(options.get(JavaCore.COMPILER_SOURCE)) ? ClassFileConstants.JDK1_4 : ClassFileConstants.JDK1_3 /*sourceLevel*/, 
48
	
48
					null /*taskTags*/,
49
	public ASTConverter(Map compilerOptions, int options) {
49
					null/*taskPriorities*/);
50
		this.options = options;
51
		scanner = new DOMScanner(
52
				true /*comment*/,
53
				false /*whitespace*/,
54
				false /*nls*/,
55
				JavaCore.VERSION_1_4.equals(compilerOptions.get(JavaCore.COMPILER_SOURCE)) ? ClassFileConstants.JDK1_4 : ClassFileConstants.JDK1_3 /*sourceLevel*/, 
56
				null /*taskTags*/,
57
				null/*taskPriorities*/);
50
	}
58
	}
51
	
59
	
52
	public void setAST(AST ast) {
60
	public void setAST(AST ast) {
53
		this.ast = ast;
61
		this.ast = ast;
54
	}
62
	}
55
	
63
	
64
	private boolean resolveBindings() {
65
		return (this.options & AST.ResolveBindings) == AST.ResolveBindings;
66
	}
67
			
68
	
56
	public CompilationUnit convert(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, char[] source) {
69
	public CompilationUnit convert(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, char[] source) {
57
		this.compilationUnitSource = source;
70
		this.compilationUnitSource = source;
58
		scanner.setSource(source);
71
		scanner.setSource(source);
59
		CompilationUnit compilationUnit = this.ast.newCompilationUnit();
72
		CompilationUnit compilationUnit = this.ast.newCompilationUnit();
60
		// handle the package declaration immediately
73
		// handle the package declaration immediately
61
		// There is no node corresponding to the package declaration
74
		// There is no node corresponding to the package declaration
62
		if (resolveBindings) {
75
		if (resolveBindings()) {
63
			recordNodes(compilationUnit, unit);
76
			recordNodes(compilationUnit, unit);
64
		}
77
		}
65
		if (unit.currentPackage != null) {
78
		if (unit.currentPackage != null) {
Lines 73-78 Link Here
73
				compilationUnit.imports().add(convertImport(imports[i]));
86
				compilationUnit.imports().add(convertImport(imports[i]));
74
			}
87
			}
75
		}
88
		}
89
		int[][] comments = unit.comments;
90
		if (comments != null) {
91
			int commentsLength = comments.length;
92
			for (int i = 0; i < commentsLength; i++) {
93
				compilationUnit.comments().add(createComment(comments[i]));
94
			}
95
		}
96
76
		org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit.types;
97
		org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit.types;
77
		if (types != null) {
98
		if (types != null) {
78
			int typesLength = types.length;
99
			int typesLength = types.length;
Lines 85-91 Link Here
85
		if (unit.compilationResult.problemCount != 0) {
106
		if (unit.compilationResult.problemCount != 0) {
86
			propagateErrors(compilationUnit, unit.compilationResult.problems, unit.compilationResult.problemCount);
107
			propagateErrors(compilationUnit, unit.compilationResult.problems, unit.compilationResult.problemCount);
87
		}
108
		}
88
		if (resolveBindings) {
109
		if (resolveBindings()) {
89
			lookupForScopes();
110
			lookupForScopes();
90
		}
111
		}
91
		return compilationUnit;
112
		return compilationUnit;
Lines 108-114 Link Here
108
		}
129
		}
109
		packageDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
130
		packageDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
110
		packageDeclaration.setName(name);
131
		packageDeclaration.setName(name);
111
		if (resolveBindings) {
132
		if (resolveBindings()) {
112
			recordNodes(packageDeclaration, importReference);
133
			recordNodes(packageDeclaration, importReference);
113
			recordNodes(name, compilationUnitDeclaration);
134
			recordNodes(name, compilationUnitDeclaration);
114
		}
135
		}
Lines 133-139 Link Here
133
		importDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
154
		importDeclaration.setSourceRange(importReference.declarationSourceStart, importReference.declarationEnd - importReference.declarationSourceStart + 1);
134
		importDeclaration.setName(name);
155
		importDeclaration.setName(name);
135
		importDeclaration.setOnDemand(onDemand);
156
		importDeclaration.setOnDemand(onDemand);
136
		if (resolveBindings) {
157
		if (resolveBindings()) {
137
			recordNodes(importDeclaration, importReference);
158
			recordNodes(importDeclaration, importReference);
138
		}
159
		}
139
		return importDeclaration;
160
		return importDeclaration;
Lines 180-187 Link Here
180
		}
201
		}
181
		
202
		
182
		buildBodyDeclarations(typeDeclaration, typeDecl);
203
		buildBodyDeclarations(typeDeclaration, typeDecl);
183
		setJavaDocComment(typeDecl);
204
		// The javadoc comment is now got from list store in compilation unit declaration
184
		if (this.resolveBindings) {
205
		// @see BodyDeclaration#getComment(int)
206
		//setJavaDocComment(typeDecl);
207
		if (resolveBindings()) {
185
			recordNodes(typeDecl, typeDeclaration);
208
			recordNodes(typeDecl, typeDeclaration);
186
			recordNodes(typeName, typeDeclaration);
209
			recordNodes(typeName, typeDeclaration);
187
			typeDecl.resolveBinding();
210
			typeDecl.resolveBinding();
Lines 257-263 Link Here
257
			initializer.setBody(convert(oldInitializer.block));
280
			initializer.setBody(convert(oldInitializer.block));
258
			initializer.setModifiers(oldInitializer.modifiers);
281
			initializer.setModifiers(oldInitializer.modifiers);
259
			initializer.setSourceRange(oldInitializer.declarationSourceStart, oldInitializer.sourceEnd - oldInitializer.declarationSourceStart + 1);
282
			initializer.setSourceRange(oldInitializer.declarationSourceStart, oldInitializer.sourceEnd - oldInitializer.declarationSourceStart + 1);
260
			setJavaDocComment(initializer);
283
			// The javadoc comment is now got from list store in compilation unit declaration
284
			// @see BodyDeclaration#getComment(int)
285
			//setJavaDocComment(initializer);
261
			bodyDeclarations.add(initializer);
286
			bodyDeclarations.add(initializer);
262
			return;
287
			return;
263
		}
288
		}
Lines 305-311 Link Here
305
			name = this.ast.newSimpleName(new String(typeName[0]));
330
			name = this.ast.newSimpleName(new String(typeName[0]));
306
			name.setSourceRange(typeReference.sourceStart, typeReference.sourceEnd - typeReference.sourceStart + 1);
331
			name.setSourceRange(typeReference.sourceStart, typeReference.sourceEnd - typeReference.sourceStart + 1);
307
		}
332
		}
308
		if (this.resolveBindings) {
333
		if (resolveBindings()) {
309
			recordNodes(name, typeReference);
334
			recordNodes(name, typeReference);
310
		}
335
		}
311
		return name;
336
		return name;
Lines 313-319 Link Here
313
	
338
	
314
	public SimpleName convert(org.eclipse.jdt.internal.compiler.ast.SingleNameReference nameReference) {
339
	public SimpleName convert(org.eclipse.jdt.internal.compiler.ast.SingleNameReference nameReference) {
315
		SimpleName name = this.ast.newSimpleName(new String(nameReference.token));		
340
		SimpleName name = this.ast.newSimpleName(new String(nameReference.token));		
316
		if (this.resolveBindings) {
341
		if (resolveBindings()) {
317
			recordNodes(name, nameReference);
342
			recordNodes(name, nameReference);
318
		}
343
		}
319
		name.setSourceRange(nameReference.sourceStart, nameReference.sourceEnd - nameReference.sourceStart + 1);
344
		name.setSourceRange(nameReference.sourceStart, nameReference.sourceEnd - nameReference.sourceStart + 1);
Lines 338-344 Link Here
338
		end = (int)(positions[1] & 0xFFFFFFFF);
363
		end = (int)(positions[1] & 0xFFFFFFFF);
339
		secondToken.setSourceRange(start, end - start + 1);
364
		secondToken.setSourceRange(start, end - start + 1);
340
		QualifiedName qualifiedName = this.ast.newQualifiedName(firstToken, secondToken);
365
		QualifiedName qualifiedName = this.ast.newQualifiedName(firstToken, secondToken);
341
		if (this.resolveBindings) {
366
		if (resolveBindings()) {
342
			recordNodes(qualifiedName, node);
367
			recordNodes(qualifiedName, node);
343
			recordPendingNameScopeResolution(qualifiedName);
368
			recordPendingNameScopeResolution(qualifiedName);
344
			recordNodes(firstToken, node);
369
			recordNodes(firstToken, node);
Lines 358-364 Link Here
358
			qualifiedName = this.ast.newQualifiedName(qualifiedName, newPart);
383
			qualifiedName = this.ast.newQualifiedName(qualifiedName, newPart);
359
			qualifiedName.index = newPart.index;
384
			qualifiedName.index = newPart.index;
360
			qualifiedName.setSourceRange(start0, end - start0 + 1);
385
			qualifiedName.setSourceRange(start0, end - start0 + 1);
361
			if (this.resolveBindings) {
386
			if (resolveBindings()) {
362
				recordNodes(qualifiedName, node);
387
				recordNodes(qualifiedName, node);
363
				recordNodes(newPart, node);				
388
				recordNodes(newPart, node);				
364
				recordPendingNameScopeResolution(qualifiedName);
389
				recordPendingNameScopeResolution(qualifiedName);
Lines 366-372 Link Here
366
			}
391
			}
367
		}
392
		}
368
		QualifiedName name = qualifiedName;
393
		QualifiedName name = qualifiedName;
369
		if (this.resolveBindings) {
394
		if (resolveBindings()) {
370
			recordNodes(name, node);
395
			recordNodes(name, node);
371
			recordPendingNameScopeResolution(name);
396
			recordPendingNameScopeResolution(name);
372
		}
397
		}
Lines 384-390 Link Here
384
		}  else {
409
		}  else {
385
			ThisExpression thisExpression = this.ast.newThisExpression();
410
			ThisExpression thisExpression = this.ast.newThisExpression();
386
			thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
411
			thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
387
			if (this.resolveBindings) {
412
			if (resolveBindings()) {
388
				recordNodes(thisExpression, reference);
413
				recordNodes(thisExpression, reference);
389
				recordPendingThisExpressionScopeResolution(thisExpression);
414
				recordPendingThisExpressionScopeResolution(thisExpression);
390
			}
415
			}
Lines 396-402 Link Here
396
		ThisExpression thisExpression = this.ast.newThisExpression();
421
		ThisExpression thisExpression = this.ast.newThisExpression();
397
		thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
422
		thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
398
		thisExpression.setQualifier(convert(reference.qualification));
423
		thisExpression.setQualifier(convert(reference.qualification));
399
		if (this.resolveBindings) {
424
		if (resolveBindings()) {
400
			recordNodes(thisExpression, reference);
425
			recordNodes(thisExpression, reference);
401
			recordPendingThisExpressionScopeResolution(thisExpression);
426
			recordPendingThisExpressionScopeResolution(thisExpression);
402
		}
427
		}
Lines 409-415 Link Here
409
434
410
	public ArrayAccess convert(org.eclipse.jdt.internal.compiler.ast.ArrayReference reference) {
435
	public ArrayAccess convert(org.eclipse.jdt.internal.compiler.ast.ArrayReference reference) {
411
		ArrayAccess arrayAccess = this.ast.newArrayAccess();
436
		ArrayAccess arrayAccess = this.ast.newArrayAccess();
412
		if (this.resolveBindings) {
437
		if (resolveBindings()) {
413
			recordNodes(arrayAccess, reference);
438
			recordNodes(arrayAccess, reference);
414
		}
439
		}
415
		arrayAccess.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
440
		arrayAccess.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1);
Lines 421-433 Link Here
421
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.FieldReference reference) {
446
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.FieldReference reference) {
422
		if (reference.receiver.isSuper()) {
447
		if (reference.receiver.isSuper()) {
423
			SuperFieldAccess superFieldAccess = this.ast.newSuperFieldAccess();
448
			SuperFieldAccess superFieldAccess = this.ast.newSuperFieldAccess();
424
			if (this.resolveBindings) {
449
			if (resolveBindings()) {
425
				recordNodes(superFieldAccess, reference);
450
				recordNodes(superFieldAccess, reference);
426
			}
451
			}
427
			if (reference.receiver instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
452
			if (reference.receiver instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
428
				Name qualifier = convert((org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) reference.receiver);
453
				Name qualifier = convert((org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) reference.receiver);
429
				superFieldAccess.setQualifier(qualifier);
454
				superFieldAccess.setQualifier(qualifier);
430
				if (this.resolveBindings) {
455
				if (resolveBindings()) {
431
					recordNodes(qualifier, reference.receiver);
456
					recordNodes(qualifier, reference.receiver);
432
				}
457
				}
433
			}
458
			}
Lines 436-449 Link Here
436
			int length = (int)(reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
461
			int length = (int)(reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
437
			simpleName.setSourceRange(sourceStart, length);
462
			simpleName.setSourceRange(sourceStart, length);
438
			superFieldAccess.setName(simpleName);
463
			superFieldAccess.setName(simpleName);
439
			if (this.resolveBindings) {
464
			if (resolveBindings()) {
440
				recordNodes(simpleName, reference);
465
				recordNodes(simpleName, reference);
441
			}
466
			}
442
			superFieldAccess.setSourceRange(reference.receiver.sourceStart, reference.sourceEnd - reference.receiver.sourceStart + 1);
467
			superFieldAccess.setSourceRange(reference.receiver.sourceStart, reference.sourceEnd - reference.receiver.sourceStart + 1);
443
			return superFieldAccess;
468
			return superFieldAccess;
444
		} else {
469
		} else {
445
			FieldAccess fieldAccess = this.ast.newFieldAccess();
470
			FieldAccess fieldAccess = this.ast.newFieldAccess();
446
			if (this.resolveBindings) {
471
			if (resolveBindings()) {
447
				recordNodes(fieldAccess, reference);
472
				recordNodes(fieldAccess, reference);
448
			}
473
			}
449
			Expression receiver = convert(reference.receiver);
474
			Expression receiver = convert(reference.receiver);
Lines 453-459 Link Here
453
			int length = (int)(reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
478
			int length = (int)(reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
454
			simpleName.setSourceRange(sourceStart, length);
479
			simpleName.setSourceRange(sourceStart, length);
455
			fieldAccess.setName(simpleName);
480
			fieldAccess.setName(simpleName);
456
			if (this.resolveBindings) {
481
			if (resolveBindings()) {
457
				recordNodes(simpleName, reference);
482
				recordNodes(simpleName, reference);
458
			}
483
			}
459
			fieldAccess.setSourceRange(receiver.getStartPosition(), reference.sourceEnd - receiver.getStartPosition() + 1);
484
			fieldAccess.setSourceRange(receiver.getStartPosition(), reference.sourceEnd - receiver.getStartPosition() + 1);
Lines 519-525 Link Here
519
					PrimitiveType primitiveType = this.ast.newPrimitiveType(getPrimitiveTypeCode(name));
544
					PrimitiveType primitiveType = this.ast.newPrimitiveType(getPrimitiveTypeCode(name));
520
					primitiveType.setSourceRange(sourceStart, end - sourceStart + 1);
545
					primitiveType.setSourceRange(sourceStart, end - sourceStart + 1);
521
					type = this.ast.newArrayType(primitiveType, dimensions);
546
					type = this.ast.newArrayType(primitiveType, dimensions);
522
					if (resolveBindings) {
547
					if (resolveBindings()) {
523
						// store keys for inner types
548
						// store keys for inner types
524
						completeRecord((ArrayType) type, typeReference);
549
						completeRecord((ArrayType) type, typeReference);
525
					}
550
					}
Lines 537-543 Link Here
537
					simpleType.setSourceRange(sourceStart, end - sourceStart + 1);
562
					simpleType.setSourceRange(sourceStart, end - sourceStart + 1);
538
					type = this.ast.newArrayType(simpleType, dimensions);
563
					type = this.ast.newArrayType(simpleType, dimensions);
539
					type.setSourceRange(sourceStart, length);
564
					type.setSourceRange(sourceStart, length);
540
					if (this.resolveBindings) {
565
					if (resolveBindings()) {
541
						completeRecord((ArrayType) type, typeReference);
566
						completeRecord((ArrayType) type, typeReference);
542
						this.recordNodes(simpleName, typeReference);
567
						this.recordNodes(simpleName, typeReference);
543
					}
568
					}
Lines 551-557 Link Here
551
					simpleName.setSourceRange(sourceStart, length);
576
					simpleName.setSourceRange(sourceStart, length);
552
					type = this.ast.newSimpleType(simpleName);
577
					type = this.ast.newSimpleType(simpleName);
553
					type.setSourceRange(sourceStart, length);
578
					type.setSourceRange(sourceStart, length);
554
					if (this.resolveBindings) {
579
					if (resolveBindings()) {
555
						this.recordNodes(simpleName, typeReference);
580
						this.recordNodes(simpleName, typeReference);
556
					}
581
					}
557
				}
582
				}
Lines 568-574 Link Here
568
				SimpleType simpleType = this.ast.newSimpleType(qualifiedName);
593
				SimpleType simpleType = this.ast.newSimpleType(qualifiedName);
569
				simpleType.setSourceRange(sourceStart, length);
594
				simpleType.setSourceRange(sourceStart, length);
570
				type = this.ast.newArrayType(simpleType, dimensions);
595
				type = this.ast.newArrayType(simpleType, dimensions);
571
				if (this.resolveBindings) {
596
				if (resolveBindings()) {
572
					completeRecord((ArrayType) type, typeReference);
597
					completeRecord((ArrayType) type, typeReference);
573
				}				
598
				}				
574
				int end = retrieveEndOfDimensionsPosition(sourceStart+length, this.compilationUnitSource.length);
599
				int end = retrieveEndOfDimensionsPosition(sourceStart+length, this.compilationUnitSource.length);
Lines 582-588 Link Here
582
				type.setSourceRange(sourceStart, length);
607
				type.setSourceRange(sourceStart, length);
583
			}
608
			}
584
		}
609
		}
585
		if (this.resolveBindings) {
610
		if (resolveBindings()) {
586
			this.recordNodes(type, typeReference);
611
			this.recordNodes(type, typeReference);
587
		}
612
		}
588
		return type;
613
		return type;
Lines 716-723 Link Here
716
			}			
741
			}			
717
		}
742
		}
718
		
743
		
719
		setJavaDocComment(methodDecl);
744
		// The javadoc comment is now got from list store in compilation unit declaration
720
		if (this.resolveBindings) {
745
		// @see BodyDeclaration#getComment(int)
746
		//setJavaDocComment(methodDecl);
747
		if (resolveBindings()) {
721
			recordNodes(methodDecl, methodDeclaration);
748
			recordNodes(methodDecl, methodDeclaration);
722
			recordNodes(methodName, methodDeclaration);
749
			recordNodes(methodName, methodDeclaration);
723
			methodDecl.resolveBinding();
750
			methodDecl.resolveBinding();
Lines 831-837 Link Here
831
858
832
	public ParenthesizedExpression convertToParenthesizedExpression(org.eclipse.jdt.internal.compiler.ast.Expression expression) {
859
	public ParenthesizedExpression convertToParenthesizedExpression(org.eclipse.jdt.internal.compiler.ast.Expression expression) {
833
		ParenthesizedExpression parenthesizedExpression = this.ast.newParenthesizedExpression();
860
		ParenthesizedExpression parenthesizedExpression = this.ast.newParenthesizedExpression();
834
		if (this.resolveBindings) {
861
		if (resolveBindings()) {
835
			recordNodes(parenthesizedExpression, expression);
862
			recordNodes(parenthesizedExpression, expression);
836
		}
863
		}
837
		parenthesizedExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
864
		parenthesizedExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 847-853 Link Here
847
	
874
	
848
	public ClassInstanceCreation convert(org.eclipse.jdt.internal.compiler.ast.AllocationExpression expression) {
875
	public ClassInstanceCreation convert(org.eclipse.jdt.internal.compiler.ast.AllocationExpression expression) {
849
		ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
876
		ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
850
		if (this.resolveBindings) {
877
		if (resolveBindings()) {
851
			recordNodes(classInstanceCreation, expression);
878
			recordNodes(classInstanceCreation, expression);
852
		}
879
		}
853
		classInstanceCreation.setName(convert(expression.type));
880
		classInstanceCreation.setName(convert(expression.type));
Lines 926-932 Link Here
926
953
927
	public ArrayCreation convert(org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression expression) {
954
	public ArrayCreation convert(org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression expression) {
928
		ArrayCreation arrayCreation = this.ast.newArrayCreation();
955
		ArrayCreation arrayCreation = this.ast.newArrayCreation();
929
		if (this.resolveBindings) {
956
		if (resolveBindings()) {
930
			recordNodes(arrayCreation, expression);
957
			recordNodes(arrayCreation, expression);
931
		}
958
		}
932
		arrayCreation.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
959
		arrayCreation.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 936-949 Link Here
936
		for (int i = 0; i < dimensionsLength; i++) {
963
		for (int i = 0; i < dimensionsLength; i++) {
937
			if (dimensions[i] != null) {
964
			if (dimensions[i] != null) {
938
				Expression dimension = convert(dimensions[i]);
965
				Expression dimension = convert(dimensions[i]);
939
				if (this.resolveBindings) {
966
				if (resolveBindings()) {
940
					recordNodes(dimension, dimensions[i]);
967
					recordNodes(dimension, dimensions[i]);
941
				}
968
				}
942
				arrayCreation.dimensions().add(dimension);
969
				arrayCreation.dimensions().add(dimension);
943
			}
970
			}
944
		}
971
		}
945
		Type type = convertType(expression.type);
972
		Type type = convertType(expression.type);
946
		if (this.resolveBindings) {
973
		if (resolveBindings()) {
947
			recordNodes(type, expression.type);
974
			recordNodes(type, expression.type);
948
		}		
975
		}		
949
		ArrayType arrayType = null;
976
		ArrayType arrayType = null;
Lines 951-957 Link Here
951
			arrayType = (ArrayType) type;
978
			arrayType = (ArrayType) type;
952
		} else {
979
		} else {
953
			arrayType = this.ast.newArrayType(type, dimensionsLength);
980
			arrayType = this.ast.newArrayType(type, dimensionsLength);
954
			if (this.resolveBindings) {
981
			if (resolveBindings()) {
955
				completeRecord(arrayType, expression);
982
				completeRecord(arrayType, expression);
956
			}			
983
			}			
957
			int start = type.getStartPosition();
984
			int start = type.getStartPosition();
Lines 965-971 Link Here
965
			}
992
			}
966
		}
993
		}
967
		arrayCreation.setType(arrayType);
994
		arrayCreation.setType(arrayType);
968
		if (this.resolveBindings) {
995
		if (resolveBindings()) {
969
			recordNodes(arrayType, expression);
996
			recordNodes(arrayType, expression);
970
		}	
997
		}	
971
		if (expression.initializer != null) {
998
		if (expression.initializer != null) {
Lines 1008-1014 Link Here
1008
		 */
1035
		 */
1009
		setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions);
1036
		setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions);
1010
		variableDecl.setSourceRange(argument.declarationSourceStart, rightEnd - argument.declarationSourceStart + 1);
1037
		variableDecl.setSourceRange(argument.declarationSourceStart, rightEnd - argument.declarationSourceStart + 1);
1011
		if (this.resolveBindings) {
1038
		if (resolveBindings()) {
1012
			recordNodes(name, argument);
1039
			recordNodes(name, argument);
1013
			recordNodes(variableDecl, argument);
1040
			recordNodes(variableDecl, argument);
1014
			variableDecl.resolveBinding();
1041
			variableDecl.resolveBinding();
Lines 1018-1024 Link Here
1018
1045
1019
	public ArrayInitializer convert(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer expression) {
1046
	public ArrayInitializer convert(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer expression) {
1020
		ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
1047
		ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
1021
		if (this.resolveBindings) {
1048
		if (resolveBindings()) {
1022
			recordNodes(arrayInitializer, expression);
1049
			recordNodes(arrayInitializer, expression);
1023
		}
1050
		}
1024
		arrayInitializer.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1051
		arrayInitializer.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1027-1033 Link Here
1027
			int length = expressions.length;
1054
			int length = expressions.length;
1028
			for (int i = 0; i < length; i++) {
1055
			for (int i = 0; i < length; i++) {
1029
				Expression expr = convert(expressions[i]);
1056
				Expression expr = convert(expressions[i]);
1030
				if (this.resolveBindings) {
1057
				if (resolveBindings()) {
1031
					recordNodes(expr, expressions[i]);
1058
					recordNodes(expr, expressions[i]);
1032
				}
1059
				}
1033
				arrayInitializer.expressions().add(expr);
1060
				arrayInitializer.expressions().add(expr);
Lines 1057-1063 Link Here
1057
			anonymousClassDeclaration.setSourceRange(start, allocation.anonymousType.bodyEnd - start + 1);
1084
			anonymousClassDeclaration.setSourceRange(start, allocation.anonymousType.bodyEnd - start + 1);
1058
			classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
1085
			classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
1059
			buildBodyDeclarations(allocation.anonymousType, anonymousClassDeclaration);
1086
			buildBodyDeclarations(allocation.anonymousType, anonymousClassDeclaration);
1060
			if (this.resolveBindings) {
1087
			if (resolveBindings()) {
1061
				recordNodes(classInstanceCreation, allocation.anonymousType);
1088
				recordNodes(classInstanceCreation, allocation.anonymousType);
1062
				recordNodes(anonymousClassDeclaration, allocation.anonymousType);
1089
				recordNodes(anonymousClassDeclaration, allocation.anonymousType);
1063
				anonymousClassDeclaration.resolveBinding();
1090
				anonymousClassDeclaration.resolveBinding();
Lines 1073-1085 Link Here
1073
				int length = arguments.length;
1100
				int length = arguments.length;
1074
				for (int i = 0; i < length; i++) {
1101
				for (int i = 0; i < length; i++) {
1075
					Expression argument = convert(arguments[i]);
1102
					Expression argument = convert(arguments[i]);
1076
					if (this.resolveBindings) {
1103
					if (resolveBindings()) {
1077
						recordNodes(argument, arguments[i]);
1104
						recordNodes(argument, arguments[i]);
1078
					}
1105
					}
1079
					classInstanceCreation.arguments().add(argument);
1106
					classInstanceCreation.arguments().add(argument);
1080
				}
1107
				}
1081
			}
1108
			}
1082
			if (this.resolveBindings) {
1109
			if (resolveBindings()) {
1083
				recordNodes(classInstanceCreation, allocation);
1110
				recordNodes(classInstanceCreation, allocation);
1084
			}
1111
			}
1085
			removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
1112
			removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
Lines 1089-1095 Link Here
1089
	
1116
	
1090
	public Assignment convert(org.eclipse.jdt.internal.compiler.ast.Assignment expression) {
1117
	public Assignment convert(org.eclipse.jdt.internal.compiler.ast.Assignment expression) {
1091
		Assignment assignment = this.ast.newAssignment();
1118
		Assignment assignment = this.ast.newAssignment();
1092
		if (this.resolveBindings) {
1119
		if (resolveBindings()) {
1093
			recordNodes(assignment, expression);
1120
			recordNodes(assignment, expression);
1094
		}
1121
		}
1095
		Expression lhs = convert(expression.lhs);
1122
		Expression lhs = convert(expression.lhs);
Lines 1148-1154 Link Here
1148
1175
1149
	public PrefixExpression convert(org.eclipse.jdt.internal.compiler.ast.PrefixExpression expression) {
1176
	public PrefixExpression convert(org.eclipse.jdt.internal.compiler.ast.PrefixExpression expression) {
1150
		PrefixExpression prefixExpression = this.ast.newPrefixExpression();
1177
		PrefixExpression prefixExpression = this.ast.newPrefixExpression();
1151
		if (this.resolveBindings) {
1178
		if (resolveBindings()) {
1152
			recordNodes(prefixExpression, expression);
1179
			recordNodes(prefixExpression, expression);
1153
		}
1180
		}
1154
		prefixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1181
		prefixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1166-1172 Link Here
1166
1193
1167
	public PostfixExpression convert(org.eclipse.jdt.internal.compiler.ast.PostfixExpression expression) {
1194
	public PostfixExpression convert(org.eclipse.jdt.internal.compiler.ast.PostfixExpression expression) {
1168
		PostfixExpression postfixExpression = this.ast.newPostfixExpression();
1195
		PostfixExpression postfixExpression = this.ast.newPostfixExpression();
1169
		if (this.resolveBindings) {
1196
		if (resolveBindings()) {
1170
			recordNodes(postfixExpression, expression);
1197
			recordNodes(postfixExpression, expression);
1171
		}
1198
		}
1172
		postfixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1199
		postfixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1193-1199 Link Here
1193
			castExpression.setType(convertToType((org.eclipse.jdt.internal.compiler.ast.NameReference)type));
1220
			castExpression.setType(convertToType((org.eclipse.jdt.internal.compiler.ast.NameReference)type));
1194
		}
1221
		}
1195
		castExpression.setExpression(convert(expression.expression));
1222
		castExpression.setExpression(convert(expression.expression));
1196
		if (this.resolveBindings) {
1223
		if (resolveBindings()) {
1197
			recordNodes(castExpression, expression);
1224
			recordNodes(castExpression, expression);
1198
		}
1225
		}
1199
		return castExpression;
1226
		return castExpression;
Lines 1203-1216 Link Here
1203
		Name name = convert(reference);
1230
		Name name = convert(reference);
1204
		SimpleType type = this.ast.newSimpleType(name);
1231
		SimpleType type = this.ast.newSimpleType(name);
1205
		type.setSourceRange(name.getStartPosition(), name.getLength());
1232
		type.setSourceRange(name.getStartPosition(), name.getLength());
1206
		if (this.resolveBindings) {
1233
		if (resolveBindings()) {
1207
			this.recordNodes(type, reference);
1234
			this.recordNodes(type, reference);
1208
		}
1235
		}
1209
		return type;
1236
		return type;
1210
	}
1237
	}
1211
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess expression) {
1238
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess expression) {
1212
		TypeLiteral typeLiteral = this.ast.newTypeLiteral();
1239
		TypeLiteral typeLiteral = this.ast.newTypeLiteral();
1213
		if (this.resolveBindings) {
1240
		if (resolveBindings()) {
1214
			this.recordNodes(typeLiteral, expression);
1241
			this.recordNodes(typeLiteral, expression);
1215
		}
1242
		}
1216
		typeLiteral.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1243
		typeLiteral.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1220-1226 Link Here
1220
1247
1221
	public BooleanLiteral convert(org.eclipse.jdt.internal.compiler.ast.FalseLiteral expression) {
1248
	public BooleanLiteral convert(org.eclipse.jdt.internal.compiler.ast.FalseLiteral expression) {
1222
		BooleanLiteral literal = this.ast.newBooleanLiteral(false);
1249
		BooleanLiteral literal = this.ast.newBooleanLiteral(false);
1223
		if (this.resolveBindings) {
1250
		if (resolveBindings()) {
1224
			this.recordNodes(literal, expression);
1251
			this.recordNodes(literal, expression);
1225
		}
1252
		}
1226
		literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1253
		literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1229-1235 Link Here
1229
		
1256
		
1230
	public BooleanLiteral convert(org.eclipse.jdt.internal.compiler.ast.TrueLiteral expression) {
1257
	public BooleanLiteral convert(org.eclipse.jdt.internal.compiler.ast.TrueLiteral expression) {
1231
		BooleanLiteral literal = this.ast.newBooleanLiteral(true);
1258
		BooleanLiteral literal = this.ast.newBooleanLiteral(true);
1232
		if (this.resolveBindings) {
1259
		if (resolveBindings()) {
1233
			this.recordNodes(literal, expression);
1260
			this.recordNodes(literal, expression);
1234
		}
1261
		}
1235
		literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1262
		literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1238-1244 Link Here
1238
	
1265
	
1239
	public org.eclipse.jdt.core.dom.NullLiteral convert(org.eclipse.jdt.internal.compiler.ast.NullLiteral expression) {
1266
	public org.eclipse.jdt.core.dom.NullLiteral convert(org.eclipse.jdt.internal.compiler.ast.NullLiteral expression) {
1240
		org.eclipse.jdt.core.dom.NullLiteral literal = this.ast.newNullLiteral();
1267
		org.eclipse.jdt.core.dom.NullLiteral literal = this.ast.newNullLiteral();
1241
		if (this.resolveBindings) {
1268
		if (resolveBindings()) {
1242
			this.recordNodes(literal, expression);
1269
			this.recordNodes(literal, expression);
1243
		}
1270
		}
1244
		literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1271
		literal.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1251-1257 Link Here
1251
		char[] tokens = new char[length];
1278
		char[] tokens = new char[length];
1252
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1279
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1253
		CharacterLiteral literal = this.ast.newCharacterLiteral();
1280
		CharacterLiteral literal = this.ast.newCharacterLiteral();
1254
		if (this.resolveBindings) {
1281
		if (resolveBindings()) {
1255
			this.recordNodes(literal, expression);
1282
			this.recordNodes(literal, expression);
1256
		}
1283
		}
1257
		literal.setEscapedValue(new String(tokens));
1284
		literal.setEscapedValue(new String(tokens));
Lines 1266-1272 Link Here
1266
		char[] tokens = new char[length];
1293
		char[] tokens = new char[length];
1267
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1294
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1268
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1295
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1269
		if (this.resolveBindings) {
1296
		if (resolveBindings()) {
1270
			this.recordNodes(literal, expression);
1297
			this.recordNodes(literal, expression);
1271
		}
1298
		}
1272
		literal.setSourceRange(sourceStart, length);
1299
		literal.setSourceRange(sourceStart, length);
Lines 1280-1286 Link Here
1280
		char[] tokens = new char[length];
1307
		char[] tokens = new char[length];
1281
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1308
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1282
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1309
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1283
		if (this.resolveBindings) {
1310
		if (resolveBindings()) {
1284
			this.recordNodes(literal, expression);
1311
			this.recordNodes(literal, expression);
1285
		}
1312
		}
1286
		literal.setSourceRange(sourceStart, length);
1313
		literal.setSourceRange(sourceStart, length);
Lines 1294-1300 Link Here
1294
		char[] tokens = new char[length];
1321
		char[] tokens = new char[length];
1295
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1322
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1296
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1323
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1297
		if (this.resolveBindings) {
1324
		if (resolveBindings()) {
1298
			this.recordNodes(literal, expression);
1325
			this.recordNodes(literal, expression);
1299
		}
1326
		}
1300
		literal.setSourceRange(sourceStart, length);
1327
		literal.setSourceRange(sourceStart, length);
Lines 1308-1314 Link Here
1308
		char[] tokens = new char[length];
1335
		char[] tokens = new char[length];
1309
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1336
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1310
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1337
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1311
		if (this.resolveBindings) {
1338
		if (resolveBindings()) {
1312
			this.recordNodes(literal, expression);
1339
			this.recordNodes(literal, expression);
1313
		}
1340
		}
1314
		literal.setSourceRange(sourceStart, length);
1341
		literal.setSourceRange(sourceStart, length);
Lines 1322-1328 Link Here
1322
		char[] tokens = new char[length];
1349
		char[] tokens = new char[length];
1323
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1350
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1324
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1351
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1325
		if (this.resolveBindings) {
1352
		if (resolveBindings()) {
1326
			this.recordNodes(literal, expression);
1353
			this.recordNodes(literal, expression);
1327
		}
1354
		}
1328
		literal.setSourceRange(sourceStart, length);
1355
		literal.setSourceRange(sourceStart, length);
Lines 1336-1342 Link Here
1336
		char[] tokens = new char[length];
1363
		char[] tokens = new char[length];
1337
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1364
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1338
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1365
		NumberLiteral literal = this.ast.newNumberLiteral(new String(tokens));
1339
		if (this.resolveBindings) {
1366
		if (resolveBindings()) {
1340
			this.recordNodes(literal, expression);
1367
			this.recordNodes(literal, expression);
1341
		}
1368
		}
1342
		literal.setSourceRange(sourceStart, length);
1369
		literal.setSourceRange(sourceStart, length);
Lines 1350-1356 Link Here
1350
		char[] tokens = new char[length];
1377
		char[] tokens = new char[length];
1351
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1378
		System.arraycopy(this.compilationUnitSource, sourceStart, tokens, 0, length);
1352
		StringLiteral literal = this.ast.newStringLiteral();
1379
		StringLiteral literal = this.ast.newStringLiteral();
1353
		if (this.resolveBindings) {
1380
		if (resolveBindings()) {
1354
			this.recordNodes(literal, expression);
1381
			this.recordNodes(literal, expression);
1355
		}
1382
		}
1356
		literal.setEscapedValue(new String(tokens));
1383
		literal.setEscapedValue(new String(tokens));
Lines 1361-1367 Link Here
1361
	public StringLiteral convert(org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral expression) {
1388
	public StringLiteral convert(org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral expression) {
1362
		expression.computeConstant();
1389
		expression.computeConstant();
1363
		StringLiteral literal = this.ast.newStringLiteral();
1390
		StringLiteral literal = this.ast.newStringLiteral();
1364
		if (this.resolveBindings) {
1391
		if (resolveBindings()) {
1365
			this.recordNodes(literal, expression);
1392
			this.recordNodes(literal, expression);
1366
		}
1393
		}
1367
		literal.setLiteralValue(expression.constant.stringValue());
1394
		literal.setLiteralValue(expression.constant.stringValue());
Lines 1371-1377 Link Here
1371
	
1398
	
1372
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.BinaryExpression expression) {
1399
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.BinaryExpression expression) {
1373
		InfixExpression infixExpression = this.ast.newInfixExpression();
1400
		InfixExpression infixExpression = this.ast.newInfixExpression();
1374
		if (this.resolveBindings) {
1401
		if (resolveBindings()) {
1375
			this.recordNodes(infixExpression, expression);
1402
			this.recordNodes(infixExpression, expression);
1376
		}
1403
		}
1377
1404
Lines 1446-1452 Link Here
1446
				 || ((rightOperand instanceof org.eclipse.jdt.internal.compiler.ast.BinaryExpression && ((rightOperand.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorMASK) >> org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorSHIFT) != expressionOperatorID) && ((rightOperand.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0))) {
1473
				 || ((rightOperand instanceof org.eclipse.jdt.internal.compiler.ast.BinaryExpression && ((rightOperand.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorMASK) >> org.eclipse.jdt.internal.compiler.ast.ASTNode.OperatorSHIFT) != expressionOperatorID) && ((rightOperand.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) == 0))) {
1447
				 	List extendedOperands = infixExpression.extendedOperands();
1474
				 	List extendedOperands = infixExpression.extendedOperands();
1448
				 	InfixExpression temp = this.ast.newInfixExpression();
1475
				 	InfixExpression temp = this.ast.newInfixExpression();
1449
					if (this.resolveBindings) {
1476
					if (resolveBindings()) {
1450
						this.recordNodes(temp, expression);
1477
						this.recordNodes(temp, expression);
1451
					}
1478
					}
1452
				 	temp.setOperator(getOperatorFor(expressionOperatorID));
1479
				 	temp.setOperator(getOperatorFor(expressionOperatorID));
Lines 1458-1464 Link Here
1458
				 		Expression expr = temp;
1485
				 		Expression expr = temp;
1459
				 		temp = this.ast.newInfixExpression();
1486
				 		temp = this.ast.newInfixExpression();
1460
				 		
1487
				 		
1461
						if (this.resolveBindings) {
1488
						if (resolveBindings()) {
1462
							this.recordNodes(temp, expression);
1489
							this.recordNodes(temp, expression);
1463
						}				 	
1490
						}				 	
1464
				 		temp.setLeftOperand(expr);
1491
				 		temp.setLeftOperand(expr);
Lines 1477-1483 Link Here
1477
				 	}
1504
				 	}
1478
					int startPosition = infixExpression.getLeftOperand().getStartPosition();
1505
					int startPosition = infixExpression.getLeftOperand().getStartPosition();
1479
					infixExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
1506
					infixExpression.setSourceRange(startPosition, expression.sourceEnd - startPosition + 1);
1480
					if (this.resolveBindings) {
1507
					if (resolveBindings()) {
1481
						this.recordNodes(infixExpression, expression);
1508
						this.recordNodes(infixExpression, expression);
1482
					}
1509
					}
1483
					return infixExpression;
1510
					return infixExpression;
Lines 1502-1508 Link Here
1502
			
1529
			
1503
	public PrefixExpression convert(org.eclipse.jdt.internal.compiler.ast.UnaryExpression expression) {
1530
	public PrefixExpression convert(org.eclipse.jdt.internal.compiler.ast.UnaryExpression expression) {
1504
		PrefixExpression prefixExpression = this.ast.newPrefixExpression();
1531
		PrefixExpression prefixExpression = this.ast.newPrefixExpression();
1505
		if (this.resolveBindings) {
1532
		if (resolveBindings()) {
1506
			this.recordNodes(prefixExpression, expression);
1533
			this.recordNodes(prefixExpression, expression);
1507
		}
1534
		}
1508
		prefixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1535
		prefixExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1525-1531 Link Here
1525
	
1552
	
1526
	public InstanceofExpression convert(org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression expression) {
1553
	public InstanceofExpression convert(org.eclipse.jdt.internal.compiler.ast.InstanceOfExpression expression) {
1527
		InstanceofExpression instanceOfExpression = this.ast.newInstanceofExpression();
1554
		InstanceofExpression instanceOfExpression = this.ast.newInstanceofExpression();
1528
		if (this.resolveBindings) {
1555
		if (resolveBindings()) {
1529
			recordNodes(instanceOfExpression, expression);
1556
			recordNodes(instanceOfExpression, expression);
1530
		}
1557
		}
1531
		Expression leftExpression = convert(expression.expression);
1558
		Expression leftExpression = convert(expression.expression);
Lines 1538-1544 Link Here
1538
1565
1539
	public ConditionalExpression convert(org.eclipse.jdt.internal.compiler.ast.ConditionalExpression expression) {
1566
	public ConditionalExpression convert(org.eclipse.jdt.internal.compiler.ast.ConditionalExpression expression) {
1540
		ConditionalExpression conditionalExpression = this.ast.newConditionalExpression();
1567
		ConditionalExpression conditionalExpression = this.ast.newConditionalExpression();
1541
		if (this.resolveBindings) {
1568
		if (resolveBindings()) {
1542
			recordNodes(conditionalExpression, expression);
1569
			recordNodes(conditionalExpression, expression);
1543
		}
1570
		}
1544
		conditionalExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
1571
		conditionalExpression.setSourceRange(expression.sourceStart, expression.sourceEnd - expression.sourceStart + 1);
Lines 1555-1568 Link Here
1555
		if (expression.isSuperAccess()) {
1582
		if (expression.isSuperAccess()) {
1556
			// returns a SuperMethodInvocation
1583
			// returns a SuperMethodInvocation
1557
			SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation();
1584
			SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation();
1558
			if (this.resolveBindings) {
1585
			if (resolveBindings()) {
1559
				recordNodes(superMethodInvocation, expression);
1586
				recordNodes(superMethodInvocation, expression);
1560
			}
1587
			}
1561
			SimpleName name = this.ast.newSimpleName(new String(expression.selector));
1588
			SimpleName name = this.ast.newSimpleName(new String(expression.selector));
1562
			int nameSourceStart =  (int) (expression.nameSourcePosition >>> 32);
1589
			int nameSourceStart =  (int) (expression.nameSourcePosition >>> 32);
1563
			int nameSourceLength = (int)(expression.nameSourcePosition & 0xFFFFFFFF) - nameSourceStart + 1;
1590
			int nameSourceLength = (int)(expression.nameSourcePosition & 0xFFFFFFFF) - nameSourceStart + 1;
1564
			name.setSourceRange(nameSourceStart, nameSourceLength);
1591
			name.setSourceRange(nameSourceStart, nameSourceLength);
1565
			if (this.resolveBindings) {
1592
			if (resolveBindings()) {
1566
				recordNodes(name, expression);
1593
				recordNodes(name, expression);
1567
			}
1594
			}
1568
			superMethodInvocation.setName(name);
1595
			superMethodInvocation.setName(name);
Lines 1571-1577 Link Here
1571
			if (expression.receiver instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
1598
			if (expression.receiver instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
1572
				Name qualifier = convert((org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) expression.receiver);
1599
				Name qualifier = convert((org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) expression.receiver);
1573
				superMethodInvocation.setQualifier(qualifier);
1600
				superMethodInvocation.setQualifier(qualifier);
1574
				if (this.resolveBindings) {
1601
				if (resolveBindings()) {
1575
					recordNodes(qualifier, expression.receiver);
1602
					recordNodes(qualifier, expression.receiver);
1576
				}
1603
				}
1577
				if (qualifier != null) {
1604
				if (qualifier != null) {
Lines 1583-1589 Link Here
1583
				int argumentsLength = arguments.length;
1610
				int argumentsLength = arguments.length;
1584
				for (int i = 0; i < argumentsLength; i++) {
1611
				for (int i = 0; i < argumentsLength; i++) {
1585
					Expression expri = convert(arguments[i]);
1612
					Expression expri = convert(arguments[i]);
1586
					if (this.resolveBindings) {
1613
					if (resolveBindings()) {
1587
						recordNodes(expri, arguments[i]);
1614
						recordNodes(expri, arguments[i]);
1588
					}
1615
					}
1589
					superMethodInvocation.arguments().add(expri);
1616
					superMethodInvocation.arguments().add(expri);
Lines 1593-1599 Link Here
1593
		} else {
1620
		} else {
1594
			// returns a MethodInvocation
1621
			// returns a MethodInvocation
1595
			MethodInvocation methodInvocation = this.ast.newMethodInvocation();
1622
			MethodInvocation methodInvocation = this.ast.newMethodInvocation();
1596
			if (this.resolveBindings) {
1623
			if (resolveBindings()) {
1597
				recordNodes(methodInvocation, expression);
1624
				recordNodes(methodInvocation, expression);
1598
			}
1625
			}
1599
			SimpleName name = this.ast.newSimpleName(new String(expression.selector));
1626
			SimpleName name = this.ast.newSimpleName(new String(expression.selector));
Lines 1601-1607 Link Here
1601
			int nameSourceLength = (int)(expression.nameSourcePosition & 0xFFFFFFFF) - nameSourceStart + 1;
1628
			int nameSourceLength = (int)(expression.nameSourcePosition & 0xFFFFFFFF) - nameSourceStart + 1;
1602
			name.setSourceRange(nameSourceStart, nameSourceLength);
1629
			name.setSourceRange(nameSourceStart, nameSourceLength);
1603
			methodInvocation.setName(name);
1630
			methodInvocation.setName(name);
1604
			if (this.resolveBindings) {
1631
			if (resolveBindings()) {
1605
				recordNodes(name, expression);
1632
				recordNodes(name, expression);
1606
			}
1633
			}
1607
			org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = expression.arguments;
1634
			org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = expression.arguments;
Lines 1609-1622 Link Here
1609
				int argumentsLength = arguments.length;
1636
				int argumentsLength = arguments.length;
1610
				for (int i = 0; i < argumentsLength; i++) {
1637
				for (int i = 0; i < argumentsLength; i++) {
1611
					Expression expri = convert(arguments[i]);
1638
					Expression expri = convert(arguments[i]);
1612
					if (this.resolveBindings) {
1639
					if (resolveBindings()) {
1613
						recordNodes(expri, arguments[i]);
1640
						recordNodes(expri, arguments[i]);
1614
					}
1641
					}
1615
					methodInvocation.arguments().add(expri);
1642
					methodInvocation.arguments().add(expri);
1616
				}
1643
				}
1617
			}
1644
			}
1618
			Expression qualifier = convert(expression.receiver);
1645
			Expression qualifier = convert(expression.receiver);
1619
			if (qualifier instanceof Name && this.resolveBindings) {
1646
			if (qualifier instanceof Name && resolveBindings()) {
1620
				recordNodes(qualifier, expression.receiver);
1647
				recordNodes(qualifier, expression.receiver);
1621
			}
1648
			}
1622
			methodInvocation.setExpression(qualifier);
1649
			methodInvocation.setExpression(qualifier);
Lines 1632-1638 Link Here
1632
1659
1633
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression expression) {
1660
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression expression) {
1634
		InfixExpression infixExpression = this.ast.newInfixExpression();
1661
		InfixExpression infixExpression = this.ast.newInfixExpression();
1635
		if (this.resolveBindings) {
1662
		if (resolveBindings()) {
1636
			recordNodes(infixExpression, expression);
1663
			recordNodes(infixExpression, expression);
1637
		}
1664
		}
1638
		Expression leftExpression = convert(expression.left);
1665
		Expression leftExpression = convert(expression.left);
Lines 1647-1653 Link Here
1647
	
1674
	
1648
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.EqualExpression expression) {
1675
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.EqualExpression expression) {
1649
		InfixExpression infixExpression = this.ast.newInfixExpression();
1676
		InfixExpression infixExpression = this.ast.newInfixExpression();
1650
		if (this.resolveBindings) {
1677
		if (resolveBindings()) {
1651
			recordNodes(infixExpression, expression);
1678
			recordNodes(infixExpression, expression);
1652
		}
1679
		}
1653
		Expression leftExpression = convert(expression.left);
1680
		Expression leftExpression = convert(expression.left);
Lines 1668-1674 Link Here
1668
1695
1669
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression expression) {
1696
	public Expression convert(org.eclipse.jdt.internal.compiler.ast.OR_OR_Expression expression) {
1670
		InfixExpression infixExpression = this.ast.newInfixExpression();
1697
		InfixExpression infixExpression = this.ast.newInfixExpression();
1671
		if (this.resolveBindings) {
1698
		if (resolveBindings()) {
1672
			recordNodes(infixExpression, expression);
1699
			recordNodes(infixExpression, expression);
1673
		}
1700
		}
1674
		Expression leftExpression = convert(expression.left);
1701
		Expression leftExpression = convert(expression.left);
Lines 1873-1879 Link Here
1873
		}
1900
		}
1874
		newStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
1901
		newStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
1875
		retrieveSemiColonPosition(newStatement);
1902
		retrieveSemiColonPosition(newStatement);
1876
		if (this.resolveBindings) {
1903
		if (resolveBindings()) {
1877
			recordNodes(newStatement, statement);
1904
			recordNodes(newStatement, statement);
1878
		}
1905
		}
1879
		return newStatement;
1906
		return newStatement;
Lines 2610-2616 Link Here
2610
			variableDeclarationFragment.setInitializer(convert(fieldDeclaration.initialization));
2637
			variableDeclarationFragment.setInitializer(convert(fieldDeclaration.initialization));
2611
		}
2638
		}
2612
		variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(fieldDeclaration.sourceEnd + 1, fieldDeclaration.declarationSourceEnd ));
2639
		variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(fieldDeclaration.sourceEnd + 1, fieldDeclaration.declarationSourceEnd ));
2613
		if (this.resolveBindings) {
2640
		if (resolveBindings()) {
2614
			recordNodes(name, fieldDeclaration);
2641
			recordNodes(name, fieldDeclaration);
2615
			recordNodes(variableDeclarationFragment, fieldDeclaration);
2642
			recordNodes(variableDeclarationFragment, fieldDeclaration);
2616
			variableDeclarationFragment.resolveBinding();
2643
			variableDeclarationFragment.resolveBinding();
Lines 2637-2643 Link Here
2637
			variableDeclarationFragment.setInitializer(convert(localDeclaration.initialization));
2664
			variableDeclarationFragment.setInitializer(convert(localDeclaration.initialization));
2638
		}
2665
		}
2639
		variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(localDeclaration.sourceEnd + 1, this.compilationUnitSource.length));
2666
		variableDeclarationFragment.setExtraDimensions(retrieveExtraDimension(localDeclaration.sourceEnd + 1, this.compilationUnitSource.length));
2640
		if (this.resolveBindings) {
2667
		if (resolveBindings()) {
2641
			recordNodes(variableDeclarationFragment, localDeclaration);
2668
			recordNodes(variableDeclarationFragment, localDeclaration);
2642
			recordNodes(name, localDeclaration);
2669
			recordNodes(name, localDeclaration);
2643
			variableDeclarationFragment.resolveBinding();
2670
			variableDeclarationFragment.resolveBinding();
Lines 2648-2654 Link Here
2648
	private FieldDeclaration convertToFieldDeclaration(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDecl) {
2675
	private FieldDeclaration convertToFieldDeclaration(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration fieldDecl) {
2649
		VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(fieldDecl);
2676
		VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(fieldDecl);
2650
		FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(variableDeclarationFragment);
2677
		FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(variableDeclarationFragment);
2651
		if (this.resolveBindings) {
2678
		if (resolveBindings()) {
2652
			recordNodes(variableDeclarationFragment, fieldDecl);
2679
			recordNodes(variableDeclarationFragment, fieldDecl);
2653
			variableDeclarationFragment.resolveBinding();
2680
			variableDeclarationFragment.resolveBinding();
2654
		}
2681
		}
Lines 2669-2682 Link Here
2669
			fieldDeclaration.setModifiers(fieldDecl.modifiers & legalModifiers);
2696
			fieldDeclaration.setModifiers(fieldDecl.modifiers & legalModifiers);
2670
			fieldDeclaration.setFlags(ASTNode.MALFORMED);
2697
			fieldDeclaration.setFlags(ASTNode.MALFORMED);
2671
		}
2698
		}
2672
		setJavaDocComment(fieldDeclaration);
2699
		// The javadoc comment is now got from list store in compilation unit declaration
2700
		// @see BodyDeclaration#getComment(int)
2701
		//setJavaDocComment(fieldDeclaration);
2673
		return fieldDeclaration;
2702
		return fieldDeclaration;
2674
	}
2703
	}
2675
2704
2676
	private VariableDeclarationStatement convertToVariableDeclarationStatement(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
2705
	private VariableDeclarationStatement convertToVariableDeclarationStatement(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
2677
		VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration);
2706
		VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration);
2678
		VariableDeclarationStatement variableDeclarationStatement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
2707
		VariableDeclarationStatement variableDeclarationStatement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
2679
		if (this.resolveBindings) {
2708
		if (resolveBindings()) {
2680
			recordNodes(variableDeclarationFragment, localDeclaration);
2709
			recordNodes(variableDeclarationFragment, localDeclaration);
2681
		}
2710
		}
2682
		variableDeclarationStatement.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd - localDeclaration.declarationSourceStart + 1);
2711
		variableDeclarationStatement.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd - localDeclaration.declarationSourceStart + 1);
Lines 2700-2706 Link Here
2700
	private VariableDeclarationExpression convertToVariableDeclarationExpression(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
2729
	private VariableDeclarationExpression convertToVariableDeclarationExpression(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration) {
2701
		VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration);
2730
		VariableDeclarationFragment variableDeclarationFragment = convertToVariableDeclarationFragment(localDeclaration);
2702
		VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
2731
		VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
2703
		if (this.resolveBindings) {
2732
		if (resolveBindings()) {
2704
			recordNodes(variableDeclarationFragment, localDeclaration);
2733
			recordNodes(variableDeclarationFragment, localDeclaration);
2705
		}
2734
		}
2706
		variableDeclarationExpression.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd - localDeclaration.declarationSourceStart + 1);
2735
		variableDeclarationExpression.setSourceRange(localDeclaration.declarationSourceStart, localDeclaration.declarationSourceEnd - localDeclaration.declarationSourceStart + 1);
Lines 2918-2923 Link Here
2918
		}
2947
		}
2919
	}
2948
	}
2920
	
2949
	
2950
	/*
2921
	private void setJavaDocComment(BodyDeclaration bodyDeclaration) {
2951
	private void setJavaDocComment(BodyDeclaration bodyDeclaration) {
2922
		scanner.resetTo(bodyDeclaration.getStartPosition(), bodyDeclaration.getStartPosition() + bodyDeclaration.getLength());
2952
		scanner.resetTo(bodyDeclaration.getStartPosition(), bodyDeclaration.getStartPosition() + bodyDeclaration.getLength());
2923
		try {
2953
		try {
Lines 2942-2948 Link Here
2942
			// ignore
2972
			// ignore
2943
		}
2973
		}
2944
	}
2974
	}
2945
	
2975
	*/
2976
	private Comment createComment(int[] positions) {
2977
		// Create comment node
2978
		Comment comment = null;
2979
		if (positions[1]>0) { // Javadoc comments has positive end position
2980
			comment = this.ast.newJavadoc();
2981
		} else {
2982
			comment = this.ast.newComment();
2983
		}
2984
		comment.setBlock(positions[0]>0||positions[1]>0);	// Block comment has at least one positive position
2985
		// (Javadoc comments are considered as block)
2986
		int start = positions[0]>0 ? positions[0] : -positions[0];
2987
		int end = positions[1]>0 ? positions[1] : -positions[1];
2988
		int length = end - start;
2989
		String contents = new String(this.compilationUnitSource, start, length);
2990
		comment.setSourceRange(start, length);
2991
		comment.setComment(contents);
2992
		return comment;
2993
	}
2994
2946
	private void propagateErrors(CompilationUnit unit, IProblem[] problems, int problemLength) {
2995
	private void propagateErrors(CompilationUnit unit, IProblem[] problems, int problemLength) {
2947
		// resize the problem array to the proper size
2996
		// resize the problem array to the proper size
2948
		IProblem[] resizeProblems = null;
2997
		IProblem[] resizeProblems = null;
(-)dom/org/eclipse/jdt/core/dom/ASTMatcher.java (-3 / +34 lines)
Lines 40-46 Link Here
40
 * matchers.
40
 * matchers.
41
 * </p>
41
 * </p>
42
 * 
42
 * 
43
 * @see ASTNode#subtreeMatch
43
 * @see ASTNode#subtreeMatch(ASTMatcher, Object)
44
 * @since 2.0
44
 * @since 2.0
45
 */
45
 */
46
public class ASTMatcher {
46
public class ASTMatcher {
Lines 838-851 Link Here
838
	 *   <code>false</code> if they do not match or the other object has a
838
	 *   <code>false</code> if they do not match or the other object has a
839
	 *   different node type or is <code>null</code>
839
	 *   different node type or is <code>null</code>
840
	 */
840
	 */
841
	public boolean match(Comment node, Object other) {
842
		if (!(other instanceof Comment)) {
843
			return false;
844
		}
845
		Comment o = (Comment) other;
846
		return safeSubtreeListMatch(node.tags(), o.tags());
847
	}
841
	public boolean match(Javadoc node, Object other) {
848
	public boolean match(Javadoc node, Object other) {
842
		if (!(other instanceof Javadoc)) {
849
		if (!(other instanceof Javadoc)) {
843
			return false;
850
			return false;
844
		}
851
		}
845
		Javadoc o = (Javadoc) other;
852
		Javadoc o = (Javadoc) other;
846
		return safeEquals(node.getComment(), o.getComment());
853
		return safeSubtreeListMatch(node.tags(), o.tags());
847
	}
854
	}
848
855
	public boolean match(JavadocTag node, Object other) {
856
		if (!(other instanceof JavadocTag)) {
857
			return false;
858
		}
859
		JavadocTag o = (JavadocTag) other;
860
		return (node.getIdentifier().equals(o.getIdentifier()) &&
861
				safeEquals(node.getDescription(), o.getDescription()) &&
862
				safeSubtreeMatch(node.getReference(), o.getReference()));
863
	}
864
	public boolean match(JavadocEmbeddedTag node, Object other) {
865
		if (!(other instanceof JavadocEmbeddedTag)) {
866
			return false;
867
		}
868
		JavadocEmbeddedTag o = (JavadocEmbeddedTag) other;
869
		return (node.getIdentifier().equals(o.getIdentifier()) &&
870
				safeSubtreeMatch(node.getTag(), o.getTag()));
871
	}
872
	public boolean match(JavadocArgument node, Object other) {
873
		if (!(other instanceof JavadocArgument)) {
874
			return false;
875
		}
876
		JavadocArgument o = (JavadocArgument) other;
877
		return (node.getArgument().equals(o.getArgument()));
878
	}
879
	
849
	/**
880
	/**
850
	 * Returns whether the given node and the other object match.
881
	 * Returns whether the given node and the other object match.
851
	 * <p>
882
	 * <p>
(-)dom/org/eclipse/jdt/core/dom/ASTNode.java (-17 / +78 lines)
Lines 108-114 Link Here
108
 * problem (support for this is planned for a future release).
108
 * problem (support for this is planned for a future release).
109
 * </p>
109
 * </p>
110
 * 
110
 * 
111
 * @see AST#parseCompilationUnit
111
 * @see AST#parseCompilationUnit(char[]) and other similar methods
112
 * @see ASTVisitor
112
 * @see ASTVisitor
113
 * @since 2.0
113
 * @since 2.0
114
 */
114
 */
Lines 549-554 Link Here
549
	public static final int INSTANCEOF_EXPRESSION = 62;
549
	public static final int INSTANCEOF_EXPRESSION = 62;
550
550
551
	/**
551
	/**
552
	 * Node type constant indicating a node of type 
553
	 * <code>Comment</code>.
554
	 * @see Comment
555
	 */
556
	public static final int COMMENT = 63;
557
558
	/**
559
	 * Node type constant indicating a node of type 
560
	 * <code>JavadocTag</code>.
561
	 * @see JavadocTag
562
	 */
563
	public static final int JAVADOC_TAG = 64;
564
565
	/**
566
	 * Node type constant indicating a node of type 
567
	 * <code>JavadocTag</code>.
568
	 * @see JavadocTag
569
	 */
570
	public static final int JAVADOC_EMBEDDED_TAG = 65;
571
572
	/**
573
	 * Node type constant indicating a node of type 
574
	 * <code>JavadocTag</code>.
575
	 * @see JavadocTag
576
	 */
577
	public static final int JAVADOC_ARGUMENT = 66;
578
	
579
	/**
552
	 * Owning AST.
580
	 * Owning AST.
553
	 */
581
	 */
554
	private final AST owner;
582
	private final AST owner;
Lines 562-568 Link Here
562
	/**
590
	/**
563
	 * An unmodifiable empty map (used to implement <code>properties()</code>).
591
	 * An unmodifiable empty map (used to implement <code>properties()</code>).
564
	 * 
592
	 * 
565
	 * @see #properties
593
	 * @see #properties()
566
	 */
594
	 */
567
	private static Map UNMODIFIABLE_EMPTY_MAP
595
	private static Map UNMODIFIABLE_EMPTY_MAP
568
		= Collections.unmodifiableMap(new HashMap(1));
596
		= Collections.unmodifiableMap(new HashMap(1));
Lines 927-933 Link Here
927
	public ASTNode getParent() {
955
	public ASTNode getParent() {
928
		return parent;
956
		return parent;
929
	}
957
	}
930
		
958
	
931
	/**
959
	/**
932
	 * Returns the root node at or above this node; returns this node if 
960
	 * Returns the root node at or above this node; returns this node if 
933
	 * it is a root.
961
	 * it is a root.
Lines 947-952 Link Here
947
	}
975
	}
948
	
976
	
949
	/**
977
	/**
978
	 * Returns the compilation unit which owns this node; returns this node if 
979
	 * it is a compilation unit or null if none was found.
980
	 * 
981
	 * @return the compilation unit node founds in node hierarchy or null if none was found
982
	 */ 
983
	public CompilationUnit getCompilationUnit() {
984
		ASTNode candidate = this;
985
		while (candidate != null) {
986
			if (candidate instanceof CompilationUnit) {
987
				return (CompilationUnit) candidate;
988
			}
989
			candidate = candidate.getParent();
990
		}
991
		return null;
992
	}
993
	
994
	/**
950
	 * Internal callback indicating that a field of this node is about to
995
	 * Internal callback indicating that a field of this node is about to
951
	 * be modified.
996
	 * be modified.
952
	 */
997
	 */
Lines 1062-1068 Link Here
1062
	 * 
1107
	 * 
1063
	 * @param propertyName the property name
1108
	 * @param propertyName the property name
1064
	 * @return the property value, or <code>null</code> if none
1109
	 * @return the property value, or <code>null</code> if none
1065
	 * @see #setProperty
1110
	 * @see #setProperty(String, Object)
1066
	 */
1111
	 */
1067
	public Object getProperty(String propertyName) {
1112
	public Object getProperty(String propertyName) {
1068
		if (propertyName == null) {
1113
		if (propertyName == null) {
Lines 1102-1108 Link Here
1102
	 * 
1147
	 * 
1103
	 * @param propertyName the property name
1148
	 * @param propertyName the property name
1104
	 * @param data the new property value, or <code>null</code> if none
1149
	 * @param data the new property value, or <code>null</code> if none
1105
	 * @see #getProperty
1150
	 * @see #getProperty(String)
1106
	 */
1151
	 */
1107
	public void setProperty(String propertyName, Object data) {
1152
	public void setProperty(String propertyName, Object data) {
1108
		if (propertyName == null) {
1153
		if (propertyName == null) {
Lines 1208-1214 Link Here
1208
	 * </p>
1253
	 * </p>
1209
	 * 
1254
	 * 
1210
	 * @return the bitwise-or of individual flags
1255
	 * @return the bitwise-or of individual flags
1211
	 * @see #setFlags
1256
	 * @see #setFlags(int)
1212
	 * @see #MALFORMED
1257
	 * @see #MALFORMED
1213
	 */
1258
	 */
1214
	public int getFlags() {
1259
	public int getFlags() {
Lines 1228-1234 Link Here
1228
	 * </p>
1273
	 * </p>
1229
	 * 
1274
	 * 
1230
	 * @param flags the bitwise-or of individual flags
1275
	 * @param flags the bitwise-or of individual flags
1231
	 * @see #getFlags
1276
	 * @see #getFlags()
1232
	 * @see #MALFORMED
1277
	 * @see #MALFORMED
1233
	 */
1278
	 */
1234
	public void setFlags(int flags) {
1279
	public void setFlags(int flags) {
Lines 1438-1448 Link Here
1438
	 * 
1483
	 * 
1439
	 * @return the 0-based character index, or <code>-1</code>
1484
	 * @return the 0-based character index, or <code>-1</code>
1440
	 *    if no source position information is recorded for this node
1485
	 *    if no source position information is recorded for this node
1441
	 * @see #getLength
1486
	 * @see #getLength()
1442
	 * @see AST#parseCompilationUnit
1487
	 * @see AST#parseCompilationUnit
1443
	 */
1488
	 */
1444
	public int getStartPosition() {
1489
	public int getStartPosition() {
1445
		return startPosition;
1490
		return this.startPosition;
1491
	}
1492
1493
	/**
1494
	 * Returns the character index into the original source file indicating
1495
	 * where the source fragment corresponding to this node ends.
1496
	 * 
1497
	 * @return the 0-based character index, or <code>-1</code>
1498
	 *    if no source position information is recorded for this node
1499
	 * @see #getLength()
1500
	 */
1501
	public int getEndPosition() {
1502
		if (this.length==0) {
1503
			return -1;
1504
		}else {
1505
			return this.startPosition+this.length-1;
1506
		}
1446
	}
1507
	}
1447
1508
1448
	/**
1509
	/**
Lines 1460-1466 Link Here
1460
	 * @see AST#parseCompilationUnit
1521
	 * @see AST#parseCompilationUnit
1461
	 */
1522
	 */
1462
	public int getLength() {
1523
	public int getLength() {
1463
		return length;
1524
		return this.length;
1464
	}
1525
	}
1465
	
1526
	
1466
	/**
1527
	/**
Lines 1477-1484 Link Here
1477
	 * @param length a (possibly 0) length, 
1538
	 * @param length a (possibly 0) length, 
1478
	 *    or <code>0</code> if no source position information is recorded 
1539
	 *    or <code>0</code> if no source position information is recorded 
1479
	 *    for this node
1540
	 *    for this node
1480
	 * @see #getStartPosition
1541
	 * @see #getStartPosition()
1481
	 * @see #getLength
1542
	 * @see #getLength()
1482
	 * @see AST#parseCompilationUnit
1543
	 * @see AST#parseCompilationUnit
1483
	 */
1544
	 */
1484
	public void setSourceRange(int startPosition, int length) {
1545
	public void setSourceRange(int startPosition, int length) {
Lines 1537-1543 Link Here
1537
		// print the subtree by default
1598
		// print the subtree by default
1538
		appendPrintString(buffer);
1599
		appendPrintString(buffer);
1539
	}
1600
	}
1540
		
1601
1541
	/**
1602
	/**
1542
	 * Appends a standard Java source code representation of this subtree to the given
1603
	 * Appends a standard Java source code representation of this subtree to the given
1543
	 * string buffer.
1604
	 * string buffer.
Lines 1549-1567 Link Here
1549
		this.accept(printer);
1610
		this.accept(printer);
1550
		buffer.append(printer.getResult());
1611
		buffer.append(printer.getResult());
1551
	}
1612
	}
1552
	
1613
1553
	/**
1614
	/**
1554
	 * Estimate of size of an object header in bytes.
1615
	 * Estimate of size of an object header in bytes.
1555
	 */
1616
	 */
1556
	static final int HEADERS = 12;
1617
	static final int HEADERS = 12;
1557
	
1618
1558
	/**
1619
	/**
1559
	 * Approximate base size of an AST node instance in bytes, 
1620
	 * Approximate base size of an AST node instance in bytes, 
1560
	 * including object header and instance fields.
1621
	 * including object header and instance fields.
1561
	 * That is, HEADERS + (# instance vars in ASTNode)*4.
1622
	 * That is, HEADERS + (# instance vars in ASTNode)*4.
1562
	 */
1623
	 */
1563
	static final int BASE_NODE_SIZE = HEADERS + 7 * 4;
1624
	static final int BASE_NODE_SIZE = HEADERS + 7 * 4;
1564
	
1625
1565
	/**
1626
	/**
1566
	 * Returns an estimate of the memory footprint in bytes of the entire 
1627
	 * Returns an estimate of the memory footprint in bytes of the entire 
1567
	 * subtree rooted at this node.
1628
	 * subtree rooted at this node.
Lines 1571-1577 Link Here
1571
	public final int subtreeBytes() {
1632
	public final int subtreeBytes() {
1572
		return treeSize();
1633
		return treeSize();
1573
	}
1634
	}
1574
		
1635
1575
	/**
1636
	/**
1576
	 * Returns an estimate of the memory footprint in bytes of the entire 
1637
	 * Returns an estimate of the memory footprint in bytes of the entire 
1577
	 * subtree rooted at this node.
1638
	 * subtree rooted at this node.
(-)dom/org/eclipse/jdt/core/dom/ASTVisitor.java (-1 / +25 lines)
Lines 93-99 Link Here
93
 * </ul>
93
 * </ul>
94
 * </p>
94
 * </p>
95
 * 
95
 * 
96
 * @see ASTNode#accept
96
 * @see ASTNode#accept(ASTVisitor)
97
 */
97
 */
98
public abstract class ASTVisitor {
98
public abstract class ASTVisitor {
99
	
99
	
Lines 165-170 Link Here
165
	public boolean visit(ClassInstanceCreation node) {
165
	public boolean visit(ClassInstanceCreation node) {
166
		return true;
166
		return true;
167
	}
167
	}
168
	public boolean visit(Comment node) {
169
		return true;
170
	}
168
	public boolean visit(CompilationUnit node) {
171
	public boolean visit(CompilationUnit node) {
169
		return true;
172
		return true;
170
	}
173
	}
Lines 213-218 Link Here
213
	public boolean visit(Javadoc node) {
216
	public boolean visit(Javadoc node) {
214
		return true;
217
		return true;
215
	}
218
	}
219
	public boolean visit(JavadocTag node) {
220
		return true;
221
	}
222
	public boolean visit(JavadocEmbeddedTag node) {
223
		return true;
224
	}
225
	public boolean visit(JavadocArgument node) {
226
		return true;
227
	}
216
	public boolean visit(LabeledStatement node) {
228
	public boolean visit(LabeledStatement node) {
217
		return true;
229
		return true;
218
	}
230
	}
Lines 355-360 Link Here
355
	public void endVisit(CompilationUnit node) {
367
	public void endVisit(CompilationUnit node) {
356
		// default implementation: do nothing
368
		// default implementation: do nothing
357
	}
369
	}
370
	public void endVisit(Comment node) {
371
		// default implementation: do nothing
372
	}
358
	public void endVisit(ConditionalExpression node) {
373
	public void endVisit(ConditionalExpression node) {
359
		// default implementation: do nothing
374
		// default implementation: do nothing
360
	}
375
	}
Lines 398-403 Link Here
398
		// default implementation: do nothing
413
		// default implementation: do nothing
399
	}
414
	}
400
	public void endVisit(Javadoc node) {
415
	public void endVisit(Javadoc node) {
416
		// default implementation: do nothing
417
	}
418
	public void endVisit(JavadocTag node) {
419
		// default implementation: do nothing
420
	}
421
	public void endVisit(JavadocEmbeddedTag node) {
422
		// default implementation: do nothing
423
	}
424
	public void endVisit(JavadocArgument node) {
401
		// default implementation: do nothing
425
		// default implementation: do nothing
402
	}
426
	}
403
	public void endVisit(LabeledStatement node) {
427
	public void endVisit(LabeledStatement node) {
(-)dom/org/eclipse/jdt/core/dom/BodyDeclaration.java (-1 / +9 lines)
Lines 72-80 Link Here
72
	 * Returns the Javadoc comment node.
72
	 * Returns the Javadoc comment node.
73
	 * 
73
	 * 
74
	 * @return the javadoc comment node, or <code>null</code> if none
74
	 * @return the javadoc comment node, or <code>null</code> if none
75
	 * TODO (frederic) See if it could be interesting to store the javadoc comment instead of looking for it systematically...
75
	 */
76
	 */
76
	public Javadoc getJavadoc() {
77
	public Javadoc getJavadoc() {
77
		return optionalJavadoc;
78
		CompilationUnit unit = getCompilationUnit();
79
		if (unit != null) {
80
			Comment comment = unit.getComment(getStartPosition());
81
			if (comment != null && comment.isJavadoc()) {
82
				return (Javadoc) comment;
83
			}
84
		}
85
		return this.optionalJavadoc;
78
	}
86
	}
79
87
80
	/**
88
	/**
(-)dom/org/eclipse/jdt/core/dom/CompilationUnit.java (-7 / +69 lines)
Lines 55-60 Link Here
55
		new ASTNode.NodeList(false, TypeDeclaration.class);
55
		new ASTNode.NodeList(false, TypeDeclaration.class);
56
	
56
	
57
	/**
57
	/**
58
	 * The list of comments in textual order; 
59
	 * initially none (elementType: <code>Javadoc</code>)
60
	 */
61
	private ASTNode.NodeList comments =
62
		new ASTNode.NodeList(false, Comment.class);
63
	
64
	/**
58
	 * Line end table. If <code>lineEndTable[i] == p</code> then the
65
	 * Line end table. If <code>lineEndTable[i] == p</code> then the
59
	 * line number <code>i+1</code> ends at character position 
66
	 * line number <code>i+1</code> ends at character position 
60
	 * <code>p</code>. Except for the last line, the positions are that
67
	 * <code>p</code>. Except for the last line, the positions are that
Lines 92-98 Link Here
92
	 * For example, the source string <code>A\nB\nC</code> has
99
	 * For example, the source string <code>A\nB\nC</code> has
93
	 * line end table {1, 3, 4}.
100
	 * line end table {1, 3, 4}.
94
	 * 
101
	 * 
95
	 * @param lineEndtable the line end table
102
	 * @param lineEndTable the line end table
96
	 */
103
	 */
97
	void setLineEndTable(int[] lineEndTable) {
104
	void setLineEndTable(int[] lineEndTable) {
98
		if (lineEndTable == null) {
105
		if (lineEndTable == null) {
Lines 213-218 Link Here
213
	}
220
	}
214
221
215
	/**
222
	/**
223
	 * Returns the live list of nodes for all comments declared in this 
224
	 * compilation unit, in order of appearance.
225
	 * 
226
	 * @return the live list of comment nodes
227
	 *    (elementType: <code>Comment</code>)
228
	 */ 
229
	public List comments() {
230
		return comments;
231
	}
232
233
	/**
216
	 * Finds the corresponding AST node in the given compilation unit from 
234
	 * Finds the corresponding AST node in the given compilation unit from 
217
	 * which the given binding originated. Returns <code>null</code> if the
235
	 * which the given binding originated. Returns <code>null</code> if the
218
	 * binding does not correspond to any node in this compilation unit.
236
	 * binding does not correspond to any node in this compilation unit.
Lines 293-299 Link Here
293
	 * key is declared, or <code>null</code> if the key is <code>null</code>
311
	 * key is declared, or <code>null</code> if the key is <code>null</code>
294
	 * or if the key does not correspond to a node in this compilation unit
312
	 * or if the key does not correspond to a node in this compilation unit
295
	 * or if bindings were not requested when this AST was built
313
	 * or if bindings were not requested when this AST was built
296
	 * @see IBinding#getKey
314
	 * @see IBinding#getKey()
297
	 * @since 2.1
315
	 * @since 2.1
298
	 */
316
	 */
299
	public ASTNode findDeclaringNode(String key) {
317
	public ASTNode findDeclaringNode(String key) {
Lines 318-324 Link Here
318
	 *    position does not correspond to a source line in the original
336
	 *    position does not correspond to a source line in the original
319
	 *    source file or if line number information is not known for this
337
	 *    source file or if line number information is not known for this
320
	 *    compilation unit
338
	 *    compilation unit
321
	 * @see AST#parseCompilationUnit
339
	 * @see AST#parseCompilationUnit(char[]) and other similar methods
322
	 */
340
	 */
323
	public int lineNumber(int position) {
341
	public int lineNumber(int position) {
324
		int length = lineEndTable.length;
342
		int length = lineEndTable.length;
Lines 384-391 Link Here
384
	 * </p>
402
	 * </p>
385
	 *
403
	 *
386
	 * @return the list of messages, possibly empty
404
	 * @return the list of messages, possibly empty
387
	 * @see #getProblems
405
	 * @see #getProblems()
388
	 * @see AST#parseCompilationUnit
406
	 * @see AST#parseCompilationUnit(char[]) and other similar methods
389
	 */
407
	 */
390
	public Message[] getMessages() {
408
	public Message[] getMessages() {
391
		if (this.messages == null) {
409
		if (this.messages == null) {
Lines 416-423 Link Here
416
	 * </p>
434
	 * </p>
417
	 * 
435
	 * 
418
	 * @return the list of detailed problem objects, possibly empty
436
	 * @return the list of detailed problem objects, possibly empty
419
	 * @see #getMessages
437
	 * @see #getMessages()
420
	 * @see AST#parseCompilationUnit
438
	 * @see AST#parseCompilationUnit(char[]) and other similar methods
421
	 * @since 2.1
439
	 * @since 2.1
422
	 */
440
	 */
423
	public IProblem[] getProblems() {
441
	public IProblem[] getProblems() {
Lines 474-479 Link Here
474
			+ (optionalPackageDeclaration == null ? 0 : getPackage().treeSize())
492
			+ (optionalPackageDeclaration == null ? 0 : getPackage().treeSize())
475
			+ imports.listSize()
493
			+ imports.listSize()
476
			+ types.listSize();
494
			+ types.listSize();
495
	}
496
	
497
	/**
498
	 * Get comment of the list which includes a given position
499
	 * 
500
	 * @param position The position belonging to the looked up comment
501
	 * @return Javadoc The comment which includes the given position or null if none was found
502
	 */
503
	public Comment getComment(int position) {
504
505
		if (this.comments == null) {
506
			return null;
507
		}
508
		int size = this.comments.size();
509
		if (size == 0) {
510
			return null;
511
		}
512
		int bottom = 0, top = size - 1;
513
		int i = 0, index = -1;
514
		Comment comment = null;
515
		while (bottom <= top) {
516
			i = (bottom + top) /2;
517
			comment = (Comment) this.comments.get(i);
518
			if (position < comment.getStartPosition()) {
519
				top = i-1;
520
			} else if (position >= comment.getEndPosition()) {
521
				bottom = i+1;
522
			} else {
523
				index = i;
524
				break;
525
			}
526
		}
527
		if (index<0) {
528
			/*
529
			comment = (Comment) this.comments.get(i);
530
			if (position < comment.getStartPosition()) {
531
				index = i;
532
			} else {
533
				index = i+1;
534
			}
535
			*/
536
			return null;
537
		}
538
		return (Comment) this.comments.get(index);
477
	}
539
	}
478
}
540
}
479
541
(-)dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java (-61 / +19 lines)
Lines 11-32 Link Here
11
11
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import org.eclipse.jdt.internal.compiler.Compiler;
14
import java.util.Map;
15
import org.eclipse.jdt.internal.compiler.*;
15
16
import org.eclipse.jdt.internal.compiler.env.*;
17
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.*;
16
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.core.compiler.*;
17
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.internal.core.*;
18
import org.eclipse.jdt.internal.compiler.*;
21
import org.eclipse.jdt.internal.compiler.impl.*;
19
import org.eclipse.jdt.internal.compiler.Compiler;
22
import org.eclipse.jdt.internal.compiler.ast.*;
20
import org.eclipse.jdt.internal.compiler.ast.*;
21
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
22
import org.eclipse.jdt.internal.compiler.env.ISourceType;
23
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers;
24
import org.eclipse.jdt.internal.compiler.lookup.CompilerModifiers;
24
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
25
import org.eclipse.jdt.internal.compiler.parser.Parser;
26
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
26
import org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter;
27
import org.eclipse.jdt.internal.compiler.problem.*;
27
import org.eclipse.jdt.internal.compiler.problem.*;
28
28
import org.eclipse.jdt.internal.core.*;
29
import java.util.*;
30
29
31
class CompilationUnitResolver extends Compiler {
30
class CompilationUnitResolver extends Compiler {
32
	
31
	
Lines 77-82 Link Here
77
	
76
	
78
	/**
77
	/**
79
	 * Add additional source types
78
	 * Add additional source types
79
	 * @param sourceTypes
80
	 * @param packageBinding
80
	 */
81
	 */
81
	public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding) {
82
	public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding) {
82
		CompilationResult result =
83
		CompilationResult result =
Lines 97-146 Link Here
97
		}
98
		}
98
	}
99
	}
99
100
100
	private static Parser createDomParser(ProblemReporter problemReporter) {
101
		
102
		return new Parser(problemReporter, false) {
103
			// old annotation style check which doesn't include all leading comments into declaration
104
			// for backward compatibility with 2.1 DOM 
105
			public void checkComment() {
106
107
				if (this.currentElement != null && this.scanner.commentPtr >= 0) {
108
					flushCommentsDefinedPriorTo(endStatementPosition); // discard obsolete comments
109
				}
110
				boolean deprecated = false;
111
				boolean checkDeprecated = false;
112
				int lastCommentIndex = -1;
113
			
114
				//since jdk1.2 look only in the last java doc comment...
115
					//look for @deprecated into the first javadoc comment preceeding the declaration
116
					int commentSourceStart = scanner.commentStarts[lastCommentIndex];
117
					// javadoc only (non javadoc comment have negative end positions.)
118
					if (modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) {
119
						continue nextComment;
120
					}
121
					if (scanner.commentStops[lastCommentIndex] < 0) {
122
						continue nextComment;
123
					}
124
					checkDeprecated = true;
125
					int commentSourceEnd = scanner.commentStops[lastCommentIndex] - 1; //stop is one over
126
			
127
					deprecated =
128
						this.javadocParser.checkDeprecation(commentSourceStart, commentSourceEnd);
129
					this.javadoc = this.javadocParser.javadoc;
130
					break nextComment;
131
				}
132
				if (deprecated) {
133
					checkAndSetModifiers(AccDeprecated);
134
				}
135
				// modify the modifier source start to point at the first comment
136
				if (lastCommentIndex >= 0 && checkDeprecated) {
137
					modifiersSourceStart = scanner.commentStarts[lastCommentIndex]; 
138
				}
139
140
			}
141
		};
142
	}
143
101
144
	/*
102
	/*
145
	 *  Low-level API performing the actual compilation
103
	 *  Low-level API performing the actual compilation
Lines 185-191 Link Here
185
	 * @see org.eclipse.jdt.internal.compiler.Compiler#initializeParser()
142
	 * @see org.eclipse.jdt.internal.compiler.Compiler#initializeParser()
186
	 */
143
	 */
187
	public void initializeParser() {
144
	public void initializeParser() {
188
		this.parser = createDomParser(this.problemReporter);
145
		this.parser = new DOMParser(this.problemReporter, false);
189
	}
146
	}
190
	/*
147
	/*
191
	 * Compiler crash recovery in case of unexpected runtime exceptions
148
	 * Compiler crash recovery in case of unexpected runtime exceptions
Lines 260-270 Link Here
260
			throw new IllegalArgumentException();
217
			throw new IllegalArgumentException();
261
		}
218
		}
262
		CompilerOptions compilerOptions = new CompilerOptions(settings);
219
		CompilerOptions compilerOptions = new CompilerOptions(settings);
263
		Parser parser = createDomParser(
220
		DOMParser parser = new DOMParser(
264
			new ProblemReporter(
221
			new ProblemReporter(
265
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
222
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
266
					compilerOptions, 
223
					compilerOptions, 
267
					new DefaultProblemFactory()));
224
					new DefaultProblemFactory()), false);
268
		org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = 
225
		org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = 
269
			new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
226
			new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
270
				source, 
227
				source, 
Lines 294-304 Link Here
294
			throw new IllegalArgumentException();
251
			throw new IllegalArgumentException();
295
		}
252
		}
296
		CompilerOptions compilerOptions = new CompilerOptions(settings);
253
		CompilerOptions compilerOptions = new CompilerOptions(settings);
297
		Parser parser = createDomParser(
254
		DOMParser parser = new DOMParser(
298
			new ProblemReporter(
255
			new ProblemReporter(
299
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
256
					DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
300
					compilerOptions, 
257
					compilerOptions, 
301
					new DefaultProblemFactory()));
258
					new DefaultProblemFactory()), false);
302
		org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = 
259
		org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = 
303
			new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
260
			new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(
304
				source, 
261
				source, 
Lines 500-506 Link Here
500
		}
457
		}
501
	}
458
	}
502
459
503
	/**
460
	/*
504
	 * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
461
	 * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
505
	 */
462
	 */
506
	public CompilationUnitDeclaration resolve(
463
	public CompilationUnitDeclaration resolve(
Lines 576-582 Link Here
576
			// this.reset();
533
			// this.reset();
577
		}
534
		}
578
	}
535
	}
579
	/**
536
	/*
580
	 * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
537
	 * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
581
	 */
538
	 */
582
	public CompilationUnitDeclaration resolve(
539
	public CompilationUnitDeclaration resolve(
Lines 593-599 Link Here
593
			generateCode);
550
			generateCode);
594
	}
551
	}
595
552
596
	/**
553
	/*
597
	 * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
554
	 * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
598
	 */
555
	 */
599
	public CompilationUnitDeclaration resolve(
556
	public CompilationUnitDeclaration resolve(
(-)dom/org/eclipse/jdt/core/dom/IBinding.java (-5 / +8 lines)
Lines 33-39 Link Here
33
	 * Kind constant (value 1) indicating a package binding.
33
	 * Kind constant (value 1) indicating a package binding.
34
	 * Bindings of this kind can be safely cast to <code>IPackageBinding</code>.
34
	 * Bindings of this kind can be safely cast to <code>IPackageBinding</code>.
35
	 * 
35
	 * 
36
	 * @see #getKind
36
	 * @see #getKind()
37
	 * @see IPackageBinding
37
	 * @see IPackageBinding
38
	 */
38
	 */
39
	public static final int PACKAGE = 1;
39
	public static final int PACKAGE = 1;
Lines 42-48 Link Here
42
	 * Kind constant (value 2) indicating a type binding.
42
	 * Kind constant (value 2) indicating a type binding.
43
	 * Bindings of this kind can be safely cast to <code>ITypeBinding</code>.
43
	 * Bindings of this kind can be safely cast to <code>ITypeBinding</code>.
44
	 * 
44
	 * 
45
	 * @see #getKind
45
	 * @see #getKind()
46
	 * @see ITypeBinding
46
	 * @see ITypeBinding
47
	 */
47
	 */
48
	public static final int TYPE = 2;
48
	public static final int TYPE = 2;
Lines 51-57 Link Here
51
	 * Kind constant (value 3) indicating a field or local variable binding.
51
	 * Kind constant (value 3) indicating a field or local variable binding.
52
	 * Bindings of this kind can be safely cast to <code>IVariableBinding</code>.
52
	 * Bindings of this kind can be safely cast to <code>IVariableBinding</code>.
53
	 * 
53
	 * 
54
	 * @see #getKind
54
	 * @see #getKind()
55
	 * @see IVariableBinding
55
	 * @see IVariableBinding
56
	 */
56
	 */
57
	public static final int VARIABLE = 3;
57
	public static final int VARIABLE = 3;
Lines 60-66 Link Here
60
	 * Kind constant (value 4) indicating a method or constructor binding.
60
	 * Kind constant (value 4) indicating a method or constructor binding.
61
	 * Bindings of this kind can be safely cast to <code>IMethodBinding</code>.
61
	 * Bindings of this kind can be safely cast to <code>IMethodBinding</code>.
62
	 * 
62
	 * 
63
	 * @see #getKind
63
	 * @see #getKind()
64
	 * @see IMethodBinding
64
	 * @see IMethodBinding
65
	 */
65
	 */
66
	public static final int METHOD = 4;
66
	public static final int METHOD = 4;
Lines 172-178 Link Here
172
	 * not be different; in these cases, the client should compare bindings
172
	 * not be different; in these cases, the client should compare bindings
173
	 * via their binding keys (<code>getKey</code>) if available.
173
	 * via their binding keys (<code>getKey</code>) if available.
174
	 * 
174
	 * 
175
	 * @see #getKey
175
	 * @see #getKey()
176
	 * 
177
	 * @param obj
178
	 * @return
176
	 */
179
	 */
177
	public boolean equals(Object obj);
180
	public boolean equals(Object obj);
178
	
181
	
(-)dom/org/eclipse/jdt/core/dom/Javadoc.java (-58 / +60 lines)
Lines 8-33 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
12
package org.eclipse.jdt.core.dom;
11
package org.eclipse.jdt.core.dom;
13
12
14
import org.eclipse.jdt.core.compiler.InvalidInputException;
15
import org.eclipse.jdt.internal.compiler.parser.Scanner;
16
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
17
13
18
/**
14
/**
19
 * AST node for a Javadoc comment.
15
 * AST node for a Javadoc comment.
20
 * 
16
 * 
21
 * @since 2.0
17
 * @since 2.0
22
 */
18
 */
23
public class Javadoc extends ASTNode {
19
public class Javadoc extends Comment {
24
20
25
	/**
21
	/**
26
	 * The javadoc comment string, including opening and closing comment 
22
	 * First non-empty line of comment text before the first Javadoc tag;
27
	 * delimiters; defaults to an unspecified, but legal, Javadoc comment.
23
	 * default is empty string.
28
	 */
24
	 */
29
	private String comment = "/** */";//$NON-NLS-1$
25
	//String title = "";//$NON-NLS-1$
30
	
26
27
	/**
28
	 * Non-empty lines of comment text after the title and before the first
29
	 * Javadoc tag; default is empty string.
30
	 */
31
	//String[] description = { "" }; //$NON-NLS-1$
32
	//String description = ""; //$NON-NLS-1$
33
31
	/**
34
	/**
32
	 * Creates a new AST node for a Javadoc comment owned by the given AST.
35
	 * Creates a new AST node for a Javadoc comment owned by the given AST.
33
	 * The new node has an unspecified, but legal, Javadoc comment.
36
	 * The new node has an unspecified, but legal, Javadoc comment.
Lines 41-46 Link Here
41
	 */
44
	 */
42
	Javadoc(AST ast) {
45
	Javadoc(AST ast) {
43
		super(ast);
46
		super(ast);
47
		this.block = true;
48
		this.text = "/** */"; //$NON-NLS-1$
44
	}
49
	}
45
	
50
	
46
	/* (omit javadoc for this method)
51
	/* (omit javadoc for this method)
Lines 56-62 Link Here
56
	ASTNode clone(AST target) {
61
	ASTNode clone(AST target) {
57
		Javadoc result = new Javadoc(target);
62
		Javadoc result = new Javadoc(target);
58
		result.setSourceRange(this.getStartPosition(), this.getLength());
63
		result.setSourceRange(this.getStartPosition(), this.getLength());
59
		result.setComment(getComment());
64
		result.setText(this.text);
65
		//result.setTitle(this.title);
66
		//result.setDescription(this.description);
60
		return result;
67
		return result;
61
	}
68
	}
62
	
69
	
Lines 81-146 Link Here
81
	 * and ending comment delimiters, and any embedded line breaks.
88
	 * and ending comment delimiters, and any embedded line breaks.
82
	 * 
89
	 * 
83
	 * @return the javadoc comment string
90
	 * @return the javadoc comment string
91
	 * @deprecated Use #getText() instead
84
	 */
92
	 */
85
	public String getComment() {
93
	public String getComment() {
86
		return comment;
94
		return getText();
87
	}
95
	}
88
96
89
	/**
97
	/**
90
	 * Sets or clears the Javadoc comment string. The documentation
98
	 * Returns whether the comment is a javadoc comment or not.
91
	 * string must include the starting and ending comment delimiters,
99
	 * @return true if the comment is a Javadoc one, false otherwise.
92
	 * and any embedded line breaks.
100
	 */
93
	 * 
101
	public boolean isJavadoc() {
94
	 * @param javadocComment the javadoc comment string
102
		return true;
95
	 * @exception IllegalArgumentException if the Java comment string is invalid
103
	}
104
105
	/**
106
	 * @return Returns the description as string.
96
	 */
107
	 */
97
	public void setComment(String javadocComment) {
108
	public String getDescription() {
98
		if (javadocComment == null) {
109
		JavadocTag tag = getFirstSentence(false);
99
			throw new IllegalArgumentException();
110
		if (tag != null) {
111
			return tag.getDescription();
100
		}
112
		}
101
		char[] source = javadocComment.toCharArray();
113
		return "";	//$NON-NLS-1$
102
		Scanner scanner = this.getAST().scanner;
114
	}
103
		scanner.resetTo(0, source.length);
115
104
		scanner.setSource(source);
116
	/**
105
		try {
117
	 * Return the first sengtence of Javadoc comment.
106
			int token;
118
	 * This is the first tag of the list which has no identifier.
107
			boolean onlyOneComment = false;
119
	 * @param setIfNull Tells whether the first sentence should be created if none was found
108
			while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
120
	 * @return The first sentence of the Javadoc as a JavadocTag
109
				switch(token) {
121
	 * @see JavadocTag
110
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
122
	 */
111
						if (onlyOneComment) {
123
	public JavadocTag getFirstSentence(boolean setIfNull) {
112
							throw new IllegalArgumentException();
124
		if (this.tags.size() > 0) {
113
						}
125
			JavadocTag tag = (JavadocTag) tags().get(0);
114
						onlyOneComment = true;
126
			if (tag.getIdentifier().length() == 0) {
115
						break;
127
				return tag;
116
					default:
117
						onlyOneComment = false;
118
				}
119
			}
120
			if (!onlyOneComment) {
121
				throw new IllegalArgumentException();
122
			}
128
			}
123
		} catch (InvalidInputException e) {
124
			throw new IllegalArgumentException();
125
		}
129
		}
126
		modifying();
130
		if (setIfNull) {
127
		this.comment = javadocComment;
131
			JavadocTag tag = getAST().newJavadocTag();
128
	}
132
			this.tags.add(0, tag);
129
		
133
			return tag;
130
	/* (omit javadoc for this method)
134
		} else {
131
	 * Method declared on ASTNode.
135
			return null;
132
	 */
136
		}
133
	int memSize() {
134
		int size = BASE_NODE_SIZE + 1 * 4;
135
		size += HEADERS + 2 * 4 + HEADERS + 2 * comment.length();
136
		return size;
137
	}
137
	}
138
	
138
	
139
	/* (omit javadoc for this method)
139
	/* (non-Javadoc)
140
	 * Method declared on ASTNode.
140
	 * @see org.eclipse.jdt.core.dom.Comment#isBlock()
141
	 */
141
	 */
142
	int treeSize() {
142
	public boolean isBlock() {
143
		return memSize();
143
		// Javadoc comment is always considered as a block comment
144
		return true;
144
	}
145
	}
146
145
}
147
}
146
148
(-)dom/org/eclipse/jdt/core/dom/NaiveASTFlattener.java (-156 / +205 lines)
Lines 54-67 Link Here
54
	 * @return the serialized 
54
	 * @return the serialized 
55
	 */
55
	 */
56
	public String getResult() {
56
	public String getResult() {
57
		return buffer.toString();
57
		return this.buffer.toString();
58
	}
58
	}
59
	
59
	
60
	/**
60
	/**
61
	 * Resets this printer so that it can be used again.
61
	 * Resets this printer so that it can be used again.
62
	 */
62
	 */
63
	public void reset() {
63
	public void reset() {
64
		buffer.setLength(0);
64
		this.buffer.setLength(0);
65
	}
65
	}
66
	
66
	
67
	/**
67
	/**
Lines 71-107 Link Here
71
	 */
71
	 */
72
	void printModifiers(int modifiers) {
72
	void printModifiers(int modifiers) {
73
		if (Modifier.isPublic(modifiers)) {
73
		if (Modifier.isPublic(modifiers)) {
74
			buffer.append("public ");//$NON-NLS-1$
74
			this.buffer.append("public ");//$NON-NLS-1$
75
		}
75
		}
76
		if (Modifier.isProtected(modifiers)) {
76
		if (Modifier.isProtected(modifiers)) {
77
			buffer.append("protected ");//$NON-NLS-1$
77
			this.buffer.append("protected ");//$NON-NLS-1$
78
		}
78
		}
79
		if (Modifier.isPrivate(modifiers)) {
79
		if (Modifier.isPrivate(modifiers)) {
80
			buffer.append("private ");//$NON-NLS-1$
80
			this.buffer.append("private ");//$NON-NLS-1$
81
		}
81
		}
82
		if (Modifier.isStatic(modifiers)) {
82
		if (Modifier.isStatic(modifiers)) {
83
			buffer.append("static ");//$NON-NLS-1$
83
			this.buffer.append("static ");//$NON-NLS-1$
84
		}
84
		}
85
		if (Modifier.isAbstract(modifiers)) {
85
		if (Modifier.isAbstract(modifiers)) {
86
			buffer.append("abstract ");//$NON-NLS-1$
86
			this.buffer.append("abstract ");//$NON-NLS-1$
87
		}
87
		}
88
		if (Modifier.isFinal(modifiers)) {
88
		if (Modifier.isFinal(modifiers)) {
89
			buffer.append("final ");//$NON-NLS-1$
89
			this.buffer.append("final ");//$NON-NLS-1$
90
		}
90
		}
91
		if (Modifier.isSynchronized(modifiers)) {
91
		if (Modifier.isSynchronized(modifiers)) {
92
			buffer.append("synchronized ");//$NON-NLS-1$
92
			this.buffer.append("synchronized ");//$NON-NLS-1$
93
		}
93
		}
94
		if (Modifier.isVolatile(modifiers)) {
94
		if (Modifier.isVolatile(modifiers)) {
95
			buffer.append("volatile ");//$NON-NLS-1$
95
			this.buffer.append("volatile ");//$NON-NLS-1$
96
		}
96
		}
97
		if (Modifier.isNative(modifiers)) {
97
		if (Modifier.isNative(modifiers)) {
98
			buffer.append("native ");//$NON-NLS-1$
98
			this.buffer.append("native ");//$NON-NLS-1$
99
		}
99
		}
100
		if (Modifier.isStrictfp(modifiers)) {
100
		if (Modifier.isStrictfp(modifiers)) {
101
			buffer.append("strictfp ");//$NON-NLS-1$
101
			this.buffer.append("strictfp ");//$NON-NLS-1$
102
		}
102
		}
103
		if (Modifier.isTransient(modifiers)) {
103
		if (Modifier.isTransient(modifiers)) {
104
			buffer.append("transient ");//$NON-NLS-1$
104
			this.buffer.append("transient ");//$NON-NLS-1$
105
		}
105
		}
106
	}		
106
	}		
107
	
107
	
Lines 109-120 Link Here
109
	 * @see ASTVisitor#visit(AnonymousClassDeclaration)
109
	 * @see ASTVisitor#visit(AnonymousClassDeclaration)
110
	 */
110
	 */
111
	public boolean visit(AnonymousClassDeclaration node) {
111
	public boolean visit(AnonymousClassDeclaration node) {
112
		buffer.append("{");//$NON-NLS-1$
112
		this.buffer.append("{");//$NON-NLS-1$
113
		for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
113
		for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
114
			BodyDeclaration b = (BodyDeclaration) it.next();
114
			BodyDeclaration b = (BodyDeclaration) it.next();
115
			b.accept(this);
115
			b.accept(this);
116
		}
116
		}
117
		buffer.append("}");//$NON-NLS-1$
117
		this.buffer.append("}");//$NON-NLS-1$
118
		return false;
118
		return false;
119
	}
119
	}
120
120
Lines 123-131 Link Here
123
	 */
123
	 */
124
	public boolean visit(ArrayAccess node) {
124
	public boolean visit(ArrayAccess node) {
125
		node.getArray().accept(this);
125
		node.getArray().accept(this);
126
		buffer.append("[");//$NON-NLS-1$
126
		this.buffer.append("[");//$NON-NLS-1$
127
		node.getIndex().accept(this);
127
		node.getIndex().accept(this);
128
		buffer.append("]");//$NON-NLS-1$
128
		this.buffer.append("]");//$NON-NLS-1$
129
		return false;
129
		return false;
130
	}
130
	}
131
131
Lines 133-156 Link Here
133
	 * @see ASTVisitor#visit(ArrayCreation)
133
	 * @see ASTVisitor#visit(ArrayCreation)
134
	 */
134
	 */
135
	public boolean visit(ArrayCreation node) {
135
	public boolean visit(ArrayCreation node) {
136
		buffer.append("new ");//$NON-NLS-1$
136
		this.buffer.append("new ");//$NON-NLS-1$
137
		ArrayType at = node.getType();
137
		ArrayType at = node.getType();
138
		int dims = at.getDimensions();
138
		int dims = at.getDimensions();
139
		Type elementType = at.getElementType();
139
		Type elementType = at.getElementType();
140
		elementType.accept(this);
140
		elementType.accept(this);
141
		for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) {
141
		for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) {
142
			buffer.append("[");//$NON-NLS-1$
142
			this.buffer.append("[");//$NON-NLS-1$
143
			Expression e = (Expression) it.next();
143
			Expression e = (Expression) it.next();
144
			e.accept(this);
144
			e.accept(this);
145
			buffer.append("]");//$NON-NLS-1$
145
			this.buffer.append("]");//$NON-NLS-1$
146
			dims--;
146
			dims--;
147
		}
147
		}
148
		// add empty "[]" for each extra array dimension
148
		// add empty "[]" for each extra array dimension
149
		for (int i= 0; i < dims; i++) {
149
		for (int i= 0; i < dims; i++) {
150
			buffer.append("[]");//$NON-NLS-1$
150
			this.buffer.append("[]");//$NON-NLS-1$
151
		}
151
		}
152
		if (node.getInitializer() != null) {
152
		if (node.getInitializer() != null) {
153
			buffer.append("=");//$NON-NLS-1$
153
			this.buffer.append("=");//$NON-NLS-1$
154
			node.getInitializer().accept(this);
154
			node.getInitializer().accept(this);
155
		}
155
		}
156
		return false;
156
		return false;
Lines 160-172 Link Here
160
	 * @see ASTVisitor#visit(ArrayInitializer)
160
	 * @see ASTVisitor#visit(ArrayInitializer)
161
	 */
161
	 */
162
	public boolean visit(ArrayInitializer node) {
162
	public boolean visit(ArrayInitializer node) {
163
		buffer.append("{");//$NON-NLS-1$
163
		this.buffer.append("{");//$NON-NLS-1$
164
		for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
164
		for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
165
			Expression e = (Expression) it.next();
165
			Expression e = (Expression) it.next();
166
			e.accept(this);
166
			e.accept(this);
167
			buffer.append(",");//$NON-NLS-1$
167
			this.buffer.append(",");//$NON-NLS-1$
168
		}
168
		}
169
		buffer.append("}");//$NON-NLS-1$
169
		this.buffer.append("}");//$NON-NLS-1$
170
		return false;
170
		return false;
171
	}
171
	}
172
172
Lines 175-181 Link Here
175
	 */
175
	 */
176
	public boolean visit(ArrayType node) {
176
	public boolean visit(ArrayType node) {
177
		node.getComponentType().accept(this);
177
		node.getComponentType().accept(this);
178
		buffer.append("[]");//$NON-NLS-1$
178
		this.buffer.append("[]");//$NON-NLS-1$
179
		return false;
179
		return false;
180
	}
180
	}
181
181
Lines 183-195 Link Here
183
	 * @see ASTVisitor#visit(AssertStatement)
183
	 * @see ASTVisitor#visit(AssertStatement)
184
	 */
184
	 */
185
	public boolean visit(AssertStatement node) {
185
	public boolean visit(AssertStatement node) {
186
		buffer.append("assert ");//$NON-NLS-1$
186
		this.buffer.append("assert ");//$NON-NLS-1$
187
		node.getExpression().accept(this);
187
		node.getExpression().accept(this);
188
		if (node.getMessage() != null) {
188
		if (node.getMessage() != null) {
189
			node.getMessage().accept(this);
189
			node.getMessage().accept(this);
190
		}
190
		}
191
		buffer.append(";");//$NON-NLS-1$
191
		this.buffer.append(";");//$NON-NLS-1$
192
		return false;
192
		return false;
193
	}
193
	}
194
194
Lines 198-204 Link Here
198
	 */
198
	 */
199
	public boolean visit(Assignment node) {
199
	public boolean visit(Assignment node) {
200
		node.getLeftHandSide().accept(this);
200
		node.getLeftHandSide().accept(this);
201
		buffer.append(node.getOperator().toString());
201
		this.buffer.append(node.getOperator().toString());
202
		node.getRightHandSide().accept(this);
202
		node.getRightHandSide().accept(this);
203
		return false;
203
		return false;
204
	}
204
	}
Lines 207-218 Link Here
207
	 * @see ASTVisitor#visit(Block)
207
	 * @see ASTVisitor#visit(Block)
208
	 */
208
	 */
209
	public boolean visit(Block node) {
209
	public boolean visit(Block node) {
210
		buffer.append("{");//$NON-NLS-1$
210
		this.buffer.append("{");//$NON-NLS-1$
211
		for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
211
		for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
212
			Statement s = (Statement) it.next();
212
			Statement s = (Statement) it.next();
213
			s.accept(this);
213
			s.accept(this);
214
		}
214
		}
215
		buffer.append("}");//$NON-NLS-1$
215
		this.buffer.append("}");//$NON-NLS-1$
216
		return false;
216
		return false;
217
	}
217
	}
218
218
Lines 221-229 Link Here
221
	 */
221
	 */
222
	public boolean visit(BooleanLiteral node) {
222
	public boolean visit(BooleanLiteral node) {
223
		if (node.booleanValue() == true) {
223
		if (node.booleanValue() == true) {
224
			buffer.append("true");//$NON-NLS-1$
224
			this.buffer.append("true");//$NON-NLS-1$
225
		} else {
225
		} else {
226
			buffer.append("false");//$NON-NLS-1$
226
			this.buffer.append("false");//$NON-NLS-1$
227
		}
227
		}
228
		return false;
228
		return false;
229
	}
229
	}
Lines 232-243 Link Here
232
	 * @see ASTVisitor#visit(BreakStatement)
232
	 * @see ASTVisitor#visit(BreakStatement)
233
	 */
233
	 */
234
	public boolean visit(BreakStatement node) {
234
	public boolean visit(BreakStatement node) {
235
		buffer.append("break");//$NON-NLS-1$
235
		this.buffer.append("break");//$NON-NLS-1$
236
		if (node.getLabel() != null) {
236
		if (node.getLabel() != null) {
237
			buffer.append(" ");//$NON-NLS-1$
237
			this.buffer.append(" ");//$NON-NLS-1$
238
			node.getLabel().accept(this);
238
			node.getLabel().accept(this);
239
		}
239
		}
240
		buffer.append(";");//$NON-NLS-1$
240
		this.buffer.append(";");//$NON-NLS-1$
241
		return false;
241
		return false;
242
	}
242
	}
243
243
Lines 245-253 Link Here
245
	 * @see ASTVisitor#visit(CastExpression)
245
	 * @see ASTVisitor#visit(CastExpression)
246
	 */
246
	 */
247
	public boolean visit(CastExpression node) {
247
	public boolean visit(CastExpression node) {
248
		buffer.append("(");//$NON-NLS-1$
248
		this.buffer.append("(");//$NON-NLS-1$
249
		node.getType().accept(this);
249
		node.getType().accept(this);
250
		buffer.append(")");//$NON-NLS-1$
250
		this.buffer.append(")");//$NON-NLS-1$
251
		node.getExpression().accept(this);
251
		node.getExpression().accept(this);
252
		return false;
252
		return false;
253
	}
253
	}
Lines 256-264 Link Here
256
	 * @see ASTVisitor#visit(CatchClause)
256
	 * @see ASTVisitor#visit(CatchClause)
257
	 */
257
	 */
258
	public boolean visit(CatchClause node) {
258
	public boolean visit(CatchClause node) {
259
		buffer.append("catch (");//$NON-NLS-1$
259
		this.buffer.append("catch (");//$NON-NLS-1$
260
		node.getException().accept(this);
260
		node.getException().accept(this);
261
		buffer.append(") ");//$NON-NLS-1$
261
		this.buffer.append(") ");//$NON-NLS-1$
262
		node.getBody().accept(this);
262
		node.getBody().accept(this);
263
		return false;
263
		return false;
264
	}
264
	}
Lines 267-273 Link Here
267
	 * @see ASTVisitor#visit(CharacterLiteral)
267
	 * @see ASTVisitor#visit(CharacterLiteral)
268
	 */
268
	 */
269
	public boolean visit(CharacterLiteral node) {
269
	public boolean visit(CharacterLiteral node) {
270
		buffer.append(node.getEscapedValue());
270
		this.buffer.append(node.getEscapedValue());
271
		return false;
271
		return false;
272
	}
272
	}
273
273
Lines 277-295 Link Here
277
	public boolean visit(ClassInstanceCreation node) {
277
	public boolean visit(ClassInstanceCreation node) {
278
		if (node.getExpression() != null) {
278
		if (node.getExpression() != null) {
279
			node.getExpression().accept(this);
279
			node.getExpression().accept(this);
280
			buffer.append(".");//$NON-NLS-1$
280
			this.buffer.append(".");//$NON-NLS-1$
281
		}
281
		}
282
		buffer.append("new ");//$NON-NLS-1$
282
		this.buffer.append("new ");//$NON-NLS-1$
283
		node.getName().accept(this);
283
		node.getName().accept(this);
284
		buffer.append("(");//$NON-NLS-1$
284
		this.buffer.append("(");//$NON-NLS-1$
285
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
285
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
286
			Expression e = (Expression) it.next();
286
			Expression e = (Expression) it.next();
287
			e.accept(this);
287
			e.accept(this);
288
			if (it.hasNext()) {
288
			if (it.hasNext()) {
289
				buffer.append(",");//$NON-NLS-1$
289
				this.buffer.append(",");//$NON-NLS-1$
290
			}
290
			}
291
		}
291
		}
292
		buffer.append(")");//$NON-NLS-1$
292
		this.buffer.append(")");//$NON-NLS-1$
293
		if (node.getAnonymousClassDeclaration() != null) {
293
		if (node.getAnonymousClassDeclaration() != null) {
294
			node.getAnonymousClassDeclaration().accept(this);
294
			node.getAnonymousClassDeclaration().accept(this);
295
		}
295
		}
Lines 319-327 Link Here
319
	 */
319
	 */
320
	public boolean visit(ConditionalExpression node) {
320
	public boolean visit(ConditionalExpression node) {
321
		node.getExpression().accept(this);
321
		node.getExpression().accept(this);
322
		buffer.append("?");//$NON-NLS-1$
322
		this.buffer.append("?");//$NON-NLS-1$
323
		node.getThenExpression().accept(this);
323
		node.getThenExpression().accept(this);
324
		buffer.append(":");//$NON-NLS-1$
324
		this.buffer.append(":");//$NON-NLS-1$
325
		node.getElseExpression().accept(this);
325
		node.getElseExpression().accept(this);
326
		return false;
326
		return false;
327
	}
327
	}
Lines 330-344 Link Here
330
	 * @see ASTVisitor#visit(ConstructorInvocation)
330
	 * @see ASTVisitor#visit(ConstructorInvocation)
331
	 */
331
	 */
332
	public boolean visit(ConstructorInvocation node) {
332
	public boolean visit(ConstructorInvocation node) {
333
		buffer.append("this(");//$NON-NLS-1$
333
		this.buffer.append("this(");//$NON-NLS-1$
334
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
334
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
335
			Expression e = (Expression) it.next();
335
			Expression e = (Expression) it.next();
336
			e.accept(this);
336
			e.accept(this);
337
			if (it.hasNext()) {
337
			if (it.hasNext()) {
338
				buffer.append(",");//$NON-NLS-1$
338
				this.buffer.append(",");//$NON-NLS-1$
339
			}
339
			}
340
		}
340
		}
341
		buffer.append(");");//$NON-NLS-1$
341
		this.buffer.append(");");//$NON-NLS-1$
342
		return false;
342
		return false;
343
	}
343
	}
344
344
Lines 346-357 Link Here
346
	 * @see ASTVisitor#visit(ContinueStatement)
346
	 * @see ASTVisitor#visit(ContinueStatement)
347
	 */
347
	 */
348
	public boolean visit(ContinueStatement node) {
348
	public boolean visit(ContinueStatement node) {
349
		buffer.append("continue");//$NON-NLS-1$
349
		this.buffer.append("continue");//$NON-NLS-1$
350
		if (node.getLabel() != null) {
350
		if (node.getLabel() != null) {
351
			buffer.append(" ");//$NON-NLS-1$
351
			this.buffer.append(" ");//$NON-NLS-1$
352
			node.getLabel().accept(this);
352
			node.getLabel().accept(this);
353
		}
353
		}
354
		buffer.append(";");//$NON-NLS-1$
354
		this.buffer.append(";");//$NON-NLS-1$
355
		return false;
355
		return false;
356
	}
356
	}
357
357
Lines 359-369 Link Here
359
	 * @see ASTVisitor#visit(DoStatement)
359
	 * @see ASTVisitor#visit(DoStatement)
360
	 */
360
	 */
361
	public boolean visit(DoStatement node) {
361
	public boolean visit(DoStatement node) {
362
		buffer.append("do ");//$NON-NLS-1$
362
		this.buffer.append("do ");//$NON-NLS-1$
363
		node.getBody().accept(this);
363
		node.getBody().accept(this);
364
		buffer.append(" while (");//$NON-NLS-1$
364
		this.buffer.append(" while (");//$NON-NLS-1$
365
		node.getExpression().accept(this);
365
		node.getExpression().accept(this);
366
		buffer.append(");");//$NON-NLS-1$
366
		this.buffer.append(");");//$NON-NLS-1$
367
		return false;
367
		return false;
368
	}
368
	}
369
369
Lines 371-377 Link Here
371
	 * @see ASTVisitor#visit(EmptyStatement)
371
	 * @see ASTVisitor#visit(EmptyStatement)
372
	 */
372
	 */
373
	public boolean visit(EmptyStatement node) {
373
	public boolean visit(EmptyStatement node) {
374
		buffer.append(";");//$NON-NLS-1$
374
		this.buffer.append(";");//$NON-NLS-1$
375
		return false;
375
		return false;
376
	}
376
	}
377
377
Lines 380-386 Link Here
380
	 */
380
	 */
381
	public boolean visit(ExpressionStatement node) {
381
	public boolean visit(ExpressionStatement node) {
382
		node.getExpression().accept(this);
382
		node.getExpression().accept(this);
383
		buffer.append(";");//$NON-NLS-1$
383
		this.buffer.append(";");//$NON-NLS-1$
384
		return false;
384
		return false;
385
	}
385
	}
386
386
Lines 389-395 Link Here
389
	 */
389
	 */
390
	public boolean visit(FieldAccess node) {
390
	public boolean visit(FieldAccess node) {
391
		node.getExpression().accept(this);
391
		node.getExpression().accept(this);
392
		buffer.append(".");//$NON-NLS-1$
392
		this.buffer.append(".");//$NON-NLS-1$
393
		node.getName().accept(this);
393
		node.getName().accept(this);
394
		return false;
394
		return false;
395
	}
395
	}
Lines 403-417 Link Here
403
		}
403
		}
404
		printModifiers(node.getModifiers());
404
		printModifiers(node.getModifiers());
405
		node.getType().accept(this);
405
		node.getType().accept(this);
406
		buffer.append(" ");//$NON-NLS-1$
406
		this.buffer.append(" ");//$NON-NLS-1$
407
		for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
407
		for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
408
			VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
408
			VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
409
			f.accept(this);
409
			f.accept(this);
410
			if (it.hasNext()) {
410
			if (it.hasNext()) {
411
				buffer.append(", ");//$NON-NLS-1$
411
				this.buffer.append(", ");//$NON-NLS-1$
412
			}
412
			}
413
		}
413
		}
414
		buffer.append(";");//$NON-NLS-1$
414
		this.buffer.append(";");//$NON-NLS-1$
415
		return false;
415
		return false;
416
	}
416
	}
417
417
Lines 419-439 Link Here
419
	 * @see ASTVisitor#visit(ForStatement)
419
	 * @see ASTVisitor#visit(ForStatement)
420
	 */
420
	 */
421
	public boolean visit(ForStatement node) {
421
	public boolean visit(ForStatement node) {
422
		buffer.append("for (");//$NON-NLS-1$
422
		this.buffer.append("for (");//$NON-NLS-1$
423
		for (Iterator it = node.initializers().iterator(); it.hasNext(); ) {
423
		for (Iterator it = node.initializers().iterator(); it.hasNext(); ) {
424
			Expression e = (Expression) it.next();
424
			Expression e = (Expression) it.next();
425
			e.accept(this);
425
			e.accept(this);
426
		}
426
		}
427
		buffer.append("; ");//$NON-NLS-1$
427
		this.buffer.append("; ");//$NON-NLS-1$
428
		if (node.getExpression() != null) {
428
		if (node.getExpression() != null) {
429
			node.getExpression().accept(this);
429
			node.getExpression().accept(this);
430
		}
430
		}
431
		buffer.append("; ");//$NON-NLS-1$
431
		this.buffer.append("; ");//$NON-NLS-1$
432
		for (Iterator it = node.updaters().iterator(); it.hasNext(); ) {
432
		for (Iterator it = node.updaters().iterator(); it.hasNext(); ) {
433
			Expression e = (Expression) it.next();
433
			Expression e = (Expression) it.next();
434
			e.accept(this);
434
			e.accept(this);
435
		}
435
		}
436
		buffer.append(") ");//$NON-NLS-1$
436
		this.buffer.append(") ");//$NON-NLS-1$
437
		node.getBody().accept(this);
437
		node.getBody().accept(this);
438
		return false;
438
		return false;
439
	}
439
	}
Lines 442-453 Link Here
442
	 * @see ASTVisitor#visit(IfStatement)
442
	 * @see ASTVisitor#visit(IfStatement)
443
	 */
443
	 */
444
	public boolean visit(IfStatement node) {
444
	public boolean visit(IfStatement node) {
445
		buffer.append("if (");//$NON-NLS-1$
445
		this.buffer.append("if (");//$NON-NLS-1$
446
		node.getExpression().accept(this);
446
		node.getExpression().accept(this);
447
		buffer.append(") ");//$NON-NLS-1$
447
		this.buffer.append(") ");//$NON-NLS-1$
448
		node.getThenStatement().accept(this);
448
		node.getThenStatement().accept(this);
449
		if (node.getElseStatement() != null) {
449
		if (node.getElseStatement() != null) {
450
			buffer.append(" else ");//$NON-NLS-1$
450
			this.buffer.append(" else ");//$NON-NLS-1$
451
			node.getElseStatement().accept(this);
451
			node.getElseStatement().accept(this);
452
		}
452
		}
453
		return false;
453
		return false;
Lines 457-468 Link Here
457
	 * @see ASTVisitor#visit(ImportDeclaration)
457
	 * @see ASTVisitor#visit(ImportDeclaration)
458
	 */
458
	 */
459
	public boolean visit(ImportDeclaration node) {
459
	public boolean visit(ImportDeclaration node) {
460
		buffer.append("import ");//$NON-NLS-1$
460
		this.buffer.append("import ");//$NON-NLS-1$
461
		node.getName().accept(this);
461
		node.getName().accept(this);
462
		if (node.isOnDemand()) {
462
		if (node.isOnDemand()) {
463
			buffer.append(".*");//$NON-NLS-1$
463
			this.buffer.append(".*");//$NON-NLS-1$
464
		}
464
		}
465
		buffer.append(";");//$NON-NLS-1$
465
		this.buffer.append(";");//$NON-NLS-1$
466
		return false;
466
		return false;
467
	}
467
	}
468
468
Lines 471-480 Link Here
471
	 */
471
	 */
472
	public boolean visit(InfixExpression node) {
472
	public boolean visit(InfixExpression node) {
473
		node.getLeftOperand().accept(this);
473
		node.getLeftOperand().accept(this);
474
		buffer.append(node.getOperator().toString());
474
		this.buffer.append(node.getOperator().toString());
475
		node.getRightOperand().accept(this);
475
		node.getRightOperand().accept(this);
476
		for (Iterator it = node.extendedOperands().iterator(); it.hasNext(); ) {
476
		for (Iterator it = node.extendedOperands().iterator(); it.hasNext(); ) {
477
			buffer.append(node.getOperator().toString());
477
			this.buffer.append(node.getOperator().toString());
478
			Expression e = (Expression) it.next();
478
			Expression e = (Expression) it.next();
479
			e.accept(this);
479
			e.accept(this);
480
		}
480
		}
Lines 486-492 Link Here
486
	 */
486
	 */
487
	public boolean visit(InstanceofExpression node) {
487
	public boolean visit(InstanceofExpression node) {
488
		node.getLeftOperand().accept(this);
488
		node.getLeftOperand().accept(this);
489
		buffer.append(" instanceof ");//$NON-NLS-1$
489
		this.buffer.append(" instanceof ");//$NON-NLS-1$
490
		node.getRightOperand().accept(this);
490
		node.getRightOperand().accept(this);
491
		return false;
491
		return false;
492
	}
492
	}
Lines 507-522 Link Here
507
	 * @see ASTVisitor#visit(Javadoc)
507
	 * @see ASTVisitor#visit(Javadoc)
508
	 */
508
	 */
509
	public boolean visit(Javadoc node) {
509
	public boolean visit(Javadoc node) {
510
		buffer.append(node.getComment());
510
		this.buffer.append("[block: "+node.isBlock());	//$NON-NLS-1$
511
		this.buffer.append("][javadoc: "+node.isJavadoc());	//$NON-NLS-1$
512
		this.buffer.append("][tags:"+node.tags().size()); //$NON-NLS-1$
513
		this.buffer.append("]");	//$NON-NLS-1$
514
		for (Iterator it = node.tags().iterator(); it.hasNext(); ) {
515
			JavadocTag tag = (JavadocTag) it.next();
516
			this.buffer.append("\n * "); //$NON-NLS-1$
517
			tag.accept(this);
518
		}
519
		this.buffer.append("\nText:"); //$NON-NLS-1$
520
		this.buffer.append(node.getText());
511
		return false;
521
		return false;
512
	}
522
	}
513
523
	public boolean visit(JavadocTag node) {
524
		boolean hasIdentifier = node.getIdentifier().length() > 0;
525
		if (hasIdentifier) {
526
			this.buffer.append('@');
527
			this.buffer.append(node.getIdentifier());
528
		}
529
		boolean hasReference = node.getReference() != null;
530
		if (hasReference) {
531
			if (hasIdentifier) {
532
				this.buffer.append(' ');
533
			}
534
			node.getReference().accept(this);
535
		}
536
		String txt = node.getDescription();
537
		if (txt.length() > 0) {
538
			if (hasIdentifier || hasReference) {
539
				this.buffer.append(' ');
540
			}
541
			this.buffer.append(txt);
542
		}
543
		return false;
544
	}
545
	public boolean visit(JavadocEmbeddedTag node) {
546
		boolean hasIdentifier = node.getIdentifier().length() > 0;
547
		this.buffer.append('{');
548
		if (hasIdentifier) {
549
			this.buffer.append('@');
550
			this.buffer.append(node.getIdentifier());
551
		}
552
		boolean hasTag = node.getTag() != null;
553
		if (hasTag) {
554
			if (hasIdentifier) {
555
				this.buffer.append(' ');
556
			}
557
			node.getTag().accept(this);
558
		}
559
		this.buffer.append('}');
560
		return false;
561
	}
562
	
514
	/*
563
	/*
515
	 * @see ASTVisitor#visit(LabeledStatement)
564
	 * @see ASTVisitor#visit(LabeledStatement)
516
	 */
565
	 */
517
	public boolean visit(LabeledStatement node) {
566
	public boolean visit(LabeledStatement node) {
518
		node.getLabel().accept(this);
567
		node.getLabel().accept(this);
519
		buffer.append(": ");//$NON-NLS-1$
568
		this.buffer.append(": ");//$NON-NLS-1$
520
		node.getBody().accept(this);
569
		node.getBody().accept(this);
521
		return false;
570
		return false;
522
	}
571
	}
Lines 531-561 Link Here
531
		printModifiers(node.getModifiers());
580
		printModifiers(node.getModifiers());
532
		if (!node.isConstructor()) {
581
		if (!node.isConstructor()) {
533
			node.getReturnType().accept(this);
582
			node.getReturnType().accept(this);
534
			buffer.append(" ");//$NON-NLS-1$
583
			this.buffer.append(" ");//$NON-NLS-1$
535
		}
584
		}
536
		node.getName().accept(this);
585
		node.getName().accept(this);
537
		buffer.append("(");//$NON-NLS-1$
586
		this.buffer.append("(");//$NON-NLS-1$
538
		for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
587
		for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
539
			SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
588
			SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
540
			v.accept(this);
589
			v.accept(this);
541
			if (it.hasNext()) {
590
			if (it.hasNext()) {
542
				buffer.append(",");//$NON-NLS-1$
591
				this.buffer.append(",");//$NON-NLS-1$
543
			}
592
			}
544
		}
593
		}
545
		buffer.append(")");//$NON-NLS-1$
594
		this.buffer.append(")");//$NON-NLS-1$
546
		if (!node.thrownExceptions().isEmpty()) {
595
		if (!node.thrownExceptions().isEmpty()) {
547
			buffer.append(" throws ");//$NON-NLS-1$
596
			this.buffer.append(" throws ");//$NON-NLS-1$
548
			for (Iterator it = node.thrownExceptions().iterator(); it.hasNext(); ) {
597
			for (Iterator it = node.thrownExceptions().iterator(); it.hasNext(); ) {
549
				Name n = (Name) it.next();
598
				Name n = (Name) it.next();
550
				n.accept(this);
599
				n.accept(this);
551
				if (it.hasNext()) {
600
				if (it.hasNext()) {
552
					buffer.append(", ");//$NON-NLS-1$
601
					this.buffer.append(", ");//$NON-NLS-1$
553
				}
602
				}
554
			}
603
			}
555
			buffer.append(" ");//$NON-NLS-1$
604
			this.buffer.append(" ");//$NON-NLS-1$
556
		}
605
		}
557
		if (node.getBody() == null) {
606
		if (node.getBody() == null) {
558
			buffer.append(";");//$NON-NLS-1$
607
			this.buffer.append(";");//$NON-NLS-1$
559
		} else {
608
		} else {
560
			node.getBody().accept(this);
609
			node.getBody().accept(this);
561
		}
610
		}
Lines 568-585 Link Here
568
	public boolean visit(MethodInvocation node) {
617
	public boolean visit(MethodInvocation node) {
569
		if (node.getExpression() != null) {
618
		if (node.getExpression() != null) {
570
			node.getExpression().accept(this);
619
			node.getExpression().accept(this);
571
			buffer.append(".");//$NON-NLS-1$
620
			this.buffer.append(".");//$NON-NLS-1$
572
		}
621
		}
573
		node.getName().accept(this);
622
		node.getName().accept(this);
574
		buffer.append("(");//$NON-NLS-1$
623
		this.buffer.append("(");//$NON-NLS-1$
575
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
624
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
576
			Expression e = (Expression) it.next();
625
			Expression e = (Expression) it.next();
577
			e.accept(this);
626
			e.accept(this);
578
			if (it.hasNext()) {
627
			if (it.hasNext()) {
579
				buffer.append(",");//$NON-NLS-1$
628
				this.buffer.append(",");//$NON-NLS-1$
580
			}
629
			}
581
		}
630
		}
582
		buffer.append(")");//$NON-NLS-1$
631
		this.buffer.append(")");//$NON-NLS-1$
583
		return false;
632
		return false;
584
	}
633
	}
585
634
Lines 587-593 Link Here
587
	 * @see ASTVisitor#visit(NullLiteral)
636
	 * @see ASTVisitor#visit(NullLiteral)
588
	 */
637
	 */
589
	public boolean visit(NullLiteral node) {
638
	public boolean visit(NullLiteral node) {
590
		buffer.append("null");//$NON-NLS-1$
639
		this.buffer.append("null");//$NON-NLS-1$
591
		return false;
640
		return false;
592
	}
641
	}
593
642
Lines 595-601 Link Here
595
	 * @see ASTVisitor#visit(NumberLiteral)
644
	 * @see ASTVisitor#visit(NumberLiteral)
596
	 */
645
	 */
597
	public boolean visit(NumberLiteral node) {
646
	public boolean visit(NumberLiteral node) {
598
		buffer.append(node.getToken());
647
		this.buffer.append(node.getToken());
599
		return false;
648
		return false;
600
	}
649
	}
601
650
Lines 603-611 Link Here
603
	 * @see ASTVisitor#visit(PackageDeclaration)
652
	 * @see ASTVisitor#visit(PackageDeclaration)
604
	 */
653
	 */
605
	public boolean visit(PackageDeclaration node) {
654
	public boolean visit(PackageDeclaration node) {
606
		buffer.append("package ");//$NON-NLS-1$
655
		this.buffer.append("package ");//$NON-NLS-1$
607
		node.getName().accept(this);
656
		node.getName().accept(this);
608
		buffer.append(";");//$NON-NLS-1$
657
		this.buffer.append(";");//$NON-NLS-1$
609
		return false;
658
		return false;
610
	}
659
	}
611
660
Lines 613-621 Link Here
613
	 * @see ASTVisitor#visit(ParenthesizedExpression)
662
	 * @see ASTVisitor#visit(ParenthesizedExpression)
614
	 */
663
	 */
615
	public boolean visit(ParenthesizedExpression node) {
664
	public boolean visit(ParenthesizedExpression node) {
616
		buffer.append("(");//$NON-NLS-1$
665
		this.buffer.append("(");//$NON-NLS-1$
617
		node.getExpression().accept(this);
666
		node.getExpression().accept(this);
618
		buffer.append(")");//$NON-NLS-1$
667
		this.buffer.append(")");//$NON-NLS-1$
619
		return false;
668
		return false;
620
	}
669
	}
621
670
Lines 624-630 Link Here
624
	 */
673
	 */
625
	public boolean visit(PostfixExpression node) {
674
	public boolean visit(PostfixExpression node) {
626
		node.getOperand().accept(this);
675
		node.getOperand().accept(this);
627
		buffer.append(node.getOperator().toString());
676
		this.buffer.append(node.getOperator().toString());
628
		return false;
677
		return false;
629
	}
678
	}
630
679
Lines 632-638 Link Here
632
	 * @see ASTVisitor#visit(PrefixExpression)
681
	 * @see ASTVisitor#visit(PrefixExpression)
633
	 */
682
	 */
634
	public boolean visit(PrefixExpression node) {
683
	public boolean visit(PrefixExpression node) {
635
		buffer.append(node.getOperator().toString());
684
		this.buffer.append(node.getOperator().toString());
636
		node.getOperand().accept(this);
685
		node.getOperand().accept(this);
637
		return false;
686
		return false;
638
	}
687
	}
Lines 641-647 Link Here
641
	 * @see ASTVisitor#visit(PrimitiveType)
690
	 * @see ASTVisitor#visit(PrimitiveType)
642
	 */
691
	 */
643
	public boolean visit(PrimitiveType node) {
692
	public boolean visit(PrimitiveType node) {
644
		buffer.append(node.getPrimitiveTypeCode().toString());
693
		this.buffer.append(node.getPrimitiveTypeCode().toString());
645
		return false;
694
		return false;
646
	}
695
	}
647
696
Lines 650-656 Link Here
650
	 */
699
	 */
651
	public boolean visit(QualifiedName node) {
700
	public boolean visit(QualifiedName node) {
652
		node.getQualifier().accept(this);
701
		node.getQualifier().accept(this);
653
		buffer.append(".");//$NON-NLS-1$
702
		this.buffer.append(".");//$NON-NLS-1$
654
		node.getName().accept(this);
703
		node.getName().accept(this);
655
		return false;
704
		return false;
656
	}
705
	}
Lines 659-670 Link Here
659
	 * @see ASTVisitor#visit(ReturnStatement)
708
	 * @see ASTVisitor#visit(ReturnStatement)
660
	 */
709
	 */
661
	public boolean visit(ReturnStatement node) {
710
	public boolean visit(ReturnStatement node) {
662
		buffer.append("return");//$NON-NLS-1$
711
		this.buffer.append("return");//$NON-NLS-1$
663
		if (node.getExpression() != null) {
712
		if (node.getExpression() != null) {
664
			buffer.append(" ");//$NON-NLS-1$
713
			this.buffer.append(" ");//$NON-NLS-1$
665
			node.getExpression().accept(this);
714
			node.getExpression().accept(this);
666
		}
715
		}
667
		buffer.append(";");//$NON-NLS-1$
716
		this.buffer.append(";");//$NON-NLS-1$
668
		return false;
717
		return false;
669
	}
718
	}
670
719
Lines 672-678 Link Here
672
	 * @see ASTVisitor#visit(SimpleName)
721
	 * @see ASTVisitor#visit(SimpleName)
673
	 */
722
	 */
674
	public boolean visit(SimpleName node) {
723
	public boolean visit(SimpleName node) {
675
		buffer.append(node.getIdentifier());
724
		this.buffer.append(node.getIdentifier());
676
		return false;
725
		return false;
677
	}
726
	}
678
727
Lines 689-698 Link Here
689
	public boolean visit(SingleVariableDeclaration node) {
738
	public boolean visit(SingleVariableDeclaration node) {
690
		printModifiers(node.getModifiers());
739
		printModifiers(node.getModifiers());
691
		node.getType().accept(this);
740
		node.getType().accept(this);
692
		buffer.append(" ");//$NON-NLS-1$
741
		this.buffer.append(" ");//$NON-NLS-1$
693
		node.getName().accept(this);
742
		node.getName().accept(this);
694
		if (node.getInitializer() != null) {
743
		if (node.getInitializer() != null) {
695
			buffer.append("=");//$NON-NLS-1$
744
			this.buffer.append("=");//$NON-NLS-1$
696
			node.getInitializer().accept(this);
745
			node.getInitializer().accept(this);
697
		}
746
		}
698
		return false;
747
		return false;
Lines 702-708 Link Here
702
	 * @see ASTVisitor#visit(StringLiteral)
751
	 * @see ASTVisitor#visit(StringLiteral)
703
	 */
752
	 */
704
	public boolean visit(StringLiteral node) {
753
	public boolean visit(StringLiteral node) {
705
		buffer.append(node.getEscapedValue());
754
		this.buffer.append(node.getEscapedValue());
706
		return false;
755
		return false;
707
	}
756
	}
708
757
Lines 712-728 Link Here
712
	public boolean visit(SuperConstructorInvocation node) {
761
	public boolean visit(SuperConstructorInvocation node) {
713
		if (node.getExpression() != null) {
762
		if (node.getExpression() != null) {
714
			node.getExpression().accept(this);
763
			node.getExpression().accept(this);
715
			buffer.append(".");//$NON-NLS-1$
764
			this.buffer.append(".");//$NON-NLS-1$
716
		}
765
		}
717
		buffer.append("super(");//$NON-NLS-1$
766
		this.buffer.append("super(");//$NON-NLS-1$
718
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
767
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
719
			Expression e = (Expression) it.next();
768
			Expression e = (Expression) it.next();
720
			e.accept(this);
769
			e.accept(this);
721
			if (it.hasNext()) {
770
			if (it.hasNext()) {
722
				buffer.append(",");//$NON-NLS-1$
771
				this.buffer.append(",");//$NON-NLS-1$
723
			}
772
			}
724
		}
773
		}
725
		buffer.append(");");//$NON-NLS-1$
774
		this.buffer.append(");");//$NON-NLS-1$
726
		return false;
775
		return false;
727
	}
776
	}
728
777
Lines 732-740 Link Here
732
	public boolean visit(SuperFieldAccess node) {
781
	public boolean visit(SuperFieldAccess node) {
733
		if (node.getQualifier() != null) {
782
		if (node.getQualifier() != null) {
734
			node.getQualifier().accept(this);
783
			node.getQualifier().accept(this);
735
			buffer.append(".");//$NON-NLS-1$
784
			this.buffer.append(".");//$NON-NLS-1$
736
		}
785
		}
737
		buffer.append("super.");//$NON-NLS-1$
786
		this.buffer.append("super.");//$NON-NLS-1$
738
		node.getName().accept(this);
787
		node.getName().accept(this);
739
		return false;
788
		return false;
740
	}
789
	}
Lines 745-763 Link Here
745
	public boolean visit(SuperMethodInvocation node) {
794
	public boolean visit(SuperMethodInvocation node) {
746
		if (node.getQualifier() != null) {
795
		if (node.getQualifier() != null) {
747
			node.getQualifier().accept(this);
796
			node.getQualifier().accept(this);
748
			buffer.append(".");//$NON-NLS-1$
797
			this.buffer.append(".");//$NON-NLS-1$
749
		}
798
		}
750
		buffer.append("super.");//$NON-NLS-1$
799
		this.buffer.append("super.");//$NON-NLS-1$
751
		node.getName().accept(this);
800
		node.getName().accept(this);
752
		buffer.append("(");//$NON-NLS-1$
801
		this.buffer.append("(");//$NON-NLS-1$
753
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
802
		for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
754
			Expression e = (Expression) it.next();
803
			Expression e = (Expression) it.next();
755
			e.accept(this);
804
			e.accept(this);
756
			if (it.hasNext()) {
805
			if (it.hasNext()) {
757
				buffer.append(",");//$NON-NLS-1$
806
				this.buffer.append(",");//$NON-NLS-1$
758
			}
807
			}
759
		}
808
		}
760
		buffer.append(")");//$NON-NLS-1$
809
		this.buffer.append(")");//$NON-NLS-1$
761
		return false;
810
		return false;
762
	}
811
	}
763
812
Lines 766-776 Link Here
766
	 */
815
	 */
767
	public boolean visit(SwitchCase node) {
816
	public boolean visit(SwitchCase node) {
768
		if (node.isDefault()) {
817
		if (node.isDefault()) {
769
			buffer.append("default :");//$NON-NLS-1$
818
			this.buffer.append("default :");//$NON-NLS-1$
770
		} else {
819
		} else {
771
			buffer.append("case ");//$NON-NLS-1$
820
			this.buffer.append("case ");//$NON-NLS-1$
772
			node.getExpression().accept(this);
821
			node.getExpression().accept(this);
773
			buffer.append(":");//$NON-NLS-1$
822
			this.buffer.append(":");//$NON-NLS-1$
774
		}
823
		}
775
		return false;
824
		return false;
776
	}
825
	}
Lines 779-793 Link Here
779
	 * @see ASTVisitor#visit(SwitchStatement)
828
	 * @see ASTVisitor#visit(SwitchStatement)
780
	 */
829
	 */
781
	public boolean visit(SwitchStatement node) {
830
	public boolean visit(SwitchStatement node) {
782
		buffer.append("switch (");//$NON-NLS-1$
831
		this.buffer.append("switch (");//$NON-NLS-1$
783
		node.getExpression().accept(this);
832
		node.getExpression().accept(this);
784
		buffer.append(") ");//$NON-NLS-1$
833
		this.buffer.append(") ");//$NON-NLS-1$
785
		buffer.append("{");//$NON-NLS-1$
834
		this.buffer.append("{");//$NON-NLS-1$
786
		for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
835
		for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
787
			Statement s = (Statement) it.next();
836
			Statement s = (Statement) it.next();
788
			s.accept(this);
837
			s.accept(this);
789
		}
838
		}
790
		buffer.append("}");//$NON-NLS-1$
839
		this.buffer.append("}");//$NON-NLS-1$
791
		return false;
840
		return false;
792
	}
841
	}
793
842
Lines 795-803 Link Here
795
	 * @see ASTVisitor#visit(SynchronizedStatement)
844
	 * @see ASTVisitor#visit(SynchronizedStatement)
796
	 */
845
	 */
797
	public boolean visit(SynchronizedStatement node) {
846
	public boolean visit(SynchronizedStatement node) {
798
		buffer.append("synchronized (");//$NON-NLS-1$
847
		this.buffer.append("synchronized (");//$NON-NLS-1$
799
		node.getExpression().accept(this);
848
		node.getExpression().accept(this);
800
		buffer.append(") ");//$NON-NLS-1$
849
		this.buffer.append(") ");//$NON-NLS-1$
801
		node.getBody().accept(this);
850
		node.getBody().accept(this);
802
		return false;
851
		return false;
803
	}
852
	}
Lines 808-816 Link Here
808
	public boolean visit(ThisExpression node) {
857
	public boolean visit(ThisExpression node) {
809
		if (node.getQualifier() != null) {
858
		if (node.getQualifier() != null) {
810
			node.getQualifier().accept(this);
859
			node.getQualifier().accept(this);
811
			buffer.append(".");//$NON-NLS-1$
860
			this.buffer.append(".");//$NON-NLS-1$
812
		}
861
		}
813
		buffer.append("this");//$NON-NLS-1$
862
		this.buffer.append("this");//$NON-NLS-1$
814
		return false;
863
		return false;
815
	}
864
	}
816
865
Lines 818-826 Link Here
818
	 * @see ASTVisitor#visit(ThrowStatement)
867
	 * @see ASTVisitor#visit(ThrowStatement)
819
	 */
868
	 */
820
	public boolean visit(ThrowStatement node) {
869
	public boolean visit(ThrowStatement node) {
821
		buffer.append("throw ");//$NON-NLS-1$
870
		this.buffer.append("throw ");//$NON-NLS-1$
822
		node.getExpression().accept(this);
871
		node.getExpression().accept(this);
823
		buffer.append(";");//$NON-NLS-1$
872
		this.buffer.append(";");//$NON-NLS-1$
824
		return false;
873
		return false;
825
	}
874
	}
826
875
Lines 828-842 Link Here
828
	 * @see ASTVisitor#visit(TryStatement)
877
	 * @see ASTVisitor#visit(TryStatement)
829
	 */
878
	 */
830
	public boolean visit(TryStatement node) {
879
	public boolean visit(TryStatement node) {
831
		buffer.append("try ");//$NON-NLS-1$
880
		this.buffer.append("try ");//$NON-NLS-1$
832
		node.getBody().accept(this);
881
		node.getBody().accept(this);
833
		buffer.append(" ");//$NON-NLS-1$
882
		this.buffer.append(" ");//$NON-NLS-1$
834
		for (Iterator it = node.catchClauses().iterator(); it.hasNext(); ) {
883
		for (Iterator it = node.catchClauses().iterator(); it.hasNext(); ) {
835
			CatchClause cc = (CatchClause) it.next();
884
			CatchClause cc = (CatchClause) it.next();
836
			cc.accept(this);
885
			cc.accept(this);
837
		}
886
		}
838
		if (node.getFinally() != null) {
887
		if (node.getFinally() != null) {
839
			buffer.append("finally ");//$NON-NLS-1$
888
			this.buffer.append("finally ");//$NON-NLS-1$
840
			node.getFinally().accept(this);
889
			node.getFinally().accept(this);
841
		}
890
		}
842
		return false;
891
		return false;
Lines 850-880 Link Here
850
			node.getJavadoc().accept(this);
899
			node.getJavadoc().accept(this);
851
		}
900
		}
852
		printModifiers(node.getModifiers());
901
		printModifiers(node.getModifiers());
853
		buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
902
		this.buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
854
		node.getName().accept(this);
903
		node.getName().accept(this);
855
		buffer.append(" ");//$NON-NLS-1$
904
		this.buffer.append(" ");//$NON-NLS-1$
856
		if (node.getSuperclass() != null) {
905
		if (node.getSuperclass() != null) {
857
			buffer.append("extends ");//$NON-NLS-1$
906
			this.buffer.append("extends ");//$NON-NLS-1$
858
			node.getSuperclass().accept(this);
907
			node.getSuperclass().accept(this);
859
			buffer.append(" ");//$NON-NLS-1$
908
			this.buffer.append(" ");//$NON-NLS-1$
860
		}
909
		}
861
		if (!node.superInterfaces().isEmpty()) {
910
		if (!node.superInterfaces().isEmpty()) {
862
			buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
911
			this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
863
			for (Iterator it = node.superInterfaces().iterator(); it.hasNext(); ) {
912
			for (Iterator it = node.superInterfaces().iterator(); it.hasNext(); ) {
864
				Name n = (Name) it.next();
913
				Name n = (Name) it.next();
865
				n.accept(this);
914
				n.accept(this);
866
				if (it.hasNext()) {
915
				if (it.hasNext()) {
867
					buffer.append(", ");//$NON-NLS-1$
916
					this.buffer.append(", ");//$NON-NLS-1$
868
				}
917
				}
869
			}
918
			}
870
			buffer.append(" ");//$NON-NLS-1$
919
			this.buffer.append(" ");//$NON-NLS-1$
871
		}
920
		}
872
		buffer.append("{");//$NON-NLS-1$
921
		this.buffer.append("{");//$NON-NLS-1$
873
		for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
922
		for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
874
			BodyDeclaration d = (BodyDeclaration) it.next();
923
			BodyDeclaration d = (BodyDeclaration) it.next();
875
			d.accept(this);
924
			d.accept(this);
876
		}
925
		}
877
		buffer.append("}");//$NON-NLS-1$
926
		this.buffer.append("}");//$NON-NLS-1$
878
		return false;
927
		return false;
879
	}
928
	}
880
929
Lines 883-889 Link Here
883
	 */
932
	 */
884
	public boolean visit(TypeDeclarationStatement node) {
933
	public boolean visit(TypeDeclarationStatement node) {
885
		node.getTypeDeclaration().accept(this);
934
		node.getTypeDeclaration().accept(this);
886
		buffer.append(";");//$NON-NLS-1$
935
		this.buffer.append(";");//$NON-NLS-1$
887
		return false;
936
		return false;
888
	}
937
	}
889
938
Lines 892-898 Link Here
892
	 */
941
	 */
893
	public boolean visit(TypeLiteral node) {
942
	public boolean visit(TypeLiteral node) {
894
		node.getType().accept(this);
943
		node.getType().accept(this);
895
		buffer.append(".class");//$NON-NLS-1$
944
		this.buffer.append(".class");//$NON-NLS-1$
896
		return false;
945
		return false;
897
	}
946
	}
898
947
Lines 902-916 Link Here
902
	public boolean visit(VariableDeclarationExpression node) {
951
	public boolean visit(VariableDeclarationExpression node) {
903
		printModifiers(node.getModifiers());
952
		printModifiers(node.getModifiers());
904
		node.getType().accept(this);
953
		node.getType().accept(this);
905
		buffer.append(" ");//$NON-NLS-1$
954
		this.buffer.append(" ");//$NON-NLS-1$
906
		for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
955
		for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
907
			VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
956
			VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
908
			f.accept(this);
957
			f.accept(this);
909
			if (it.hasNext()) {
958
			if (it.hasNext()) {
910
				buffer.append(", ");//$NON-NLS-1$
959
				this.buffer.append(", ");//$NON-NLS-1$
911
			}
960
			}
912
		}
961
		}
913
		buffer.append(";");//$NON-NLS-1$
962
		this.buffer.append(";");//$NON-NLS-1$
914
		return false;
963
		return false;
915
	}
964
	}
916
965
Lines 920-929 Link Here
920
	public boolean visit(VariableDeclarationFragment node) {
969
	public boolean visit(VariableDeclarationFragment node) {
921
		node.getName().accept(this);
970
		node.getName().accept(this);
922
		for (int i = 0; i < node.getExtraDimensions(); i++) {
971
		for (int i = 0; i < node.getExtraDimensions(); i++) {
923
			buffer.append("[]");//$NON-NLS-1$
972
			this.buffer.append("[]");//$NON-NLS-1$
924
		}
973
		}
925
		if (node.getInitializer() != null) {
974
		if (node.getInitializer() != null) {
926
			buffer.append("=");//$NON-NLS-1$
975
			this.buffer.append("=");//$NON-NLS-1$
927
			node.getInitializer().accept(this);
976
			node.getInitializer().accept(this);
928
		}
977
		}
929
		return false;
978
		return false;
Lines 935-949 Link Here
935
	public boolean visit(VariableDeclarationStatement node) {
984
	public boolean visit(VariableDeclarationStatement node) {
936
		printModifiers(node.getModifiers());
985
		printModifiers(node.getModifiers());
937
		node.getType().accept(this);
986
		node.getType().accept(this);
938
		buffer.append(" ");//$NON-NLS-1$
987
		this.buffer.append(" ");//$NON-NLS-1$
939
		for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
988
		for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
940
			VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
989
			VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
941
			f.accept(this);
990
			f.accept(this);
942
			if (it.hasNext()) {
991
			if (it.hasNext()) {
943
				buffer.append(", ");//$NON-NLS-1$
992
				this.buffer.append(", ");//$NON-NLS-1$
944
			}
993
			}
945
		}
994
		}
946
		buffer.append(";");//$NON-NLS-1$
995
		this.buffer.append(";");//$NON-NLS-1$
947
		return false;
996
		return false;
948
	}
997
	}
949
998
Lines 951-959 Link Here
951
	 * @see ASTVisitor#visit(WhileStatement)
1000
	 * @see ASTVisitor#visit(WhileStatement)
952
	 */
1001
	 */
953
	public boolean visit(WhileStatement node) {
1002
	public boolean visit(WhileStatement node) {
954
		buffer.append("while (");//$NON-NLS-1$
1003
		this.buffer.append("while (");//$NON-NLS-1$
955
		node.getExpression().accept(this);
1004
		node.getExpression().accept(this);
956
		buffer.append(") ");//$NON-NLS-1$
1005
		this.buffer.append(") ");//$NON-NLS-1$
957
		node.getBody().accept(this);
1006
		node.getBody().accept(this);
958
		return false;
1007
		return false;
959
	}
1008
	}
(-)dom/org/eclipse/jdt/core/dom/QualifiedName.java (-1 / +1 lines)
Lines 112-118 Link Here
112
	/**
112
	/**
113
	 * Sets the qualifier of this qualified name to the given name.
113
	 * Sets the qualifier of this qualified name to the given name.
114
	 * 
114
	 * 
115
	 * @param the qualifier of this qualified name
115
	 * @param qualifier the qualifier of this qualified name
116
	 * @exception IllegalArgumentException if:
116
	 * @exception IllegalArgumentException if:
117
	 * <ul>
117
	 * <ul>
118
	 * <li>the node belongs to a different AST</li>
118
	 * <li>the node belongs to a different AST</li>
(-)model/org/eclipse/jdt/internal/core/util/PublicScanner.java (-2 / +7 lines)
Lines 431-436 Link Here
431
 * e.g.	getLineStart(1) --> 0	indicates that the first line starts at character 0.
431
 * e.g.	getLineStart(1) --> 0	indicates that the first line starts at character 0.
432
 *
432
 *
433
 * In case the given line number is inconsistent, answers -1.
433
 * In case the given line number is inconsistent, answers -1.
434
 * 
435
 * @param lineNumber
436
 * @return int
434
 */
437
 */
435
public final int getLineStart(int lineNumber) {
438
public final int getLineStart(int lineNumber) {
436
439
Lines 2228-2235 Link Here
2228
 * Reposition the scanner on some portion of the original source. The given endPosition is the last valid position.
2231
 * Reposition the scanner on some portion of the original source. The given endPosition is the last valid position.
2229
 * Beyond this position, the scanner will answer EOF tokens (<code>ITerminalSymbols.TokenNameEOF</code>).
2232
 * Beyond this position, the scanner will answer EOF tokens (<code>ITerminalSymbols.TokenNameEOF</code>).
2230
 * 
2233
 * 
2231
 * @param startPosition the given start position
2234
 * @param begin the given start position
2232
 * @param endPosition the given end position
2235
 * @param end the given end position
2233
 */
2236
 */
2234
public void resetTo(int begin, int end) {
2237
public void resetTo(int begin, int end) {
2235
	//reset the scanner to a given position where it may rescan again
2238
	//reset the scanner to a given position where it may rescan again
Lines 3036-3041 Link Here
3036
/**
3039
/**
3037
 * Search the line number corresponding to a specific position
3040
 * Search the line number corresponding to a specific position
3038
 *
3041
 *
3042
 * @param position
3043
 * @return int
3039
 */
3044
 */
3040
public final int getLineNumber(int position) {
3045
public final int getLineNumber(int position) {
3041
3046
(-)dom/org/eclipse/jdt/core/dom/Comment.java (+211 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
import java.util.Iterator;
14
import java.util.List;
15
16
/**
17
 * AST node for a comment.
18
 * This is a concrete class which represents line comments: <code>// comment</code>
19
 * and block comments <code>/* comment \*\/</code>.
20
 * 
21
 * Javadoc comment are still representated with Javadoc class which is now a sub-class
22
 * of this class.
23
 * @see Javadoc
24
 * 
25
 * @since 3.0
26
 */
27
public class Comment extends ASTNode {
28
29
	/**
30
	 * The comment text, including opening and closing comment 
31
	 * delimiters; defaults to an empty, but legal, line comment.
32
	 */
33
	String text = "//";//$NON-NLS-1$
34
35
	/**
36
	 * Indicates whether the comment is a block or a line comment;
37
	 * defaults to an unspecified, but legal, comment.
38
	 * Note that Javadoc comment are considered as block comments
39
	 * @see Javadoc
40
	 */
41
	boolean block = false;
42
	
43
	/**
44
	 * The tags included in the comment (element type: <code>JavadocTag</code>).
45
	 * Defaults to none.
46
	 */
47
	ASTNode.NodeList tags = new ASTNode.NodeList(true, JavadocTag.class);
48
49
	/**
50
	 * Creates a new AST node for a Javadoc comment owned by the given AST.
51
	 * The new node has an unspecified, but legal, Javadoc comment.
52
	 * <p>
53
	 * N.B. This constructor is package-private; all subclasses must be 
54
	 * declared in the same package; clients are unable to declare 
55
	 * additional subclasses.
56
	 * </p>
57
	 * 
58
	 * @param ast the AST that is to own this node
59
	 */
60
	Comment(AST ast) {
61
		super(ast);
62
	}
63
	
64
	/* (omit javadoc for this method)
65
	 * Method declared on ASTNode.
66
	 */
67
	public int getNodeType() {
68
		return COMMENT;
69
	}
70
71
	/* (omit javadoc for this method)
72
	 * Method declared on ASTNode.
73
	 */
74
	ASTNode clone(AST target) {
75
		Comment result = new Comment(target);
76
		result.setSourceRange(this.getStartPosition(), this.getLength());
77
		result.setText(this.text);
78
		result.setBlock(this.block);
79
		return result;
80
	}
81
	
82
	/* (omit javadoc for this method)
83
	 * Method declared on ASTNode.
84
	 */
85
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
86
		// dispatch to correct overloaded match method
87
		return matcher.match(this, other);
88
	}
89
90
	/* (omit javadoc for this method)
91
	 * Method declared on ASTNode.
92
	 */
93
	void accept0(ASTVisitor visitor) {
94
		visitor.visit(this);
95
		visitor.endVisit(this);
96
	}
97
98
	/**
99
	 * Returns the Javadoc comment string, including the starting
100
	 * and ending comment delimiters, and any embedded line breaks.
101
	 * 
102
	 * @return the javadoc comment string
103
	 */
104
	public String getText() {
105
		return this.text;
106
	}
107
108
	/**
109
	 * Sets or clears the Javadoc comment string. The documentation
110
	 * string must include the starting and ending comment delimiters,
111
	 * and any embedded line breaks.
112
	 * 
113
	 * @param textComment the javadoc comment string
114
	 * @exception IllegalArgumentException if the Java comment string is invalid
115
	 */
116
	public void setText(String textComment) {
117
		if (textComment == null) {
118
			throw new IllegalArgumentException();
119
		}
120
		modifying();
121
		this.text = textComment;
122
	}
123
124
	/**
125
	 * Sets or clears the Javadoc comment string. The documentation
126
	 * string must include the starting and ending comment delimiters,
127
	 * and any embedded line breaks.
128
	 * 
129
	 * @param comment the javadoc comment string
130
	 * @exception IllegalArgumentException if the Java comment string is invalid
131
	 */
132
	public void setComment(String comment) {
133
		setText(comment);
134
		//this.block = (comment.indexOf('\r') >= 0 || comment.indexOf('\n') >= 0);
135
		if (this.block) {
136
			DOMCommentParser parser = new DOMCommentParser(this.getAST());
137
			if (parser.parse(this)) {
138
				if ((getStartPosition() > 0) && (this.tags != null)) {
139
					for(Iterator it = this.tags.iterator(); it.hasNext(); ) {
140
						JavadocTag tag = (JavadocTag) it.next();
141
						tag.setSourceRange(tag.getStartPosition()+getStartPosition(), tag.getLength());
142
					}
143
				}
144
			} else {
145
				throw new IllegalArgumentException();
146
			}
147
		}
148
	}
149
	
150
	/* (omit javadoc for this method)
151
	 * Method declared on ASTNode.
152
	 */
153
	int memSize() {
154
		int size = BASE_NODE_SIZE;
155
		if (this.text != null) {
156
			// Strings usually have 4 instance fields, one of which is a char[]
157
			size += HEADERS + 4 * 4;
158
			// char[] has 2 bytes per character
159
			size += HEADERS + 2 * this.text.length();
160
		}
161
		size += 4; // size for block
162
		size += 4; // size for tags
163
		return size;
164
	}
165
	
166
	/* (omit javadoc for this method)
167
	 * Method declared on ASTNode.
168
	 */
169
	int treeSize() {
170
		return memSize() + tags.listSize();
171
	}
172
173
	/**
174
	 * @return Returns the tagDeclarations.
175
	 */
176
	public List tags() {
177
		return tags;
178
	}
179
180
	/**
181
	 * @return Returns the isBlock.
182
	 */
183
	public boolean isBlock() {
184
		return block;
185
	}
186
187
	/**
188
	 * @param isBlock The isBlock to set.
189
	 */
190
	public void setBlock(boolean isBlock) {
191
		modifying();
192
		this.block = isBlock;
193
	}
194
195
	/**
196
	 * Returns whether the comment is a javadoc comment or not.
197
	 * @return true if the comment is a Javadoc one, false otherwise.
198
	 */
199
	public boolean isJavadoc() {
200
		return false;
201
	}
202
	
203
	/**
204
	 * Returns whether the comment has tags or not.
205
	 * @return true if some tags are written in the comment, false otherwise.
206
	 */
207
	public boolean hasTags() {
208
		return (this.tags != null) && (this.tags.size() > 0);
209
	}
210
}
211
(-)dom/org/eclipse/jdt/core/dom/DOMCommentParser.java (+928 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
import java.util.ArrayList;
14
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.InvalidInputException;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
19
20
/**
21
 * Parser specialized for decoding comments.
22
 */
23
public class DOMCommentParser {
24
25
	// recognized tags
26
	public static final char[] TAG_DEPRECATED = "deprecated".toCharArray(); //$NON-NLS-1$
27
	public static final char[] TAG_PARAM = "param".toCharArray(); //$NON-NLS-1$
28
	public static final char[] TAG_RETURN = "return".toCharArray(); //$NON-NLS-1$
29
	public static final char[] TAG_THROWS = "throws".toCharArray(); //$NON-NLS-1$
30
	public static final char[] TAG_EXCEPTION = "exception".toCharArray(); //$NON-NLS-1$
31
	public static final char[] TAG_SEE = "see".toCharArray(); //$NON-NLS-1$
32
	public static final char[] EMBEDDED_TAG_INHERIT_DOC = "inheritdDoc".toCharArray(); //$NON-NLS-1$
33
	public static final char[] EMBEDDED_TAG_LINK = "link".toCharArray(); //$NON-NLS-1$
34
	public static final char[] EMBEDDED_TAG_LINKPLAIN = "linkplain".toCharArray(); //$NON-NLS-1$
35
	
36
	// tags expected positions
37
	public final static int ORDERED_TAGS_NUMBER = 3;
38
	public final static int PARAM_TAG_EXPECTED_ORDER = 0;
39
	public final static int THROWS_TAG_EXPECTED_ORDER = 1;
40
	public final static int SEE_TAG_EXPECTED_ORDER = 2;
41
	
42
	// Public fields
43
	private Comment comment;
44
	private DOMScanner scanner;
45
	private AST ast;
46
	
47
	// Private fields
48
	private int currentTokenType = -1;
49
	private int index, linePtr;
50
	private char[] source;
51
	
52
	// Identifier stack
53
	protected int identifierPtr;
54
	protected String[] identifierStack;
55
	protected int identifierLengthPtr;
56
	protected int[] identifierLengthStack;
57
	protected long[] identifierPositionStack;
58
	// Ast stack
59
	protected static int AstStackIncrement = 10;
60
	protected int astPtr;
61
	protected ASTNode[] astStack;
62
	//protected int astLengthPtr;
63
	//protected int[] astLengthStack;
64
65
	DOMCommentParser(AST ast) {
66
		this.ast = ast;
67
		this.scanner = new DOMScanner(true, true, false, ClassFileConstants.JDK1_3, null, null);
68
		this.scanner.recordLineSeparator = true;
69
		this.identifierStack = new String[10];
70
		this.identifierPositionStack = new long[10];
71
		this.identifierLengthStack = new int[20];
72
		this.astStack = new ASTNode[20];
73
		//this.astLengthStack = new int[30];
74
	}
75
76
	/* (non-Javadoc)
77
	 * Returns true if tag @deprecated is present in annotation.
78
	 * 
79
	 * If annotation checking is enabled, will also construct an Annotation node, which will be stored into Parser.annotation
80
	 * slot for being consumed later on.
81
	 */
82
	public boolean parse(Comment astComment) {
83
84
		// Init
85
		this.scanner.setSource(astComment.getText().toCharArray());
86
		reset();
87
		boolean valid = false;
88
		this.comment = astComment;
89
		Javadoc javadoc = astComment.isJavadoc() ? (Javadoc) astComment : null;
90
		
91
		// Parse
92
		try {
93
			// Verify first characters
94
			if (readChar() != '/' || readChar() != '*') {
95
				return false;
96
			}
97
			
98
			// Go to first non blank char
99
			if (this.source[this.index] == '*') {
100
				readChar();
101
				if (!astComment.isJavadoc()) {
102
					return readChar() == '/' && this.index == this.scanner.eofPosition;
103
				}
104
			}
105
			this.scanner.restartFrom(this.index);
106
			skipWhiteChars(true);
107
			int tagStart = this.index;
108
109
			// We got some text before first tag declaration
110
			if (this.source[this.index] != '@') {
111
				// read sentences before first tag
112
				int textStart = this.index;
113
				this.linePtr = this.scanner.linePtr;
114
				boolean endComment = false;
115
				while (!endComment && (this.source[this.index] != '@') && (this.index < this.scanner.eofPosition)) {
116
					endComment = readLine(true);	// skip '*' after line
117
				}
118
				
119
				// Store first sentence in javadoc
120
				if (javadoc != null) {
121
					// description
122
					int textEnd = this.scanner.getCurrentTokenEndPosition();
123
					if (this.scanner.linePtr > this.linePtr) {
124
						textEnd = this.scanner.getLineEnd(this.scanner.linePtr+1);
125
					}
126
					JavadocTag firstSentence = javadoc.getFirstSentence(true/*instanciate if null*/);
127
					firstSentence.setSourceRange(textStart, textEnd-textStart+1);
128
					firstSentence.setDescription(new String(this.source, textStart, textEnd-textStart+1));
129
				
130
					// embedded tags
131
					if (this.scanner.embeddedPtr >= 0) {
132
						for (int i=0; i<=this.scanner.embeddedPtr; i++) {
133
							JavadocEmbeddedTag embeddedTag = parseEmbeddedTag(this.scanner.embeddedTagStarts[i], this.scanner.embeddedTagStops[i]);
134
							firstSentence.embedded().add(embeddedTag);
135
						}
136
					}
137
				}
138
				
139
				// verify end of comment
140
				if (this.index >= this.scanner.eofPosition) {
141
					return endComment;
142
				}
143
				if (endComment) {
144
					skipWhiteChars(false);
145
					return this.index == this.scanner.eofPosition;
146
				}
147
			}
148
			
149
			// Loop on each @tag
150
			this.linePtr = this.scanner.linePtr;
151
			loopTag: while (this.index < this.scanner.eofPosition) {
152
153
				// We should be at the beginning of a tag declaration...
154
				skipWhiteChars(false);
155
				if (this.source[this.index] != '@') {
156
					break;
157
				}
158
				tagStart = this.index;
159
				readChar();
160
				this.scanner.restartFrom(this.index);
161
162
				// Consume tag declaration
163
				int tk = readTokenAndConsume();	// tag name
164
				JavadocTag javadocTag = null;
165
				switch (tk) {
166
					case TerminalTokens.TokenNameIdentifier :
167
						char[] tag = this.scanner.getCurrentIdentifierSource();
168
						skipWhiteChars(false);
169
						if (CharOperation.equals(tag, TAG_PARAM)) {
170
							javadocTag = parseParam();
171
						} else if (CharOperation.equals(tag, TAG_EXCEPTION)) {
172
							javadocTag = parseThrows();
173
						} else if (CharOperation.equals(tag, TAG_SEE)) {
174
							javadocTag = parseSee();
175
						} else {
176
							javadocTag = parseTag(new String(tag));
177
						}
178
						break;
179
					case TerminalTokens.TokenNamereturn :
180
						javadocTag = parseTag(new String(TAG_RETURN));
181
						break;
182
					case TerminalTokens.TokenNamethrows :
183
						javadocTag = parseThrows();
184
						break;
185
				}
186
				if (javadocTag == null) {
187
					break;
188
				}
189
				
190
				// Consume tag description
191
				int textStart = this.index;
192
				if (this.currentTokenType == -1) {
193
					skipWhiteChars(false);
194
					textStart = this.index; // store start again as it might be changed
195
				} else {
196
					if (this.currentTokenType != TerminalTokens.TokenNameWHITESPACE) {
197
						textStart = this.scanner.getCurrentTokenStartPosition(); // one token was already read, start is at the beginning of this token
198
					}
199
					consumeToken();
200
				}
201
202
				// If new line was encountered while parsing tag declaration then do not read the first line
203
				// (if this happens, this means that first line of description was empty and we're already on the second one)
204
				boolean firstLineEmpty = this.scanner.linePtr > this.linePtr;
205
206
				// Loop on lines for tag description
207
				loopText: while (this.index < this.scanner.eofPosition) {
208
					this.linePtr = this.scanner.linePtr;
209
					if (!firstLineEmpty) {
210
						// stop right now if end of the comment is encountered
211
						if (readLine(false/*keep '*' after line*/)) {
212
							setJavadocTagText(javadocTag, tagStart, textStart);
213
							skipWhiteChars(false);
214
							valid = this.index == this.scanner.eofPosition;
215
							break loopTag;
216
						}
217
218
						// add embedded tags if necessary
219
						if (this.scanner.embeddedPtr >= 0) {
220
							for (int i=0; i<=this.scanner.embeddedPtr; i++) {
221
								JavadocEmbeddedTag embeddedTag = parseEmbeddedTag(this.scanner.embeddedTagStarts[i], this.scanner.embeddedTagStops[i]);
222
								javadocTag.embedded().add(embeddedTag);
223
							}
224
						}
225
						
226
					}
227
					
228
					// after reading a line, we should have a new line starting with a '*' or a new tag
229
					// (since JDK 1.4 '*' is not mandatory at the beginning of the line...)
230
					switch (this.source[this.index]) {
231
						case '*' :
232
							readChar();
233
							if (this.source[this.index] == '/') {
234
								// sounds like end of comment, prepare to leave
235
								readChar();
236
								skipWhiteChars(false);
237
								valid = this.index == this.scanner.eofPosition;
238
							} else {
239
								skipWhiteChars(false);
240
								if (this.source[this.index] != '@') {
241
									// we're not on a new tag declaration, then read following line of description
242
									break;
243
								}
244
							}
245
							// fall through following case as we got a new tag or end of comment
246
						case '@':
247
							if (firstLineEmpty && (javadocTag.getReference() != null)) { // we're on an empty first line, end of text is on previous line...
248
								int textEnd = javadocTag.getReference().getEndPosition();
249
								javadocTag.setSourceRange(tagStart, textEnd-tagStart+1);
250
								//javadocTag.setDescription(new String(this.source, textStart, textEnd-textStart+1));
251
								this.linePtr = this.scanner.linePtr;
252
								//this.linesPtr = -1;
253
							} else {
254
								setJavadocTagText(javadocTag, tagStart, textStart);
255
							}
256
							this.comment.tags().add(javadocTag);
257
							break loopText;
258
						default :
259
							break loopTag;
260
					}
261
					firstLineEmpty = false; // we only want to skip first line read
262
				}
263
			}
264
		} catch (Exception e) {
265
			valid = false;
266
		} finally {
267
			this.source = null; // release source as soon as finished
268
		}
269
		return valid;
270
	}
271
272
	private void consumeToken() {
273
		this.currentTokenType = -1; // flush token cache
274
	}
275
	
276
	private SimpleType getEnclosingType() {
277
		ASTNode parent = this.comment.getParent();
278
		while (parent != null) {
279
			if (parent instanceof SimpleType) {
280
				return (SimpleType) parent;
281
			}
282
			parent = parent.getParent();
283
		}
284
		return null;
285
	}
286
287
	/*
288
	 * Parse argument in @see tag method reference
289
	 */
290
	private Expression parseArguments(SimpleType receiver) throws InvalidInputException {
291
292
		// Init
293
		int modulo = 0; // should be 2 for (Type,Type,...) or 3 for (Type arg,Type arg,...)
294
		int iToken = 0;
295
		String argName = null;
296
		int ptr = this.astPtr;
297
		//int lptr = this.astLengthPtr;
298
		int start = this.scanner.getCurrentTokenStartPosition();
299
		
300
		// Decide whether we have a constructor or not
301
		SimpleName simpleName = null;
302
		Name receiverName = receiver.getName();
303
		if (receiverName.isQualifiedName()) {
304
			simpleName = ((QualifiedName) receiverName).getName();
305
		} else {
306
			simpleName = (SimpleName) receiverName;
307
		}
308
		boolean isConstructor = simpleName.getIdentifier().equals(this.identifierStack[0]);
309
310
		// Parse arguments declaration if method reference
311
		nextArg : while (this.index < this.scanner.eofPosition) {
312
313
			// Read argument type reference
314
			Type type;
315
			try {
316
				type = parseQualifiedName(false);
317
			} catch (InvalidInputException e) {
318
				break nextArg;
319
			}
320
			boolean firstArg = modulo == 0;
321
			if (firstArg) { // verify position
322
				if (iToken != 0)
323
					break nextArg;
324
			} else if ((iToken % modulo) != 0) {
325
					break nextArg;
326
			}
327
			if (type == null) {
328
				if (firstArg && this.currentTokenType == TerminalTokens.TokenNameRPAREN) {
329
					int idStart = (int) (this.identifierPositionStack[0] >>> 32);
330
					int idLength = ((int) this.identifierPositionStack[0]) - idStart + 1;
331
					if (isConstructor) {
332
						ClassInstanceCreation invocation = this.ast.newClassInstanceCreation();
333
						invocation.setSourceRange(idStart, idLength);
334
						invocation.setName(receiver.getName());
335
						return invocation;
336
					} else {
337
						SimpleName methodName = this.ast.newSimpleName(this.identifierStack[0]);
338
						methodName.setSourceRange(idStart, idLength);
339
						MethodInvocation invocation = this.ast.newMethodInvocation();
340
						invocation.setName(methodName);
341
						invocation.setSourceRange(start, this.scanner.getCurrentTokenEndPosition()-start+1);
342
						return invocation;
343
					}
344
				}
345
				break nextArg;
346
			}
347
			int argStart = type.getStartPosition();
348
			int argLength = type.getLength();
349
			iToken++;
350
351
			// Read possible array declaration
352
			if (readToken() == TerminalTokens.TokenNameLBRACKET) {
353
				while (readToken() == TerminalTokens.TokenNameLBRACKET) {
354
					consumeToken();
355
					if (readToken() != TerminalTokens.TokenNameRBRACKET) {
356
						break nextArg;
357
					}
358
					consumeToken();
359
					type = this.ast.newArrayType(type);
360
				}
361
				type.setSourceRange(argStart, this.scanner.getCurrentTokenEndPosition()-argStart+1);
362
			}
363
364
			// Read argument name
365
			if (readToken() == TerminalTokens.TokenNameIdentifier) {
366
				consumeToken();
367
				if (firstArg) { // verify position
368
					if (iToken != 1)
369
						break nextArg;
370
				} else if ((iToken % modulo) != 1) {
371
						break nextArg;
372
				}
373
				if (argName == null) { // verify that all arguments name are declared
374
					if (!firstArg) {
375
						break nextArg;
376
					}
377
				}
378
				argName = this.scanner.getCurrentIdentifierSourceAsString();
379
				argLength = this.scanner.getCurrentTokenEndPosition()-argStart+1;
380
				iToken++;
381
			} else if (argName != null) { // verify that no argument name is declared
382
				break nextArg;
383
			}
384
			
385
			// Verify token position
386
			if (firstArg) {
387
				modulo = iToken + 1;
388
			} else {
389
				if ((iToken % modulo) != (modulo - 1)) {
390
					break nextArg;
391
				}
392
			}
393
394
			// Read separator or end arguments declaration
395
			int token = readToken();
396
			String name = argName == null ? new String() : argName;
397
			if (token == TerminalTokens.TokenNameCOMMA) {
398
				// Create new argument
399
				SingleVariableDeclaration variable = this.ast.newSingleVariableDeclaration();
400
				variable.setSourceRange(argStart, argLength);
401
				variable.setName(this.ast.newSimpleName(name));
402
				variable.setType(type);
403
				JavadocArgument argument = this.ast.newJavadocArgument();
404
				argument.setSourceRange(argStart, argLength);
405
				argument.setArgument(variable);
406
				pushOnAstStack(argument);
407
				consumeToken();
408
				iToken++;
409
			} else if (token == TerminalTokens.TokenNameRPAREN) {
410
				// Create new argument
411
				SingleVariableDeclaration variable = this.ast.newSingleVariableDeclaration();
412
				variable.setSourceRange(argStart, argLength);
413
				variable.setName(this.ast.newSimpleName(name));
414
				variable.setType(type);
415
				JavadocArgument argument = this.ast.newJavadocArgument();
416
				argument.setSourceRange(argStart, argLength);
417
				argument.setArgument(variable);
418
				pushOnAstStack(argument);
419
				// Build arguments array
420
				//int size = this.astLengthStack[this.astLengthPtr--];
421
				ArrayList arguments = new ArrayList(this.astPtr);
422
				while (this.astPtr >=0) {
423
					arguments.add(this.astStack[this.astPtr--]);
424
				}
425
				// Create message send
426
				if (isConstructor) {
427
					ClassInstanceCreation invocation = this.ast.newClassInstanceCreation();
428
					invocation.setSourceRange(start, this.scanner.getCurrentTokenEndPosition()-start+1);
429
					invocation.setName(receiver.getName());
430
					invocation.arguments().addAll(arguments);
431
					return invocation;
432
				} else {
433
					int idStart = (int) (this.identifierPositionStack[0] >>> 32);
434
					int idLength = ((int) this.identifierPositionStack[0]) - idStart + 1;
435
					SimpleName methodName = this.ast.newSimpleName(this.identifierStack[0]);
436
					methodName.setSourceRange(idStart, idLength);
437
					MethodInvocation invocation = this.ast.newMethodInvocation();
438
					invocation.setSourceRange(start, this.scanner.getCurrentTokenEndPosition()-start+1);
439
					invocation.setName(methodName);
440
					invocation.arguments().addAll(arguments);
441
					return invocation;
442
				}
443
			} else {
444
				break nextArg;
445
			}
446
		}
447
448
		// Invalid input: reset ast stacks pointers
449
		consumeToken();
450
		if (iToken > 0) {
451
			this.astPtr = ptr;
452
			//this.astLengthPtr = lptr;
453
		}
454
		throw new InvalidInputException();
455
	}
456
	
457
	private JavadocEmbeddedTag parseEmbeddedTag(int start, int end) throws InvalidInputException {
458
		// Init specific scanner with text wihtout braces
459
		int sourceLength = end - (start+1);
460
		char[] tagSource = new char[sourceLength];
461
		System.arraycopy(this.source, start+1, tagSource, 0, sourceLength);
462
		DOMCommentParser parser = new DOMCommentParser(this.ast);
463
		parser.scanner.setSource(tagSource);
464
		parser.reset();
465
466
		// Read embedded tag identifier
467
		if (parser.readChar() != '@') {
468
			throw new InvalidInputException();
469
		}
470
		parser.scanner.restartFrom(parser.index);
471
		if (parser.readTokenAndConsume() != TerminalTokens.TokenNameIdentifier) {
472
			throw new InvalidInputException();
473
		}
474
		
475
		// Read embedded tag declaration
476
		JavadocTag tag = null;
477
		char[] tagName = parser.scanner.getCurrentIdentifierSource();
478
		parser.skipWhiteChars(false);
479
		if (CharOperation.equals(tagName, EMBEDDED_TAG_INHERIT_DOC)) {
480
			if (!parser.scanner.atEnd()) {
481
				throw new InvalidInputException();
482
			}
483
		}
484
		else if (CharOperation.equals(tagName, EMBEDDED_TAG_LINK) ||
485
				(CharOperation.equals(tagName, EMBEDDED_TAG_LINKPLAIN)))
486
		{
487
			tag = parser.parseSee();
488
			if (tag == null) {
489
				throw new InvalidInputException();
490
			}
491
			tag.setIdentifier(JavadocTag.NO_IDENTIFIER);
492
			if (parser.index < parser.scanner.eofPosition) {
493
				int textStart = parser.index;
494
				if (parser.currentTokenType == -1) {
495
					parser.skipWhiteChars(false);
496
					textStart = parser.index;
497
				} else {
498
					if (parser.currentTokenType != TerminalTokens.TokenNameWHITESPACE) {
499
						textStart = parser.scanner.getCurrentTokenStartPosition();
500
					}
501
				}
502
				tag.setDescription(new String(parser.source, textStart, sourceLength-textStart));
503
			}
504
		}
505
		
506
		// Build embedded tag
507
		JavadocEmbeddedTag embeddedTag = this.ast.newJavadocEmbeddedTag();
508
		embeddedTag.setSourceRange(start, end-start+1);
509
		embeddedTag.setTag(tag);
510
		embeddedTag.setIdentifier(new String(tagName));
511
		return embeddedTag;
512
	}
513
514
	/*
515
	 * Parse a method reference in @see tag
516
	 */
517
	private Expression parseMember(SimpleType receiver) throws InvalidInputException {
518
		// Init
519
		this.identifierPtr = -1;
520
		this.identifierLengthPtr = -1;
521
		
522
		// Get type ref
523
		SimpleType type = receiver;
524
		if (type == null) {
525
			type = getEnclosingType();
526
			if (type == null) {
527
				return null;
528
			}
529
		}
530
		
531
		// Get member identifier
532
		if (readTokenAndConsume() == TerminalTokens.TokenNameIdentifier) {
533
			pushIdentifier(true);
534
			if (readTokenAndConsume() == TerminalTokens.TokenNameLPAREN) {
535
				try {
536
					return parseArguments(type);
537
				} catch (InvalidInputException e) {
538
					// ignore
539
				}
540
				return null;
541
			}
542
			FieldAccess fieldAccess = this.ast.newFieldAccess();
543
			fieldAccess.setName(this.ast.newSimpleName(this.identifierStack[0]));
544
			int idStart = (int) (this.identifierPositionStack[0] >>> 32);
545
			int idLength = ((int) this.identifierPositionStack[0]) - idStart + 1;
546
			fieldAccess.setSourceRange(idStart, idLength);
547
			return fieldAccess;
548
		}
549
		return null;
550
	}
551
552
	/*
553
	 * Parse @param tag declaration
554
	 */
555
	private JavadocTag parseParam() {
556
		try {
557
			int token = readTokenAndConsume();
558
			if (token == TerminalTokens.TokenNameIdentifier) {
559
				JavadocTag tag = this.ast.newJavadocTag();
560
				tag.setIdentifier(new String(TAG_PARAM));
561
				SimpleName name = this.ast.newSimpleName(new String(this.scanner.getCurrentIdentifierSource()));
562
				VariableDeclarationFragment variable = this.ast.newVariableDeclarationFragment();
563
				variable.setSourceRange(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition()-this.scanner.getCurrentTokenStartPosition()+1);
564
				variable.setName(name);
565
				tag.setReference(variable);
566
				return tag;
567
			}
568
		} catch (InvalidInputException e) {
569
			consumeToken();
570
		}
571
		return null;
572
	}
573
574
	/*
575
	 * Parse a qualified name and built a type reference if the syntax is valid.
576
	 */
577
	private Type parseQualifiedName(boolean reset) throws InvalidInputException {
578
579
		// Reset identifier stack if requested
580
		int start = this.scanner.getCurrentTokenStartPosition();
581
		if (reset) {
582
			this.identifierPtr = -1;
583
			this.identifierLengthPtr = -1;
584
		}
585
586
		// Scan tokens
587
		int typeTokenEnd = -1;
588
		nextToken : for (int iToken = 0; ; iToken++) {
589
			int lptr = this.scanner.linePtr;
590
			int token = readToken();
591
			switch (token) {
592
				case TerminalTokens.TokenNameIdentifier :
593
					if (((iToken % 2) > 0)) { // identifiers must be odd tokens
594
						break nextToken;
595
					}
596
					pushIdentifier(iToken == 0);
597
					consumeToken();
598
					typeTokenEnd = this.scanner.getCurrentTokenEndPosition();
599
					break;
600
601
				case TerminalTokens.TokenNameDOT :
602
					if ((iToken % 2) == 0) { // dots must be even tokens
603
						throw new InvalidInputException();
604
					}
605
					consumeToken();
606
					break;
607
608
				case TerminalTokens.TokenNamevoid :
609
					if (iToken > 0) throw new InvalidInputException();
610
					PrimitiveType type = this.ast.newPrimitiveType(PrimitiveType.VOID);
611
					consumeToken();
612
					return type;
613
				case TerminalTokens.TokenNameboolean :
614
					if (iToken > 0) throw new InvalidInputException();
615
					type = this.ast.newPrimitiveType(PrimitiveType.BOOLEAN);
616
					consumeToken();
617
					return type;
618
				case TerminalTokens.TokenNamebyte :
619
					if (iToken > 0) throw new InvalidInputException();
620
					type = this.ast.newPrimitiveType(PrimitiveType.BYTE);
621
					consumeToken();
622
					return type;
623
				case TerminalTokens.TokenNamechar :
624
					if (iToken > 0) throw new InvalidInputException();
625
					type = this.ast.newPrimitiveType(PrimitiveType.CHAR);
626
					consumeToken();
627
					return type;
628
				case TerminalTokens.TokenNamedouble :
629
					if (iToken > 0) throw new InvalidInputException();
630
					type = this.ast.newPrimitiveType(PrimitiveType.DOUBLE);
631
					consumeToken();
632
					return type;
633
				case TerminalTokens.TokenNamefloat :
634
					if (iToken > 0) throw new InvalidInputException();
635
					type = this.ast.newPrimitiveType(PrimitiveType.FLOAT);
636
					consumeToken();
637
					return type;
638
				case TerminalTokens.TokenNameint :
639
					if (iToken > 0) throw new InvalidInputException();
640
					type = this.ast.newPrimitiveType(PrimitiveType.INT);
641
					consumeToken();
642
					return type;
643
				case TerminalTokens.TokenNamelong :
644
					if (iToken > 0) throw new InvalidInputException();
645
					type = this.ast.newPrimitiveType(PrimitiveType.LONG);
646
					consumeToken();
647
					return type;
648
				case TerminalTokens.TokenNameshort :
649
					if (iToken > 0) throw new InvalidInputException();
650
					type = this.ast.newPrimitiveType(PrimitiveType.SHORT);
651
					consumeToken();
652
					return type;
653
654
				case TerminalTokens.TokenNameWHITESPACE:
655
					// Ignore white spaces
656
					if (this.scanner.linePtr > lptr) {
657
						// Leave if new line was encountered
658
						break nextToken;
659
					}
660
					iToken--;
661
					consumeToken();
662
					break;
663
				default :
664
					if (iToken == 0) {
665
						return null;
666
					}
667
					if ((iToken % 2) == 0) { // cannot leave on a dot
668
						throw new InvalidInputException();
669
					}
670
					break nextToken;
671
			}
672
		}
673
		
674
		// We should have stored a end position for the type
675
		if (typeTokenEnd == -1) {
676
			throw new InvalidInputException();
677
		}
678
		
679
		// Build type reference from read tokens
680
		int size = this.identifierLengthStack[this.identifierLengthPtr--];
681
		String[] identifiers = new String[size];
682
		int pos = this.identifierPtr - size + 1;
683
		System.arraycopy(this.identifierStack, pos, identifiers, 0, size);
684
		SimpleType type = this.ast.newSimpleType( this.ast.newName(identifiers));
685
		type.setSourceRange(start, typeTokenEnd-start+1);
686
		this.identifierPtr -= size;
687
		return type;
688
	}
689
690
	/*
691
	 * Parse a reference in @see tag
692
	 */
693
	private ASTNode parseReference() throws InvalidInputException {
694
		SimpleType type = null;
695
		nextToken : while (this.index < this.scanner.eofPosition) {
696
			int token = readToken();
697
			int start = this.scanner.getCurrentTokenStartPosition();
698
			switch (token) {
699
				case TerminalTokens.TokenNameStringLiteral :
700
					// @see "string"
701
					if (type == null) {
702
						consumeToken();
703
						try {
704
							if (readToken() == TerminalTokens.TokenNameEOF) {
705
								StringLiteral node = this.ast.newStringLiteral();
706
								node.setLiteralValue(this.scanner.getCurrentTokenSourceAsString());
707
								node.setSourceRange(start, this.scanner.getCurrentTokenEndPosition()-start+1);
708
							}
709
						} catch (InvalidInputException e) {// Do nothing as we want to underline from the beginning of the string
710
						}
711
					}
712
					return null;
713
				case TerminalTokens.TokenNameLESS :
714
					// @see <a href="URL#Value">label</a>
715
					consumeToken();
716
					return null;
717
				case TerminalTokens.TokenNameERROR :
718
					consumeToken();
719
					if (this.scanner.currentCharacter == '#') { // @see ...#member
720
						return parseMember(type);
721
					}
722
					break nextToken;
723
				case TerminalTokens.TokenNameIdentifier :
724
					if (type == null) {
725
						Type refType = parseQualifiedName(true);
726
						if (refType instanceof SimpleType) {
727
							type = (SimpleType) refType;
728
							break;
729
						}
730
					}
731
				default :
732
					break nextToken;
733
			}
734
		}
735
		return type;
736
	}
737
	
738
	/*
739
	 * Parse @return tag declaration
740
	 */
741
	private JavadocTag parseTag(String tagName) {
742
		JavadocTag tag = this.ast.newJavadocTag();
743
		tag.setIdentifier(tagName);
744
		return tag;
745
	}
746
747
	/*
748
	 * Parse @see tag declaration
749
	 */
750
	private JavadocTag parseSee() {
751
		int start = this.scanner.currentPosition;
752
		try {
753
			JavadocTag tag = this.ast.newJavadocTag();
754
			tag.setIdentifier(new String(TAG_SEE));
755
			ASTNode ref = parseReference();
756
			if (ref != null) {
757
				ref.setSourceRange(start, this.scanner.getCurrentTokenEndPosition()-start+1);
758
				tag.setReference(ref);
759
				return tag;
760
			}
761
		} catch (InvalidInputException ex) {
762
			// ignore
763
		}
764
		return null;
765
	}
766
767
	/*
768
	 * Parse @throws tag declaration
769
	 */
770
	private JavadocTag parseThrows() {
771
		try {
772
			JavadocTag tag = this.ast.newJavadocTag();
773
			tag.setIdentifier(new String(TAG_THROWS));
774
			Type type = parseQualifiedName(true);
775
			if (type != null && type instanceof SimpleType) {
776
				tag.setReference(type);
777
				return tag;
778
			}
779
		} catch (InvalidInputException ex) {
780
			// ignore
781
		}
782
		return null;
783
	}
784
	
785
	/*
786
	 * push the consumeToken on the identifier stack. Increase the total number of identifier in the stack.
787
	 */
788
	private void pushIdentifier(boolean newLength) {
789
790
		String identifier = new String(this.scanner.getCurrentTokenSource());
791
		try {
792
			this.identifierStack[++this.identifierPtr] = identifier;
793
			this.identifierPositionStack[this.identifierPtr] = (((long) this.scanner.startPosition) << 32)
794
					+ (this.scanner.currentPosition - 1);
795
		} catch (IndexOutOfBoundsException e) {
796
			//---stack reallaocation (identifierPtr is correct)---
797
			int oldStackLength = this.identifierStack.length;
798
			String[] oldStack = this.identifierStack;
799
			this.identifierStack = new String[oldStackLength + 10];
800
			System.arraycopy(oldStack, 0, this.identifierStack, 0, oldStackLength);
801
			this.identifierStack[this.identifierPtr] = identifier;
802
			// identifier position stack
803
			long[] oldPos = this.identifierPositionStack;
804
			this.identifierPositionStack = new long[oldStackLength + 10];
805
			System.arraycopy(oldPos, 0, this.identifierPositionStack, 0, oldStackLength);
806
			this.identifierPositionStack[this.identifierPtr] = (((long) this.scanner.startPosition) << 32)
807
					+ (this.scanner.currentPosition - 1);
808
		}
809
810
		if (newLength) {
811
			try {
812
				this.identifierLengthStack[++this.identifierLengthPtr] = 1;
813
			} catch (IndexOutOfBoundsException e) {
814
				/* ---stack reallocation (identifierLengthPtr is correct)--- */
815
				int oldStackLength = this.identifierLengthStack.length;
816
				int oldStack[] = this.identifierLengthStack;
817
				this.identifierLengthStack = new int[oldStackLength + 10];
818
				System.arraycopy(oldStack, 0, this.identifierLengthStack, 0, oldStackLength);
819
				this.identifierLengthStack[this.identifierLengthPtr] = 1;
820
			}
821
		} else {
822
			this.identifierLengthStack[this.identifierLengthPtr]++;
823
		}
824
	}
825
	
826
	/*
827
	 * Add a new obj on top of the ast stack.
828
	 * If new length is required, then add also a new length in length stack.
829
	 */
830
	private void pushOnAstStack(ASTNode node) {
831
832
		try {
833
			this.astStack[++this.astPtr] = node;
834
		} catch (IndexOutOfBoundsException e) {
835
			int oldStackLength = this.astStack.length;
836
			ASTNode[] oldStack = this.astStack;
837
			this.astStack = new ASTNode[oldStackLength + AstStackIncrement];
838
			System.arraycopy(oldStack, 0, this.astStack, 0, oldStackLength);
839
			this.astPtr = oldStackLength;
840
			this.astStack[this.astPtr] = node;
841
		}
842
	}
843
844
	/*
845
	 * Read next char using parser source. Do NOT change scanner current position.
846
	 */
847
	private char readChar() {
848
		char c = this.source[this.index++];
849
		if (c == '\\') {
850
			int c1, c2, c3, c4;
851
			this.index++;
852
			while (this.source[this.index] == 'u')
853
				this.index++;
854
			if (!(((c1 = Character.getNumericValue(this.source[this.index++])) > 15 || c1 < 0)
855
					|| ((c2 = Character.getNumericValue(this.source[this.index++])) > 15 || c2 < 0)
856
					|| ((c3 = Character.getNumericValue(this.source[this.index++])) > 15 || c3 < 0) || ((c4 = Character.getNumericValue(this.source[this.index++])) > 15 || c4 < 0))) {
857
				c = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
858
			}
859
		}
860
		return c;
861
	}
862
863
	/*
864
	 * Read until the end of the line. If previous token was not consumed,
865
	 * then push it at the beginning of the line.
866
	 */
867
	private boolean readLine(boolean skipStar) throws InvalidInputException {
868
		//String line = (this.currentTokenType == -1) ? "" : this.scanner.getCurrentTokenSourceAsString(); //$NON-NLS-1$
869
		//line += this.scanner.getLineEndAsString();
870
		boolean endComment = this.scanner.skipCommentLine();
871
		this.index = this.scanner.currentPosition;
872
		skipWhiteChars(skipStar);
873
		return endComment;
874
	}
875
	
876
	/*
877
	 * Read token only if previous was consumed
878
	 */
879
	private int readToken() throws InvalidInputException {
880
		if (this.currentTokenType < 0) {
881
			this.currentTokenType = this.scanner.getNextToken();
882
			this.index = this.scanner.currentPosition;
883
		}
884
		return this.currentTokenType;
885
	}
886
	
887
	private int readTokenAndConsume() throws InvalidInputException {
888
		int token = readToken();
889
		consumeToken();
890
		return token;
891
	}
892
	
893
	private void reset() {
894
		this.scanner.embeddedPtr = -1;
895
		this.source = this.scanner.source;
896
		this.index = 0;
897
		this.source = this.scanner.source;
898
		//this.astLengthPtr = -1;
899
		this.astPtr = -1;
900
		this.identifierPtr = -1;
901
		this.linePtr = -1;
902
		this.currentTokenType = -1;
903
	}
904
905
	private void setJavadocTagText(JavadocTag javadocTag, int tagStart, int textStart) {
906
		int textEnd = this.scanner.getCurrentTokenEndPosition();
907
		if (this.scanner.linePtr > this.linePtr) {
908
			textEnd = this.scanner.getLineEnd(this.scanner.linePtr+1);
909
		}
910
		javadocTag.setSourceRange(tagStart, textEnd-tagStart+1);
911
		javadocTag.setDescription(new String(this.source, textStart, textEnd-textStart+1));
912
		this.linePtr = this.scanner.linePtr;
913
	}
914
915
	private void skipWhiteChars(boolean skipStar) {
916
		while (this.index<this.scanner.eofPosition && ((skipStar && this.source[this.index] == '*') || Character.isWhitespace(this.source[this.index]))) {
917
			this.scanner.currentCharacter = this.source[this.index];
918
			readChar();
919
		}
920
		this.scanner.currentPosition = this.index;
921
	}
922
	
923
	public String toString() {
924
		StringBuffer buffer = new StringBuffer();
925
		buffer.append(this.comment).append("\n");	//$NON-NLS-1$
926
		return buffer.toString();
927
	}
928
}
(-)dom/org/eclipse/jdt/core/dom/DOMParser.java (+224 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
import org.eclipse.jdt.internal.compiler.CompilationResult;
14
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
15
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
16
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
17
import org.eclipse.jdt.internal.compiler.parser.Parser;
18
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
19
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
20
21
/**
22
 * Specific parser to use while parsing source to create DOM AST nodes.
23
 */
24
public class DOMParser extends Parser {
25
	
26
	// support for comments
27
	public int[] commentStops = new int[10];
28
	public int[] commentStarts = new int[10];
29
	public int commentPtr = -1; // no comment test with commentPtr value -1
30
	protected final static int CommentIncrement = 100;
31
	
32
	/**
33
	 * @param problemReporter
34
	 * @param optimizeStringLiterals
35
	 */
36
	public DOMParser(ProblemReporter problemReporter, boolean optimizeStringLiterals) {
37
		super(problemReporter, optimizeStringLiterals);
38
		this.javadocParser.checkJavadoc = true;
39
	}
40
41
	// old javadoc style check which doesn't include all leading comments into declaration
42
	// for backward compatibility with 2.1 DOM 
43
	public void checkComment() {
44
45
		if (this.currentElement != null && this.scanner.commentPtr >= 0) {
46
			flushCommentsDefinedPriorTo(endStatementPosition); // discard obsolete comments
47
		}
48
		boolean deprecated = false;
49
		boolean checkDeprecated = false;
50
		int lastCommentIndex = -1;
51
		
52
		// 
53
		
54
		//since jdk1.2 look only in the last java doc comment...
55
		nextComment : for (lastCommentIndex = scanner.commentPtr; lastCommentIndex >= 0; lastCommentIndex--){
56
			//look for @deprecated into the first javadoc comment preceeding the declaration
57
			int commentSourceStart = scanner.commentStarts[lastCommentIndex];
58
			// javadoc only (non javadoc comment have negative end positions.)
59
			if ((commentSourceStart < 0) ||
60
				(modifiersSourceStart != -1 && modifiersSourceStart < commentSourceStart) ||
61
				(this.scanner.commentStops[lastCommentIndex] < 0))
62
			{
63
				continue nextComment;
64
			}
65
			checkDeprecated = true;
66
			int commentSourceEnd = scanner.commentStops[lastCommentIndex] - 1; //stop is one over
67
			
68
			deprecated =
69
			this.javadocParser.checkDeprecation(commentSourceStart, commentSourceEnd);
70
			this.javadoc = this.javadocParser.javadoc;
71
			break nextComment;
72
		}
73
		if (deprecated) {
74
			checkAndSetModifiers(AccDeprecated);
75
		}
76
		// modify the modifier source start to point at the first comment
77
		if (lastCommentIndex >= 0 && checkDeprecated) {
78
			modifiersSourceStart = scanner.commentStarts[lastCommentIndex]; 
79
			if (modifiersSourceStart < 0) {
80
				modifiersSourceStart = -modifiersSourceStart;
81
			}
82
		}
83
84
	}
85
86
	
87
	/* (non-Javadoc)
88
	 * Save all source comments currently stored before flushing them.
89
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#flushCommentsDefinedPriorTo(int)
90
	 */
91
	public int flushCommentsDefinedPriorTo(int position) {
92
93
		int lastCommentIndex = scanner.commentPtr;
94
		if (lastCommentIndex < 0) return position; // no comment
95
	
96
		// compute the index of the first obsolete comment
97
		int index = lastCommentIndex;
98
		int validCount = 0;
99
		while (index >= 0){
100
			int commentEnd = scanner.commentStops[index];
101
			if (commentEnd < 0) commentEnd = -commentEnd; // negative end position for non-javadoc comments
102
			if (commentEnd <= position){
103
				break;
104
			}
105
			index--;
106
			validCount++;
107
		}
108
		// if the source at <position> is immediately followed by a line comment, then
109
		// flush this comment and shift <position> to the comment end.
110
		if (validCount > 0){
111
			int immediateCommentEnd = -scanner.commentStops[index+1]; //non-javadoc comment end positions are negative
112
			if (immediateCommentEnd > 0){ // only tolerating non-javadoc comments
113
				// is there any line break until the end of the immediate comment ? (thus only tolerating line comment)
114
				immediateCommentEnd--; // comment end in one char too far
115
				if (scanner.getLineNumber(position) == scanner.getLineNumber(immediateCommentEnd)){
116
					position = immediateCommentEnd;
117
					validCount--; // flush this comment
118
					index++;
119
				}
120
			}
121
		}
122
	
123
		if (index < 0) return position; // no obsolete comment
124
		pushOnCommentsStack(0, index);
125
126
		if (validCount > 0){ // move valid comment infos, overriding obsolete comment infos
127
			System.arraycopy(scanner.commentStarts, index + 1, scanner.commentStarts, 0, validCount);
128
			System.arraycopy(scanner.commentStops, index + 1, scanner.commentStops, 0, validCount);		
129
		}
130
		scanner.commentPtr = validCount - 1;
131
		return position;
132
	}
133
134
	/*
135
	 * Push all stored comments in stack.
136
	 */
137
	protected void pushOnCommentsStack(int start, int end) {
138
139
		for (int i=start; i<=end; i++) {
140
			try {
141
				this.commentPtr++;
142
				this.commentStarts[this.commentPtr] = this.scanner.commentStarts[i];
143
				this.commentStops[this.commentPtr] = this.scanner.commentStops[i];
144
			} catch (IndexOutOfBoundsException e) {
145
				// this.commentPtr is still correct 
146
				int oldStackLength = this.commentStarts.length;
147
				int oldCommentStarts[] = this.commentStarts;
148
				this.commentStarts = new int[oldStackLength + CommentIncrement];
149
				System.arraycopy(oldCommentStarts, 0, this.commentStarts, 0, oldStackLength);
150
				this.commentStarts[this.commentPtr] = this.scanner.commentStarts[i];
151
				int oldCommentStops[] = this.commentStops;
152
				this.commentStops = new int[oldStackLength + CommentIncrement];
153
				System.arraycopy(oldCommentStops, 0, this.commentStops, 0, oldStackLength);
154
				this.commentStops[this.commentPtr] = this.scanner.commentStops[i];
155
			}
156
		}
157
	}
158
	/* (non-Javadoc)
159
	 * Save all source comments currently stored before flushing them.
160
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#resetModifiers()
161
	 */
162
	protected void resetModifiers() {
163
		pushOnCommentsStack(0, this.scanner.commentPtr);
164
		super.resetModifiers();
165
	}
166
167
	/* (non-Javadoc)
168
	 * Store comments positions saved in stack in compilation unit declaration.
169
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#dietParse(org.eclipse.jdt.internal.compiler.env.ICompilationUnit, org.eclipse.jdt.internal.compiler.CompilationResult)
170
	 */
171
	public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult) {
172
		CompilationUnitDeclaration unit = super.dietParse(sourceUnit, compilationResult);
173
		unit.comments = getCommentsPositions();
174
		return unit;
175
	}
176
177
	/* (non-Javadoc)
178
	 * Insure that start position is always positive.
179
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#containsComment(int, int)
180
	 */
181
	public boolean containsComment(int sourceStart, int sourceEnd) {
182
		int iComment = this.scanner.commentPtr;
183
		for (; iComment >= 0; iComment--) {
184
			int commentStart = this.scanner.commentStarts[iComment];
185
			if (commentStart < 0) {
186
				commentStart = -commentStart;
187
			}
188
			// ignore comments before start
189
			if (commentStart < sourceStart) continue;
190
			// ignore comments after end
191
			if (commentStart > sourceEnd) continue;
192
			return true;
193
		}
194
		return false;
195
	}
196
197
	/*
198
	 * Build a n*2 matrix of comments positions.
199
	 * For each position, 0 is for start position and 1 for end position of the comment.
200
	 */
201
	public int[][] getCommentsPositions() {
202
		int[][] positions = new int[this.commentPtr+1][2];
203
		for (int i = 0, max = this.commentPtr; i <= max; i++){
204
			positions[i][0] = this.commentStarts[i];
205
			positions[i][1] = this.commentStops[i];
206
		}
207
		return positions;
208
	}
209
	
210
	/* (non-Javadoc)
211
	 * Create and store a specific DOM scanner.
212
	 * @see org.eclipse.jdt.internal.compiler.parser.Parser#initializeScanner()
213
	 */
214
	public void initializeScanner() {
215
		this.scanner = new DOMScanner(
216
				false /*comment*/, 
217
				false /*whitespace*/, 
218
				this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/, 
219
				this.options.sourceLevel /*sourceLevel*/, 
220
				this.options.taskTags/*taskTags*/,
221
				this.options.taskPriorites/*taskPriorities*/);
222
	}
223
224
}
(-)dom/org/eclipse/jdt/core/dom/DOMScanner.java (+201 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
import org.eclipse.jdt.core.compiler.InvalidInputException;
14
import org.eclipse.jdt.internal.compiler.parser.Scanner;
15
16
/**
17
 * Specialized scanner for DOM AST nodes.
18
 */
19
public class DOMScanner extends Scanner {
20
21
	// Tell whether an end of comment was reached
22
	public int embeddedPtr = -1;
23
	public int[] embeddedTagStarts = new int[10];
24
	public int[] embeddedTagStops = new int[10];
25
	
26
	public DOMScanner() {
27
		super();
28
	}
29
30
	public DOMScanner(
31
		boolean tokenizeComments,
32
		boolean tokenizeWhiteSpace,
33
		boolean checkNonExternalizedStringLiterals,
34
		long sourceLevel,
35
		char[][] taskTags,
36
		char[][] taskPriorities) {
37
		super(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, sourceLevel, taskTags, taskPriorities);
38
	}
39
	
40
	/*(non-Javadoc)
41
	 * Return the current token source as a string. Do not call getCurrentTokenSourceString()
42
	 * method of superclass in order to avoid unnecessary array copy.
43
	 * @see org.eclipse.jdt.internal.compiler.parser.Scanner#getCurrentTokenSource()
44
	 */
45
	public final String getCurrentTokenSourceAsString() {
46
		//return the token REAL source (aka unicodes are precomputed).
47
48
		if (this.withoutUnicodePtr != 0) {
49
			//0 is used as a fast test flag so the real first char is in position 1
50
			return new String(this.withoutUnicodeBuffer, 0, this.withoutUnicodePtr);
51
		} else {
52
			if (this.currentPosition < this.startPosition) {
53
				return "";	//$NON-NLS-1$
54
			}
55
			return new String(this.source, this.startPosition, this.currentPosition - this.startPosition);
56
		}
57
	}
58
	
59
	/*(non-Javadoc)
60
	 * Return the current identifier source as a string. Do not call getCurrentTokenSourceString()
61
	 * method of superclass in order to avoid unnecessary array copy.
62
	 * @see org.eclipse.jdt.internal.compiler.parser.Scanner#getCurrentIdentifierSource()
63
	 */
64
	public String getCurrentIdentifierSourceAsString() {
65
		//return the token REAL source (aka unicodes are precomputed)
66
	
67
		if (this.withoutUnicodePtr != 0) {
68
			//0 is used as a fast test flag so the real first char is in position 1
69
			return new String(this.withoutUnicodeBuffer, 1, this.withoutUnicodePtr); 
70
		} else {
71
			int length = this.currentPosition - this.startPosition;
72
			//no optimization
73
			return new String(this.source, this.startPosition, length);
74
		}
75
	}
76
77
	/*
78
	 * Return the source until the end of current line.
79
	 *
80
	public String getLineEndAsString() {
81
		this.endComment = false;
82
		int start = this.currentPosition;
83
		int end = this.currentPosition;
84
		boolean star = false;
85
		while ((this.currentCharacter != '\r') && (this.currentCharacter != '\n')) {
86
			if (star && this.currentCharacter == '/') {
87
				this.endComment = true;
88
				break;
89
			}
90
			star = this.currentCharacter == '*';
91
			end = this.currentPosition;
92
			getNextChar();
93
		}
94
		int length = end - start;
95
		if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
96
			pushLineSeparator();
97
			this.lineEnds[this.linePtr] = end - 1;
98
		}
99
		if (length > 0) {
100
			return new String(source, start, length);
101
		} else {
102
			return "";	//$NON-NLS-1$
103
		}
104
	}
105
106
	/*
107
	 * Skip a line in a comment. Returns an positions array of possible embedded tags.
108
	 * Also store whether the end of comment has been reached or not.
109
	 */
110
	public boolean skipCommentLine() throws InvalidInputException {
111
		boolean endComment = this.currentCharacter == '*';
112
		int endLine = this.currentPosition;
113
		if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
114
			endLine--;
115
		}
116
		int startEmbedded = this.currentCharacter == '{' ? this.getCurrentTokenStartPosition() : this.currentPosition;
117
		while ((this.currentPosition < this.eofPosition) && (this.currentCharacter != '\r') && (this.currentCharacter != '\n')) {
118
			if (endComment && this.currentCharacter == '/') {
119
				break;
120
			}
121
			endComment = false;
122
			if (this.currentCharacter == '{') {
123
				int endEmbedded = this.currentPosition;
124
				getNextChar();
125
				if ((this.currentPosition >= this.eofPosition) ||
126
					(this.currentCharacter == '\r') ||
127
					(this.currentCharacter == '\n')) {
128
					// End of text of new line was found before end of embedded tag => break from loop
129
					break;
130
				}
131
				if (this.currentCharacter == '@') {
132
					while ((this.currentCharacter != '}')) {
133
						if (((endComment && this.currentCharacter == '/')) ||
134
							(this.currentPosition >= this.eofPosition) ||
135
							(this.currentCharacter == '\r') ||
136
							(this.currentCharacter == '\n')) {
137
							// End of text of new line was found before end of embedded tag => the text is not valid
138
							throw new InvalidInputException();
139
						}
140
						endEmbedded = this.currentPosition;
141
						endComment = this.currentCharacter == '*';
142
						getNextChar();
143
					}
144
					recordEmbeddedTag(startEmbedded, endEmbedded);
145
				}
146
			}
147
			endComment = this.currentCharacter == '*';
148
			endLine = this.currentPosition;
149
			startEmbedded = this.currentPosition;
150
			getNextChar();
151
		}
152
		if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
153
			pushLineSeparator();
154
			this.lineEnds[this.linePtr] = endLine - 1;
155
		}
156
		return endComment;
157
	}
158
	
159
	/* (non-Javadoc)
160
	 * Set start position negative for line comments.
161
	 * @see org.eclipse.jdt.internal.compiler.parser.Scanner#recordComment(boolean)
162
	 */
163
	public void recordComment(int token) {
164
		super.recordComment(token);
165
		if (token == TokenNameCOMMENT_LINE) {
166
			// for comment line both positions are negative
167
			this.commentStarts[this.commentPtr] = -this.commentStarts[this.commentPtr];
168
		}
169
	}
170
171
	public void recordEmbeddedTag(int start, int end) {
172
173
		// a new comment is recorded
174
		try {
175
			this.embeddedTagStops[++this.embeddedPtr] = end;
176
		} catch (IndexOutOfBoundsException e) {
177
			int oldStackLength = this.embeddedTagStops.length;
178
			int[] oldStack = this.embeddedTagStops;
179
			this.embeddedTagStops = new int[oldStackLength + 10];
180
			System.arraycopy(oldStack, 0, this.embeddedTagStops, 0, oldStackLength);
181
			this.embeddedTagStops[this.embeddedPtr] = end;
182
			//grows the positions buffers too
183
			int[] old = this.embeddedTagStarts;
184
			this.embeddedTagStarts = new int[oldStackLength + 10];
185
			System.arraycopy(old, 0, this.embeddedTagStarts, 0, oldStackLength);
186
		}
187
188
		//the buffer is of a correct size here
189
		this.embeddedTagStarts[this.embeddedPtr] = start;
190
	}
191
	
192
	/*(non-Javadoc)
193
	 * Reset initial, start and current positions.
194
	 * @see org.eclipse.jdt.internal.compiler.parser.Scanner#resetTo(int, int)
195
	 */
196
	public void restartFrom(int begin) {
197
		this.initialPosition = this.startPosition = this.currentPosition = begin;
198
		this.embeddedPtr = -1;
199
	}
200
201
}
(-)dom/org/eclipse/jdt/core/dom/JavadocArgument.java (+86 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
/**
14
 */
15
public class JavadocArgument extends Expression {
16
	public SingleVariableDeclaration argument;
17
	
18
	/**
19
	 * @param ast
20
	 */
21
	public JavadocArgument(AST ast) {
22
		super(ast);
23
		}
24
	
25
	/* (non-Javadoc)
26
	 * @see org.eclipse.jdt.core.dom.ASTNode#getNodeType()
27
	 */
28
	public int getNodeType() {
29
		return JAVADOC_ARGUMENT;
30
	}
31
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.jdt.core.dom.ASTNode#subtreeMatch(org.eclipse.jdt.core.dom.ASTMatcher, java.lang.Object)
34
	 */
35
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
36
		return matcher.match(this, other);
37
	}
38
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.jdt.core.dom.ASTNode#clone(org.eclipse.jdt.core.dom.AST)
41
	 */
42
	ASTNode clone(AST target) {
43
		JavadocArgument result = new JavadocArgument(target);
44
		result.setSourceRange(this.getStartPosition(), this.getLength());
45
		result.setArgument(getArgument());
46
		return result;
47
	}
48
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.jdt.core.dom.ASTNode#accept0(org.eclipse.jdt.core.dom.ASTVisitor)
51
	 */
52
	void accept0(ASTVisitor visitor) {
53
		visitor.visit(this);
54
		visitor.endVisit(this);
55
		
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.jdt.core.dom.ASTNode#treeSize()
60
	 */
61
	int treeSize() {
62
		return this.argument==null?0:this.argument.treeSize();
63
	}
64
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.jdt.core.dom.ASTNode#memSize()
67
	 */
68
	int memSize() {
69
		return BASE_NODE_SIZE + 4;
70
	}
71
72
	/**
73
	 * @return Returns the argument.
74
	 */
75
	public SingleVariableDeclaration getArgument() {
76
		return this.argument;
77
	}
78
79
	/**
80
	 * @param argument The argument to set.
81
	 */
82
	public void setArgument(SingleVariableDeclaration argument) {
83
		this.argument = argument;
84
	}
85
86
}
(-)dom/org/eclipse/jdt/core/dom/JavadocEmbeddedTag.java (+130 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
/**
14
 */
15
public class JavadocEmbeddedTag extends ASTNode {
16
17
	/**
18
	 * An unspecified (but externally observable) legal Javadoc tag identifier.
19
	 */
20
	private static final String MISSING_IDENTIFIER = "";//$NON-NLS-1$
21
22
	/**
23
	 * The identifier; defaults to a unspecified, legal Java identifier.
24
	 */
25
	String identifier = MISSING_IDENTIFIER;
26
	
27
	/**
28
	 * An other Javadoc tag the embedded tag refers to; defaults is null
29
	 */
30
	JavadocTag tag;
31
	
32
	/**
33
	 * @param ast
34
	 */
35
	public JavadocEmbeddedTag(AST ast) {
36
		super(ast);
37
	}
38
39
	/* (omit javadoc for this method)
40
	 * Method declared on ASTNode.
41
	 */
42
	void accept0(ASTVisitor visitor) {
43
		visitor.visit(this);
44
		visitor.endVisit(this);
45
	}
46
47
	/* (omit javadoc for this method)
48
	 * Method declared on ASTNode.
49
	 */
50
	public int getNodeType() {
51
		return JAVADOC_EMBEDDED_TAG;
52
	}
53
	
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.jdt.core.dom.ASTNode#clone(org.eclipse.jdt.core.dom.AST)
56
	 */
57
	ASTNode clone(AST target) {
58
		JavadocEmbeddedTag result = new JavadocEmbeddedTag(target);
59
		result.setSourceRange(this.getStartPosition(), this.getLength());
60
		result.setIdentifier(this.identifier);
61
		result.setTag(this.tag);
62
		return result;
63
	}
64
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.jdt.core.dom.ASTNode#memSize()
67
	 */
68
	int memSize() {
69
		int size = BASE_NODE_SIZE;
70
		if (this.identifier!= null) {
71
			// Strings usually have 4 instance fields, one of which is a char[]
72
			size += HEADERS + 4 * 4;
73
			// char[] has 2 bytes per character
74
			size += HEADERS + 2 * this.identifier.length();
75
		}
76
		size += 4;	// tag
77
		return size;
78
	}
79
	
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.jdt.core.dom.ASTNode#subtreeMatch(org.eclipse.jdt.core.dom.ASTMatcher, java.lang.Object)
82
	 */
83
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
84
		return matcher.match(this, other);
85
	}
86
	
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jdt.core.dom.ASTNode#treeSize()
89
	 */
90
	int treeSize() {
91
		return memSize() + this.tag.treeSize();
92
	}
93
	
94
	/**
95
	 * @return Returns the name.
96
	 */
97
	public String getIdentifier() {
98
		return this.identifier;
99
	}
100
101
	/**
102
	 * @param id The name to set.
103
	 */
104
	public void setIdentifier(String id) {
105
		if (id == null) {
106
			throw new IllegalArgumentException();
107
		}
108
		modifying();
109
		this.identifier = id;
110
	}
111
	
112
	/**
113
	 * @return Returns the tag.
114
	 */
115
	public JavadocTag getTag() {
116
		return this.tag;
117
	}
118
119
	/**
120
	 * @param tag The tag to set.
121
	 */
122
	public void setTag(JavadocTag tag) {
123
		if (tag == null) {
124
			throw new IllegalArgumentException();
125
		}
126
		replaceChild(this.tag, tag, false);
127
		this.tag = tag;
128
	}
129
130
}
(-)dom/org/eclipse/jdt/core/dom/JavadocTag.java (+187 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 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
package org.eclipse.jdt.core.dom;
12
13
import java.util.List;
14
15
16
/**
17
 * AST node for a Javadoc tag of a comment.
18
 * 
19
 * @since 3.0
20
 */
21
public class JavadocTag extends ASTNode {
22
23
	/**
24
	 * An unspecified (but externally observable) legal Javadoc tag identifier.
25
	 */
26
	static final String NO_IDENTIFIER = "";//$NON-NLS-1$
27
28
	/**
29
	 * The identifier; defaults to a unspecified, legal Java identifier.
30
	 */
31
	String identifier = NO_IDENTIFIER;
32
33
	/**
34
	 * An other AST node the tag refers to; defaults is null
35
	 */
36
	ASTNode reference;
37
	
38
	String description = ""; //$NON-NLS-1$
39
40
	/**
41
	 * The embedded tags included in the tag description (element type: <code>JavadocTag</code>).
42
	 * Defaults to none.
43
	 */
44
	ASTNode.NodeList embedded = new ASTNode.NodeList(true, JavadocEmbeddedTag.class);
45
	
46
47
	/**
48
	 * Creates a new AST node for a Javadoc tag owned by the given Javadoc comment.
49
	 * The new node has an unspecified, but legal, Javadoc comment.
50
	 * <p>
51
	 * N.B. This constructor is package-private; all subclasses must be 
52
	 * declared in the same package; clients are unable to declare 
53
	 * additional subclasses.
54
	 * </p>
55
	 * 
56
	 * @param ast the AST that is to own this node
57
	 */
58
	JavadocTag(AST ast) {
59
		super(ast);
60
	}
61
62
	/* (omit javadoc for this method)
63
	 * Method declared on ASTNode.
64
	 */
65
	void accept0(ASTVisitor visitor) {
66
		visitor.visit(this);
67
		visitor.endVisit(this);
68
	}
69
70
	/* (omit javadoc for this method)
71
	 * Method declared on ASTNode.
72
	 */
73
	public int getNodeType() {
74
		return JAVADOC_TAG;
75
	}
76
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.jdt.core.dom.ASTNode#clone(org.eclipse.jdt.core.dom.AST)
79
	 */
80
	ASTNode clone(AST target) {
81
		JavadocTag result = new JavadocTag(target);
82
		result.setSourceRange(this.getStartPosition(), this.getLength());
83
		result.setIdentifier(this.identifier);
84
		result.setDescription(getDescription());
85
		result.setReference(getReference());
86
		return result;
87
	}
88
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.jdt.core.dom.ASTNode#memSize()
91
	 */
92
	int memSize() {
93
		int size = BASE_NODE_SIZE;
94
		if (this.identifier!= null) {
95
			// Strings usually have 4 instance fields, one of which is a char[]
96
			size += HEADERS + 4 * 4;
97
			// char[] has 2 bytes per character
98
			size += HEADERS + 2 * this.identifier.length();
99
		}
100
		size += 4;	// reference
101
		if (this.description!= null) {
102
			// Strings usually have 4 instance fields, one of which is a char[]
103
			size += HEADERS + 4 * 4;
104
			// char[] has 2 bytes per character
105
			size += HEADERS + 2 * this.description.length();
106
		}
107
		size += 4;	// embedded
108
		return size;
109
	}
110
	
111
	/* (non-Javadoc)
112
	 * @see org.eclipse.jdt.core.dom.ASTNode#subtreeMatch(org.eclipse.jdt.core.dom.ASTMatcher, java.lang.Object)
113
	 */
114
	public boolean subtreeMatch(ASTMatcher matcher, Object other) {
115
		return matcher.match(this, other);
116
	}
117
	
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.jdt.core.dom.ASTNode#treeSize()
120
	 */
121
	int treeSize() {
122
		return memSize()
123
			+ (this.reference == null ? 0 : this.reference.treeSize())
124
			+ (this.embedded == null ? 0 : this.embedded.listSize());
125
	}
126
127
	/**
128
	 * @return Returns the reference.
129
	 */
130
	public ASTNode getReference() {
131
		return this.reference;
132
	}
133
134
	/**
135
	 * @param reference The reference to set.
136
	 */
137
	public void setReference(ASTNode reference) {
138
		if (reference == null) {
139
			throw new IllegalArgumentException();
140
		}
141
		replaceChild(this.reference, reference, false);
142
		this.reference = reference;
143
	}
144
	
145
	/**
146
	 * @return Returns the name.
147
	 */
148
	public String getIdentifier() {
149
		return this.identifier;
150
	}
151
152
	/**
153
	 * @param id The name to set.
154
	 */
155
	public void setIdentifier(String id) {
156
		if (id == null) {
157
			throw new IllegalArgumentException();
158
		}
159
		modifying();
160
		this.identifier = id;
161
	}
162
163
	/**
164
	 * @return Returns the text.
165
	 */
166
	public String getDescription() {
167
		return this.description;
168
	}
169
170
	/**
171
	 * @param text The text to set.
172
	 */
173
	public void setDescription(String text) {
174
		if (text == null) {
175
			throw new IllegalArgumentException();
176
		}
177
		modifying();
178
		this.description = text;
179
	}
180
181
	/**
182
	 * @return Returns the tagDeclarations.
183
	 */
184
	public List embedded() {
185
		return this.embedded;
186
	}
187
}

Return to bug 27134