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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java (-2 / +2 lines)
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 126-132 Link Here
126
	}
126
	}
127
	initializeKnownFileNames(initialFileNames);
127
	initializeKnownFileNames(initialFileNames);
128
}
128
}
129
FileSystem(Classpath[] paths, String[] initialFileNames) {
129
protected FileSystem(Classpath[] paths, String[] initialFileNames) {
130
	final int length = paths.length;
130
	final int length = paths.length;
131
	int counter = 0;
131
	int counter = 0;
132
	this.classpaths = new FileSystem.Classpath[length];
132
	this.classpaths = new FileSystem.Classpath[length];
(-)dom/org/eclipse/jdt/core/dom/AST.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 267-273 Link Here
267
		ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
267
		ast.setDefaultNodeFlag(ASTNode.ORIGINAL);
268
		BindingResolver resolver = null;
268
		BindingResolver resolver = null;
269
		if (isResolved) {
269
		if (isResolved) {
270
			resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, workingCopy.owner, new DefaultBindingResolver.BindingTables(), false);
270
			resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, workingCopy.owner, new DefaultBindingResolver.BindingTables(), false, true);
271
			((DefaultBindingResolver) resolver).isRecoveringBindings = (reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0;
271
			((DefaultBindingResolver) resolver).isRecoveringBindings = (reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0;
272
			ast.setFlag(AST.RESOLVED_BINDINGS);
272
			ast.setFlag(AST.RESOLVED_BINDINGS);
273
		} else {
273
		} else {
(-)dom/org/eclipse/jdt/core/dom/ASTParser.java (-19 / +49 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
2
 * Copyright (c) 2004, 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 203-217 Link Here
203
	 * <code>null</code> if none. Defaults to none.
203
	 * <code>null</code> if none. Defaults to none.
204
     */
204
     */
205
	private String unitName = null;
205
	private String unitName = null;
206
	
207
	/**
208
	 * Classpath entries to use to resolve bindings when no java project are available.
209
	 */
210
	private String[] classpaths;
206
211
207
 	/**
212
	/**
213
	 * Sourcepath entries to use to resolve bindings when no java project are available.
214
	 */
215
	private String[] sourcepaths;
216
217
	/**
208
	 * Creates a new AST parser for the given API level.
218
	 * Creates a new AST parser for the given API level.
209
	 * <p>
219
	 * <p>
210
	 * N.B. This constructor is package-private.
220
	 * N.B. This constructor is package-private.
211
	 * </p>
221
	 * </p>
212
	 *
222
	 *
213
	 * @param level the API level; one of the LEVEL constants
223
	 * @param level the API level; one of the LEVEL constants
214
     * declared on <code>AST</code>
224
	 * declared on <code>AST</code>
215
	 */
225
	 */
216
	ASTParser(int level) {
226
	ASTParser(int level) {
217
		if ((level != AST.JLS2_INTERNAL)
227
		if ((level != AST.JLS2_INTERNAL)
Lines 219-225 Link Here
219
			throw new IllegalArgumentException();
229
			throw new IllegalArgumentException();
220
		}
230
		}
221
		this.apiLevel = level;
231
		this.apiLevel = level;
222
	   	initializeDefaults();
232
		initializeDefaults();
223
	}
233
	}
224
234
225
	/**
235
	/**
Lines 236-241 Link Here
236
		this.workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY;
246
		this.workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY;
237
		this.unitName = null;
247
		this.unitName = null;
238
		this.project = null;
248
		this.project = null;
249
		this.classpaths = null;
250
		this.sourcepaths = null;
239
		this.partial = false;
251
		this.partial = false;
240
		Map options = JavaCore.getOptions();
252
		Map options = JavaCore.getOptions();
241
		options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
253
		options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags
Lines 260-265 Link Here
260
	public void setBindingsRecovery(boolean enabled) {
272
	public void setBindingsRecovery(boolean enabled) {
261
		this.bindingsRecovery = enabled;
273
		this.bindingsRecovery = enabled;
262
	}
274
	}
275
	
276
	/**
277
	 * Set the environment that can be used when no IJavaProject are available.
278
	 * 
279
	 * <p>The user has to be sure to include all required types on the classpaths for binary types
280
	 * or on the sourcepaths for source types to resolve the given source code.</p>
281
	 * 
282
	 * @param classpathEntries the given classpath entries to be used to resolve bindings
283
	 * @param sourcepathEntries the given sourcepath entries to be used to resolve bindings
284
	 * @since 3.6
285
	 */
286
	public void setEnvironment(String[] classpathEntries, String[] sourcepathEntries) {
287
		this.classpaths = classpathEntries;
288
		this.sourcepaths = sourcepathEntries;
289
	}
263
	/**
290
	/**
264
	 * Sets the compiler options to be used when parsing.
291
	 * Sets the compiler options to be used when parsing.
265
	 * <p>
292
	 * <p>
Lines 689-709 Link Here
689
	 *  in the case of severe parsing errors
716
	 *  in the case of severe parsing errors
690
	 * @exception IllegalStateException if the settings provided
717
	 * @exception IllegalStateException if the settings provided
691
	 * are insufficient, contradictory, or otherwise unsupported
718
	 * are insufficient, contradictory, or otherwise unsupported
692
     */
719
	 */
693
	public ASTNode createAST(IProgressMonitor monitor) {
720
	public ASTNode createAST(IProgressMonitor monitor) {
694
	   ASTNode result = null;
721
		ASTNode result = null;
695
	   if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
722
		if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$
696
		try {
723
		try {
697
			if (this.rawSource == null && this.typeRoot == null) {
724
			if (this.rawSource == null && this.typeRoot == null) {
698
		   	  throw new IllegalStateException("source not specified"); //$NON-NLS-1$
725
				throw new IllegalStateException("source not specified"); //$NON-NLS-1$
699
		   }
726
			}
700
	   		result = internalCreateAST(monitor);
727
			result = internalCreateAST(monitor);
701
		} finally {
728
		} finally {
702
	   	   // re-init defaults to allow reuse (and avoid leaking)
729
			// reset to defaults to allow reuse (and avoid leaking)
703
	   	   initializeDefaults();
730
			initializeDefaults();
704
	   	   if (monitor != null) monitor.done();
731
			if (monitor != null) monitor.done();
705
		}
732
		}
706
   	   return result;
733
		return result;
707
	}
734
	}
708
735
709
	/**
736
	/**
Lines 783-789 Link Here
783
				CompilationUnitResolver.parse(compilationUnits, requestor, this.apiLevel, this.compilerOptions, flags, monitor);
810
				CompilationUnitResolver.parse(compilationUnits, requestor, this.apiLevel, this.compilerOptions, flags, monitor);
784
			}
811
			}
785
		} finally {
812
		} finally {
786
			// re-init defaults to allow reuse (and avoid leaking)
813
			// reset to defaults to allow reuse (and avoid leaking)
787
			initializeDefaults();
814
			initializeDefaults();
788
		}
815
		}
789
	}
816
	}
Lines 830-843 Link Here
830
	public IBinding[] createBindings(IJavaElement[] elements, IProgressMonitor monitor) {
857
	public IBinding[] createBindings(IJavaElement[] elements, IProgressMonitor monitor) {
831
		try {
858
		try {
832
			if (this.project == null)
859
			if (this.project == null)
833
				throw new IllegalStateException("project not specified"); //$NON-NLS-1$
860
				throw new IllegalStateException("project or classpath not specified"); //$NON-NLS-1$
834
			int flags = 0;
861
			int flags = 0;
835
			if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
862
			if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY;
836
			if (this.bindingsRecovery)  flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
863
			if (this.bindingsRecovery)  flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY;
837
			if (this.ignoreMethodBodies) flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
864
			if (this.ignoreMethodBodies) flags |= ICompilationUnit.IGNORE_METHOD_BODIES;
838
			return CompilationUnitResolver.resolve(elements, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor);
865
			return CompilationUnitResolver.resolve(elements, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor);
839
		} finally {
866
		} finally {
840
			// re-init defaults to allow reuse (and avoid leaking)
867
			// reset to defaults to allow reuse (and avoid leaking)
841
			initializeDefaults();
868
			initializeDefaults();
842
		}
869
		}
843
	}
870
	}
Lines 935-941 Link Here
935
							throw new IllegalStateException(String.valueOf(stringWriter.getBuffer()));
962
							throw new IllegalStateException(String.valueOf(stringWriter.getBuffer()));
936
						}
963
						}
937
					} else if (this.rawSource != null) {
964
					} else if (this.rawSource != null) {
938
						needToResolveBindings = this.resolveBindings && this.unitName != null && this.project != null && this.compilerOptions != null;
965
						needToResolveBindings = this.resolveBindings && this.unitName != null && (this.project != null || this.classpaths != null || this.sourcepaths != null) && this.compilerOptions != null;
939
						sourceUnit = new BasicCompilationUnit(this.rawSource, null, this.unitName == null ? "" : this.unitName, this.project); //$NON-NLS-1$
966
						sourceUnit = new BasicCompilationUnit(this.rawSource, null, this.unitName == null ? "" : this.unitName, this.project); //$NON-NLS-1$
940
					} else {
967
					} else {
941
						throw new IllegalStateException();
968
						throw new IllegalStateException();
Lines 954-959 Link Here
954
								CompilationUnitResolver.resolve(
981
								CompilationUnitResolver.resolve(
955
									sourceUnit,
982
									sourceUnit,
956
									this.project,
983
									this.project,
984
									this.classpaths,
985
									this.sourcepaths,
957
									searcher,
986
									searcher,
958
									this.compilerOptions,
987
									this.compilerOptions,
959
									this.workingCopyOwner,
988
									this.workingCopyOwner,
Lines 985-991 Link Here
985
						wcOwner,
1014
						wcOwner,
986
						needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null,
1015
						needToResolveBindings ? new DefaultBindingResolver.BindingTables() : null,
987
						flags,
1016
						flags,
988
						monitor);
1017
						monitor,
1018
						this.project != null);
989
					result.setTypeRoot(this.typeRoot);
1019
					result.setTypeRoot(this.typeRoot);
990
					return result;
1020
					return result;
991
				} finally {
1021
				} finally {
(-)dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java (-28 / +83 lines)
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) {
(-)dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java (-4 / +11 lines)
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 134-144 Link Here
134
	 * Toggle controlling whether DOM bindings should be created when missing internal compiler bindings..
134
	 * Toggle controlling whether DOM bindings should be created when missing internal compiler bindings..
135
	 */
135
	 */
136
	boolean isRecoveringBindings;
136
	boolean isRecoveringBindings;
137
137
	
138
	/**
139
	 * Set to <code>true</code> if initialized from a java project
140
	 */
141
	boolean fromJavaProject;
142
	
138
	/**
143
	/**
139
	 * Constructor for DefaultBindingResolver.
144
	 * Constructor for DefaultBindingResolver.
140
	 */
145
	 */
141
	DefaultBindingResolver(CompilationUnitScope scope, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings) {
146
	DefaultBindingResolver(CompilationUnitScope scope, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings, boolean fromJavaProject) {
142
		this.newAstToOldAst = new HashMap();
147
		this.newAstToOldAst = new HashMap();
143
		this.astNodesToBlockScope = new HashMap();
148
		this.astNodesToBlockScope = new HashMap();
144
		this.bindingsToAstNodes = new HashMap();
149
		this.bindingsToAstNodes = new HashMap();
Lines 146-154 Link Here
146
		this.scope = scope;
151
		this.scope = scope;
147
		this.workingCopyOwner = workingCopyOwner;
152
		this.workingCopyOwner = workingCopyOwner;
148
		this.isRecoveringBindings = isRecoveringBindings;
153
		this.isRecoveringBindings = isRecoveringBindings;
154
		this.fromJavaProject = fromJavaProject;
149
	}
155
	}
150
156
151
	DefaultBindingResolver(LookupEnvironment lookupEnvironment, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings) {
157
	DefaultBindingResolver(LookupEnvironment lookupEnvironment, WorkingCopyOwner workingCopyOwner, BindingTables bindingTables, boolean isRecoveringBindings, boolean fromJavaProject) {
152
		this.newAstToOldAst = new HashMap();
158
		this.newAstToOldAst = new HashMap();
153
		this.astNodesToBlockScope = new HashMap();
159
		this.astNodesToBlockScope = new HashMap();
154
		this.bindingsToAstNodes = new HashMap();
160
		this.bindingsToAstNodes = new HashMap();
Lines 156-161 Link Here
156
		this.scope = new CompilationUnitScope(new CompilationUnitDeclaration(null, null, -1), lookupEnvironment);
162
		this.scope = new CompilationUnitScope(new CompilationUnitDeclaration(null, null, -1), lookupEnvironment);
157
		this.workingCopyOwner = workingCopyOwner;
163
		this.workingCopyOwner = workingCopyOwner;
158
		this.isRecoveringBindings = isRecoveringBindings;
164
		this.isRecoveringBindings = isRecoveringBindings;
165
		this.fromJavaProject = fromJavaProject;
159
	}
166
	}
160
167
161
	/*
168
	/*
(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (-1 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 12-17 Link Here
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.JavaCore;
15
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
16
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
16
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
17
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
17
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
18
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
Lines 243-251 Link Here
243
	}
244
	}
244
245
245
	private JavaElement getUnresolvedJavaElement() {
246
	private JavaElement getUnresolvedJavaElement() {
247
		if (JavaCore.getPlugin() == null) {
248
			return null;
249
		}
246
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
250
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
247
251
248
		DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
252
		DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
253
		if (!defaultBindingResolver.fromJavaProject) return null;
249
		return Util.getUnresolvedJavaElement(
254
		return Util.getUnresolvedJavaElement(
250
				this.binding,
255
				this.binding,
251
				defaultBindingResolver.workingCopyOwner,
256
				defaultBindingResolver.workingCopyOwner,
(-)dom/org/eclipse/jdt/core/dom/NameEnviromentWithProgress.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.dom;
12
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.OperationCanceledException;
15
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
16
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
17
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
18
import org.eclipse.jdt.internal.core.INameEnviromentWithProgress;
19
import org.eclipse.jdt.internal.core.NameLookup;
20
21
/**
22
 * Batch name environment that is cancelable using a monitor.
23
 * @since 3.6
24
 */
25
class NameEnviromentWithProgress extends FileSystem implements INameEnviromentWithProgress {
26
	IProgressMonitor monitor;
27
	
28
	public NameEnviromentWithProgress(Classpath[] paths, String[] initialFileNames, IProgressMonitor monitor) {
29
		super(paths, initialFileNames);
30
		setMonitor(monitor);
31
	}
32
	private void checkCanceled() {
33
		if (this.monitor != null && this.monitor.isCanceled()) {
34
			if (NameLookup.VERBOSE)
35
				System.out.println(Thread.currentThread() + " CANCELLING LOOKUP "); //$NON-NLS-1$
36
			throw new AbortCompilation(true/*silent*/, new OperationCanceledException());
37
		}
38
	}
39
	public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
40
		checkCanceled();
41
		return super.findType(typeName, packageName);
42
	}
43
	public NameEnvironmentAnswer findType(char[][] compoundName) {
44
		checkCanceled();
45
		return super.findType(compoundName);
46
	}
47
	public boolean isPackage(char[][] compoundName, char[] packageName) {
48
		checkCanceled();
49
		return super.isPackage(compoundName, packageName);
50
	}
51
	
52
	public void setMonitor(IProgressMonitor monitor) {
53
		this.monitor = monitor;
54
	}
55
}
(-)dom/org/eclipse/jdt/core/dom/TypeBinding.java (-3 / +7 lines)
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 12-17 Link Here
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.JavaCore;
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.internal.compiler.ast.Expression;
17
import org.eclipse.jdt.internal.compiler.ast.Expression;
17
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
18
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
Lines 512-526 Link Here
512
		return getUnresolvedJavaElement(this.binding);
513
		return getUnresolvedJavaElement(this.binding);
513
	}
514
	}
514
	private JavaElement getUnresolvedJavaElement(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding ) {
515
	private JavaElement getUnresolvedJavaElement(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding ) {
516
		if (JavaCore.getPlugin() == null) {
517
			return null;
518
		}
515
		if (this.resolver instanceof DefaultBindingResolver) {
519
		if (this.resolver instanceof DefaultBindingResolver) {
516
			DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
520
			DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
521
			if (!defaultBindingResolver.fromJavaProject) return null;
517
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(
522
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(
518
					typeBinding,
523
					typeBinding,
519
					defaultBindingResolver.workingCopyOwner,
524
					defaultBindingResolver.workingCopyOwner,
520
					defaultBindingResolver.getBindingsToNodesMap());
525
					defaultBindingResolver.getBindingsToNodesMap());
521
		} else {
522
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(typeBinding, null, null);
523
		}
526
		}
527
		return null;
524
	}
528
	}
525
529
526
	/*
530
	/*
(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (-13 / +14 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 12-17 Link Here
12
package org.eclipse.jdt.core.dom;
12
package org.eclipse.jdt.core.dom;
13
13
14
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.JavaCore;
15
import org.eclipse.jdt.core.util.IModifierConstants;
16
import org.eclipse.jdt.core.util.IModifierConstants;
16
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
17
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Lines 202-221 Link Here
202
	}
203
	}
203
204
204
	private JavaElement getUnresolvedJavaElement() {
205
	private JavaElement getUnresolvedJavaElement() {
206
		if (JavaCore.getPlugin() == null) {
207
			return null;
208
		}
205
		if (isField()) {
209
		if (isField()) {
206
			if (this.resolver instanceof DefaultBindingResolver) {
210
			if (this.resolver instanceof DefaultBindingResolver) {
207
				DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
211
				DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
212
				if (!defaultBindingResolver.fromJavaProject) return null;
208
				return Util.getUnresolvedJavaElement(
213
				return Util.getUnresolvedJavaElement(
209
						(FieldBinding) this.binding,
214
						(FieldBinding) this.binding,
210
						defaultBindingResolver.workingCopyOwner,
215
						defaultBindingResolver.workingCopyOwner,
211
						defaultBindingResolver.getBindingsToNodesMap());
216
						defaultBindingResolver.getBindingsToNodesMap());
212
			} else {
213
				return Util.getUnresolvedJavaElement((FieldBinding) this.binding, null, null);
214
			}
217
			}
218
			return null;
215
		}
219
		}
216
		// local variable
220
		// local variable
217
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
221
		if (!(this.resolver instanceof DefaultBindingResolver)) return null;
218
		VariableDeclaration localVar = (VariableDeclaration) ((DefaultBindingResolver) this.resolver).bindingsToAstNodes.get(this);
222
		DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
223
		if (!defaultBindingResolver.fromJavaProject) return null;
224
		VariableDeclaration localVar = (VariableDeclaration) defaultBindingResolver.bindingsToAstNodes.get(this);
219
		if (localVar == null) return null;
225
		if (localVar == null) return null;
220
		int nameStart;
226
		int nameStart;
221
		int nameLength;
227
		int nameLength;
Lines 244-258 Link Here
244
				// Local variable is declared inside an initializer
250
				// Local variable is declared inside an initializer
245
				TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
251
				TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
246
				JavaElement typeHandle = null;
252
				JavaElement typeHandle = null;
247
				if (this.resolver instanceof DefaultBindingResolver) {
253
				typeHandle = Util.getUnresolvedJavaElement(
248
					DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
254
					typeDeclaration.binding,
249
					typeHandle = Util.getUnresolvedJavaElement(
255
					defaultBindingResolver.workingCopyOwner,
250
						typeDeclaration.binding,
256
					defaultBindingResolver.getBindingsToNodesMap());
251
						defaultBindingResolver.workingCopyOwner,
252
						defaultBindingResolver.getBindingsToNodesMap());
253
				} else {
254
					typeHandle = Util.getUnresolvedJavaElement(typeDeclaration.binding, null, null);
255
				}
256
				parent = Util.getUnresolvedJavaElement(sourceStart, sourceEnd, typeHandle);
257
				parent = Util.getUnresolvedJavaElement(sourceStart, sourceEnd, typeHandle);
257
			} else {
258
			} else {
258
				return null;
259
				return null;
(-)model/org/eclipse/jdt/internal/core/CancelableNameEnvironment.java (-4 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
2
 * Copyright (c) 2004, 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 19-30 Link Here
19
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
19
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
20
20
21
21
22
public class CancelableNameEnvironment extends SearchableEnvironment {
22
public class CancelableNameEnvironment extends SearchableEnvironment implements INameEnviromentWithProgress {
23
	public IProgressMonitor monitor;
23
	private IProgressMonitor monitor;
24
24
25
	public CancelableNameEnvironment(JavaProject project, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
25
	public CancelableNameEnvironment(JavaProject project, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
26
		super(project, owner);
26
		super(project, owner);
27
		this.monitor = monitor;
27
		setMonitor(monitor);
28
	}
28
	}
29
29
30
	private void checkCanceled() {
30
	private void checkCanceled() {
Lines 54-57 Link Here
54
		checkCanceled();
54
		checkCanceled();
55
		super.findTypes(prefix, findMembers, camelCaseMatch, searchFor, storage, progressMonitor);
55
		super.findTypes(prefix, findMembers, camelCaseMatch, searchFor, storage, progressMonitor);
56
	}
56
	}
57
	
58
	public void setMonitor(IProgressMonitor monitor) {
59
		this.monitor = monitor;
60
	}
57
}
61
}
(-)model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java (-2 / +2 lines)
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 229-235 Link Here
229
			throw new JavaModelException(e, IJavaModelStatusConstants.COMPILER_FAILURE);
229
			throw new JavaModelException(e, IJavaModelStatusConstants.COMPILER_FAILURE);
230
		} finally {
230
		} finally {
231
			if (environment != null)
231
			if (environment != null)
232
				environment.monitor = null; // don't hold a reference to this external object
232
				environment.setMonitor(null); // don't hold a reference to this external object
233
			if (problemFactory != null)
233
			if (problemFactory != null)
234
				problemFactory.monitor = null; // don't hold a reference to this external object
234
				problemFactory.monitor = null; // don't hold a reference to this external object
235
			// NB: unit.cleanUp() is done by caller
235
			// NB: unit.cleanUp() is done by caller
(-)model/org/eclipse/jdt/internal/core/INameEnviromentWithProgress.java (+8 lines)
Added Link Here
1
package org.eclipse.jdt.internal.core;
2
3
import org.eclipse.core.runtime.IProgressMonitor;
4
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
5
6
public interface INameEnviromentWithProgress extends INameEnvironment {
7
	void setMonitor(IProgressMonitor monitor);
8
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java (+2 lines)
Lines 15-20 Link Here
15
import junit.framework.Test;
15
import junit.framework.Test;
16
import junit.framework.TestSuite;
16
import junit.framework.TestSuite;
17
17
18
import org.eclipse.jdt.core.tests.dom.StandAloneASTParserTest;
18
import org.eclipse.jdt.core.tests.junit.extension.TestCase;
19
import org.eclipse.jdt.core.tests.junit.extension.TestCase;
19
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
20
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
20
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Lines 101-106 Link Here
101
102
102
	// Build final test suite
103
	// Build final test suite
103
	TestSuite all = new TestSuite(TestAll.class.getName());
104
	TestSuite all = new TestSuite(TestAll.class.getName());
105
	all.addTest(new TestSuite(StandAloneASTParserTest.class));
104
	int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
106
	int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
105
	if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) {
107
	if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) {
106
		ArrayList tests_1_3 = (ArrayList)standardTests.clone();
108
		ArrayList tests_1_3 = (ArrayList)standardTests.clone();
(-)src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java (+97 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.dom;
12
13
import java.util.List;
14
15
import org.eclipse.jdt.core.dom.AST;
16
import org.eclipse.jdt.core.dom.ASTNode;
17
import org.eclipse.jdt.core.dom.ASTParser;
18
import org.eclipse.jdt.core.dom.Block;
19
import org.eclipse.jdt.core.dom.CompilationUnit;
20
import org.eclipse.jdt.core.dom.Expression;
21
import org.eclipse.jdt.core.dom.ExpressionStatement;
22
import org.eclipse.jdt.core.dom.FieldDeclaration;
23
import org.eclipse.jdt.core.dom.IMethodBinding;
24
import org.eclipse.jdt.core.dom.ITypeBinding;
25
import org.eclipse.jdt.core.dom.IVariableBinding;
26
import org.eclipse.jdt.core.dom.MethodDeclaration;
27
import org.eclipse.jdt.core.dom.MethodInvocation;
28
import org.eclipse.jdt.core.dom.TypeDeclaration;
29
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
30
import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
31
import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
32
import org.eclipse.jdt.core.tests.util.Util;
33
34
public class StandAloneASTParserTest extends AbstractRegressionTest {
35
	public StandAloneASTParserTest(String name) {
36
		super(name);
37
	}
38
	public ASTNode runConversion(
39
			int astLevel,
40
			String source,
41
			boolean resolveBindings,
42
			boolean statementsRecovery,
43
			boolean bindingsRecovery,
44
			String unitName) {
45
46
		ASTParser parser = ASTParser.newParser(astLevel);
47
		parser.setSource(source.toCharArray());
48
		parser.setEnvironment(Util.getJavaClassLibs(), null);
49
		parser.setResolveBindings(resolveBindings);
50
		parser.setStatementsRecovery(statementsRecovery);
51
		parser.setBindingsRecovery(bindingsRecovery);
52
		parser.setCompilerOptions(getCompilerOptions());
53
		parser.setUnitName(unitName);
54
		return parser.createAST(null);
55
	}
56
	public void test1() {
57
		String contents =
58
				"package p;\n" + 
59
				"public class X {\n" + 
60
				"	public int i;\n" + 
61
				"	public static void main(String[] args) {\n" + 
62
				"		int length = args.length;\n" + 
63
				"		System.out.println(length);\n" + 
64
				"	}\n" + 
65
				"}";
66
		ASTNode node = runConversion(AST.JLS3, contents, true, true, true, "p/X.java");
67
		assertTrue("Should be a compilation unit", node instanceof CompilationUnit);
68
		CompilationUnit unit = (CompilationUnit) node;
69
		List types = unit.types();
70
		TypeDeclaration typeDeclaration  = (TypeDeclaration) types.get(0);
71
		ITypeBinding binding = typeDeclaration.resolveBinding();
72
		assertNotNull("No binding", binding);
73
		assertNull("Got a java element", binding.getJavaElement());
74
		assertEquals("Wrong name", "p.X", binding.getQualifiedName());
75
		MethodDeclaration methodDeclaration = (MethodDeclaration) typeDeclaration.bodyDeclarations().get(1);
76
		IMethodBinding methodBinding = methodDeclaration.resolveBinding();
77
		assertNotNull("No binding", methodBinding);
78
		assertNull("Got a java element", methodBinding.getJavaElement());
79
		Block body = methodDeclaration.getBody();
80
		VariableDeclarationStatement statement = (VariableDeclarationStatement) body.statements().get(0);
81
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
82
		IVariableBinding variableBinding = fragment.resolveBinding();
83
		assertNotNull("No binding", variableBinding);
84
		assertNull("Got a java element", variableBinding.getJavaElement());
85
		ExpressionStatement statement2 = (ExpressionStatement) body.statements().get(1);
86
		Expression expression = statement2.getExpression();
87
		MethodInvocation invocation = (MethodInvocation) expression;
88
		Expression expression2 = invocation.getExpression();
89
		assertNotNull("No binding", expression2.resolveTypeBinding());
90
		
91
		FieldDeclaration fieldDeclaration = (FieldDeclaration) typeDeclaration.bodyDeclarations().get(0);
92
		VariableDeclarationFragment fragment2 = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
93
		IVariableBinding variableBinding2 = fragment2.resolveBinding();
94
		assertNotNull("No binding", variableBinding2);
95
		assertNull("Got a java element", variableBinding2.getJavaElement());
96
	}
97
}

Return to bug 206391