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 |
|