Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.dom; |
11 |
package org.eclipse.jdt.core.dom; |
12 |
|
12 |
|
|
|
13 |
import java.io.PrintWriter; |
13 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
14 |
import java.util.HashMap; |
15 |
import java.util.HashMap; |
15 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
Lines 32-37
Link Here
|
32 |
import org.eclipse.jdt.internal.compiler.IProblemFactory; |
33 |
import org.eclipse.jdt.internal.compiler.IProblemFactory; |
33 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
34 |
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; |
34 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
35 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
|
|
36 |
import org.eclipse.jdt.internal.compiler.batch.Main; |
37 |
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; |
35 |
import org.eclipse.jdt.internal.compiler.env.AccessRestriction; |
38 |
import org.eclipse.jdt.internal.compiler.env.AccessRestriction; |
36 |
import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
39 |
import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
37 |
import org.eclipse.jdt.internal.compiler.env.ISourceType; |
40 |
import org.eclipse.jdt.internal.compiler.env.ISourceType; |
Lines 50-55
Link Here
|
50 |
import org.eclipse.jdt.internal.core.BinaryMember; |
53 |
import org.eclipse.jdt.internal.core.BinaryMember; |
51 |
import org.eclipse.jdt.internal.core.CancelableNameEnvironment; |
54 |
import org.eclipse.jdt.internal.core.CancelableNameEnvironment; |
52 |
import org.eclipse.jdt.internal.core.CancelableProblemFactory; |
55 |
import org.eclipse.jdt.internal.core.CancelableProblemFactory; |
|
|
56 |
import org.eclipse.jdt.internal.core.INameEnviromentWithProgress; |
53 |
import org.eclipse.jdt.internal.core.JavaProject; |
57 |
import org.eclipse.jdt.internal.core.JavaProject; |
54 |
import org.eclipse.jdt.internal.core.NameLookup; |
58 |
import org.eclipse.jdt.internal.core.NameLookup; |
55 |
import org.eclipse.jdt.internal.core.SourceRefElement; |
59 |
import org.eclipse.jdt.internal.core.SourceRefElement; |
Lines 89-94
Link Here
|
89 |
boolean hasCompilationAborted; |
93 |
boolean hasCompilationAborted; |
90 |
|
94 |
|
91 |
private IProgressMonitor monitor; |
95 |
private IProgressMonitor monitor; |
|
|
96 |
|
97 |
/** |
98 |
* Set to <code>true</code> if the receiver was initialized using a java project name environment |
99 |
*/ |
100 |
boolean fromJavaProject; |
92 |
|
101 |
|
93 |
/** |
102 |
/** |
94 |
* Answer a new CompilationUnitVisitor using the given name environment and compiler options. |
103 |
* Answer a new CompilationUnitVisitor using the given name environment and compiler options. |
Lines 131-141
Link Here
|
131 |
CompilerOptions compilerOptions, |
140 |
CompilerOptions compilerOptions, |
132 |
ICompilerRequestor requestor, |
141 |
ICompilerRequestor requestor, |
133 |
IProblemFactory problemFactory, |
142 |
IProblemFactory problemFactory, |
134 |
IProgressMonitor monitor) { |
143 |
IProgressMonitor monitor, |
|
|
144 |
boolean fromJavaProject) { |
135 |
|
145 |
|
136 |
super(environment, policy, compilerOptions, requestor, problemFactory); |
146 |
super(environment, policy, compilerOptions, requestor, problemFactory); |
137 |
this.hasCompilationAborted = false; |
147 |
this.hasCompilationAborted = false; |
138 |
this.monitor =monitor; |
148 |
this.monitor =monitor; |
|
|
149 |
this.fromJavaProject = fromJavaProject; |
139 |
} |
150 |
} |
140 |
|
151 |
|
141 |
/* |
152 |
/* |
Lines 238-255
Link Here
|
238 |
BindingKeyResolver keyResolver = new BindingKeyResolver(key, this, this.lookupEnvironment); |
249 |
BindingKeyResolver keyResolver = new BindingKeyResolver(key, this, this.lookupEnvironment); |
239 |
Binding compilerBinding = keyResolver.getCompilerBinding(); |
250 |
Binding compilerBinding = keyResolver.getCompilerBinding(); |
240 |
if (compilerBinding == null) return null; |
251 |
if (compilerBinding == null) return null; |
241 |
DefaultBindingResolver resolver = new DefaultBindingResolver(this.lookupEnvironment, null/*no owner*/, this.bindingTables, false); |
252 |
DefaultBindingResolver resolver = new DefaultBindingResolver(this.lookupEnvironment, null/*no owner*/, this.bindingTables, false, this.fromJavaProject); |
242 |
return resolver.getBinding(compilerBinding); |
253 |
return resolver.getBinding(compilerBinding); |
243 |
} |
254 |
} |
244 |
|
255 |
|
245 |
public static CompilationUnit convert(CompilationUnitDeclaration compilationUnitDeclaration, char[] source, int apiLevel, Map options, boolean needToResolveBindings, WorkingCopyOwner owner, DefaultBindingResolver.BindingTables bindingTables, int flags, IProgressMonitor monitor) { |
256 |
public static CompilationUnit convert( |
|
|
257 |
CompilationUnitDeclaration compilationUnitDeclaration, |
258 |
char[] source, |
259 |
int apiLevel, |
260 |
Map options, |
261 |
boolean needToResolveBindings, |
262 |
WorkingCopyOwner owner, |
263 |
DefaultBindingResolver.BindingTables bindingTables, |
264 |
int flags, |
265 |
IProgressMonitor monitor, |
266 |
boolean fromJavaProject) { |
246 |
BindingResolver resolver = null; |
267 |
BindingResolver resolver = null; |
247 |
AST ast = AST.newAST(apiLevel); |
268 |
AST ast = AST.newAST(apiLevel); |
248 |
ast.setDefaultNodeFlag(ASTNode.ORIGINAL); |
269 |
ast.setDefaultNodeFlag(ASTNode.ORIGINAL); |
249 |
CompilationUnit compilationUnit = null; |
270 |
CompilationUnit compilationUnit = null; |
250 |
ASTConverter converter = new ASTConverter(options, needToResolveBindings, monitor); |
271 |
ASTConverter converter = new ASTConverter(options, needToResolveBindings, monitor); |
251 |
if (needToResolveBindings) { |
272 |
if (needToResolveBindings) { |
252 |
resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, owner, bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); |
273 |
resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, owner, bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, fromJavaProject); |
253 |
ast.setFlag(flags | AST.RESOLVED_BINDINGS); |
274 |
ast.setFlag(flags | AST.RESOLVED_BINDINGS); |
254 |
} else { |
275 |
} else { |
255 |
resolver = new BindingResolver(); |
276 |
resolver = new BindingResolver(); |
Lines 370-376
Link Here
|
370 |
} |
391 |
} |
371 |
|
392 |
|
372 |
// convert AST |
393 |
// convert AST |
373 |
CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel, options, false/*don't resolve binding*/, null/*no owner needed*/, null/*no binding table needed*/, flags /* flags */, monitor); |
394 |
CompilationUnit node = convert(compilationUnitDeclaration, parser.scanner.getSource(), apiLevel, options, false/*don't resolve binding*/, null/*no owner needed*/, null/*no binding table needed*/, flags /* flags */, monitor, true); |
374 |
node.setTypeRoot(compilationUnits[i]); |
395 |
node.setTypeRoot(compilationUnits[i]); |
375 |
|
396 |
|
376 |
// accept AST |
397 |
// accept AST |
Lines 479-485
Link Here
|
479 |
compilerOptions, |
500 |
compilerOptions, |
480 |
getRequestor(), |
501 |
getRequestor(), |
481 |
problemFactory, |
502 |
problemFactory, |
482 |
monitor); |
503 |
monitor, |
|
|
504 |
javaProject != null); |
483 |
resolver.resolve(compilationUnits, bindingKeys, requestor, apiLevel, options, owner, flags); |
505 |
resolver.resolve(compilationUnits, bindingKeys, requestor, apiLevel, options, owner, flags); |
484 |
if (NameLookup.VERBOSE) { |
506 |
if (NameLookup.VERBOSE) { |
485 |
System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
507 |
System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
Lines 491-497
Link Here
|
491 |
} finally { |
513 |
} finally { |
492 |
if (monitor != null) monitor.done(); |
514 |
if (monitor != null) monitor.done(); |
493 |
if (environment != null) { |
515 |
if (environment != null) { |
494 |
environment.monitor = null; // don't hold a reference to this external object |
516 |
environment.setMonitor(null); // don't hold a reference to this external object |
495 |
} |
517 |
} |
496 |
if (problemFactory != null) { |
518 |
if (problemFactory != null) { |
497 |
problemFactory.monitor = null; // don't hold a reference to this external object |
519 |
problemFactory.monitor = null; // don't hold a reference to this external object |
Lines 501-506
Link Here
|
501 |
public static CompilationUnitDeclaration resolve( |
523 |
public static CompilationUnitDeclaration resolve( |
502 |
org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, |
524 |
org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, |
503 |
IJavaProject javaProject, |
525 |
IJavaProject javaProject, |
|
|
526 |
String[] classpaths, |
527 |
String[] sourcepaths, |
504 |
NodeSearcher nodeSearcher, |
528 |
NodeSearcher nodeSearcher, |
505 |
Map options, |
529 |
Map options, |
506 |
WorkingCopyOwner owner, |
530 |
WorkingCopyOwner owner, |
Lines 508-518
Link Here
|
508 |
IProgressMonitor monitor) throws JavaModelException { |
532 |
IProgressMonitor monitor) throws JavaModelException { |
509 |
|
533 |
|
510 |
CompilationUnitDeclaration unit = null; |
534 |
CompilationUnitDeclaration unit = null; |
511 |
CancelableNameEnvironment environment = null; |
535 |
INameEnviromentWithProgress environment = null; |
512 |
CancelableProblemFactory problemFactory = null; |
536 |
CancelableProblemFactory problemFactory = null; |
513 |
CompilationUnitResolver resolver = null; |
537 |
CompilationUnitResolver resolver = null; |
514 |
try { |
538 |
try { |
515 |
environment = new CancelableNameEnvironment(((JavaProject)javaProject), owner, monitor); |
539 |
if (javaProject == null) { |
|
|
540 |
Main main = new Main(new PrintWriter(System.out), new PrintWriter(System.err), false/*systemExit*/, null/*options*/, null/*progress*/); |
541 |
ArrayList allClasspaths = new ArrayList(); |
542 |
try { |
543 |
if (sourcepaths != null) { |
544 |
for (int i = 0, max = classpaths.length; i < max; i++) { |
545 |
main.processPathEntries( |
546 |
Main.DEFAULT_SIZE_CLASSPATH, |
547 |
allClasspaths, classpaths[i], null, true, false); |
548 |
} |
549 |
} |
550 |
if (classpaths != null) { |
551 |
for (int i = 0, max = classpaths.length; i < max; i++) { |
552 |
main.processPathEntries( |
553 |
Main.DEFAULT_SIZE_CLASSPATH, |
554 |
allClasspaths, classpaths[i], null, false, false); |
555 |
} |
556 |
} |
557 |
ArrayList pendingErrors = main.pendingErrors; |
558 |
if (pendingErrors != null && pendingErrors.size() != 0) { |
559 |
throw new IllegalStateException("invalid environment settings"); //$NON-NLS-1$ |
560 |
} |
561 |
} catch (IllegalArgumentException e) { |
562 |
throw new IllegalStateException("invalid environment settings"); //$NON-NLS-1$ |
563 |
} |
564 |
Classpath[] allEntries = new Classpath[allClasspaths.size()]; |
565 |
allClasspaths.toArray(allEntries); |
566 |
environment = new NameEnviromentWithProgress(allEntries, null, monitor); |
567 |
} else { |
568 |
environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor); |
569 |
} |
516 |
problemFactory = new CancelableProblemFactory(monitor); |
570 |
problemFactory = new CancelableProblemFactory(monitor); |
517 |
CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); |
571 |
CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); |
518 |
boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0; |
572 |
boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0; |
Lines 524-530
Link Here
|
524 |
compilerOptions, |
578 |
compilerOptions, |
525 |
getRequestor(), |
579 |
getRequestor(), |
526 |
problemFactory, |
580 |
problemFactory, |
527 |
monitor); |
581 |
monitor, |
|
|
582 |
javaProject != null); |
528 |
boolean analyzeAndGenerateCode = !ignoreMethodBodies; |
583 |
boolean analyzeAndGenerateCode = !ignoreMethodBodies; |
529 |
unit = |
584 |
unit = |
530 |
resolver.resolve( |
585 |
resolver.resolve( |
Lines 546-572
Link Here
|
546 |
} |
601 |
} |
547 |
return unitDeclaration; |
602 |
return unitDeclaration; |
548 |
} |
603 |
} |
549 |
if (NameLookup.VERBOSE) { |
604 |
if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) { |
550 |
System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
605 |
CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment; |
551 |
System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
606 |
System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
|
607 |
System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
552 |
} |
608 |
} |
553 |
return unit; |
609 |
return unit; |
554 |
} finally { |
610 |
} finally { |
555 |
if (environment != null) { |
611 |
if (environment != null) { |
556 |
environment.monitor = null; // don't hold a reference to this external object |
612 |
// don't hold a reference to this external object |
|
|
613 |
environment.setMonitor(null); |
557 |
} |
614 |
} |
558 |
if (problemFactory != null) { |
615 |
if (problemFactory != null) { |
559 |
problemFactory.monitor = null; // don't hold a reference to this external object |
616 |
problemFactory.monitor = null; // don't hold a reference to this external object |
560 |
} |
617 |
} |
561 |
// first unit cleanup is done by caller, but cleanup all enqueued requested units (not processed) |
|
|
562 |
// if (resolver != null) { |
563 |
// for (int i = 1; i < resolver.totalUnits; i++) { // could be more requested units |
564 |
// CompilationUnitDeclaration parsedUnit = resolver.unitsToProcess[i]; |
565 |
// if (parsedUnit.scope != null) |
566 |
// parsedUnit.scope.faultInTypes(); // force resolution of signatures, so clients can query DOM AST |
567 |
// parsedUnit.cleanUp(); |
568 |
// } |
569 |
// } |
570 |
} |
618 |
} |
571 |
} |
619 |
} |
572 |
public static IBinding[] resolve( |
620 |
public static IBinding[] resolve( |
Lines 680-686
Link Here
|
680 |
} |
728 |
} |
681 |
} |
729 |
} |
682 |
|
730 |
|
683 |
private void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTRequestor astRequestor, int apiLevel, Map compilerOptions, WorkingCopyOwner owner, int flags) { |
731 |
private void resolve( |
|
|
732 |
ICompilationUnit[] compilationUnits, |
733 |
String[] bindingKeys, |
734 |
ASTRequestor astRequestor, |
735 |
int apiLevel, |
736 |
Map compilerOptions, |
737 |
WorkingCopyOwner owner, |
738 |
int flags) { |
684 |
|
739 |
|
685 |
// temporarily connect ourselves to the ASTResolver - must disconnect when done |
740 |
// temporarily connect ourselves to the ASTResolver - must disconnect when done |
686 |
astRequestor.compilationUnitResolver = this; |
741 |
astRequestor.compilationUnitResolver = this; |
Lines 719-725
Link Here
|
719 |
ast.setFlag(flags | AST.RESOLVED_BINDINGS); |
774 |
ast.setFlag(flags | AST.RESOLVED_BINDINGS); |
720 |
ast.setDefaultNodeFlag(ASTNode.ORIGINAL); |
775 |
ast.setDefaultNodeFlag(ASTNode.ORIGINAL); |
721 |
ASTConverter converter = new ASTConverter(compilerOptions, true/*need to resolve bindings*/, this.monitor); |
776 |
ASTConverter converter = new ASTConverter(compilerOptions, true/*need to resolve bindings*/, this.monitor); |
722 |
BindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); |
777 |
BindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, this.fromJavaProject); |
723 |
ast.setBindingResolver(resolver); |
778 |
ast.setBindingResolver(resolver); |
724 |
converter.setAST(ast); |
779 |
converter.setAST(ast); |
725 |
CompilationUnit compilationUnit = converter.convert(unit, contents); |
780 |
CompilationUnit compilationUnit = converter.convert(unit, contents); |
Lines 763-769
Link Here
|
763 |
} |
818 |
} |
764 |
|
819 |
|
765 |
// remaining binding keys |
820 |
// remaining binding keys |
766 |
DefaultBindingResolver resolver = new DefaultBindingResolver(this.lookupEnvironment, owner, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0); |
821 |
DefaultBindingResolver resolver = new DefaultBindingResolver(this.lookupEnvironment, owner, this.bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, true); |
767 |
Object[] keys = this.requestedKeys.valueTable; |
822 |
Object[] keys = this.requestedKeys.valueTable; |
768 |
for (int j = 0, keysLength = keys.length; j < keysLength; j++) { |
823 |
for (int j = 0, keysLength = keys.length; j < keysLength; j++) { |
769 |
BindingKeyResolver keyResolver = (BindingKeyResolver) keys[j]; |
824 |
BindingKeyResolver keyResolver = (BindingKeyResolver) keys[j]; |
Lines 794-800
Link Here
|
794 |
BindingKeyResolver keyResolver = (BindingKeyResolver) key; |
849 |
BindingKeyResolver keyResolver = (BindingKeyResolver) key; |
795 |
Binding compilerBinding = keyResolver.getCompilerBinding(); |
850 |
Binding compilerBinding = keyResolver.getCompilerBinding(); |
796 |
if (compilerBinding != null) { |
851 |
if (compilerBinding != null) { |
797 |
DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, false); |
852 |
DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, false, this.fromJavaProject); |
798 |
AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding(); |
853 |
AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding(); |
799 |
IBinding binding; |
854 |
IBinding binding; |
800 |
if (annotationBinding != null) { |
855 |
if (annotationBinding != null) { |