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/ASTParser.java (-18 / +47 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,
(-)dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java (-17 / +55 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 491-497 Link Here
491
		} finally {
495
		} finally {
492
			if (monitor != null) monitor.done();
496
			if (monitor != null) monitor.done();
493
			if (environment != null) {
497
			if (environment != null) {
494
				environment.monitor = null; // don't hold a reference to this external object
498
				environment.setMonitor(null); // don't hold a reference to this external object
495
			}
499
			}
496
			if (problemFactory != null) {
500
			if (problemFactory != null) {
497
				problemFactory.monitor = null; // don't hold a reference to this external object
501
				problemFactory.monitor = null; // don't hold a reference to this external object
Lines 501-506 Link Here
501
	public static CompilationUnitDeclaration resolve(
505
	public static CompilationUnitDeclaration resolve(
502
			org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit,
506
			org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit,
503
			IJavaProject javaProject,
507
			IJavaProject javaProject,
508
			String[] classpaths,
509
			String[] sourcepaths,
504
			NodeSearcher nodeSearcher,
510
			NodeSearcher nodeSearcher,
505
			Map options,
511
			Map options,
506
			WorkingCopyOwner owner,
512
			WorkingCopyOwner owner,
Lines 508-518 Link Here
508
			IProgressMonitor monitor) throws JavaModelException {
514
			IProgressMonitor monitor) throws JavaModelException {
509
515
510
		CompilationUnitDeclaration unit = null;
516
		CompilationUnitDeclaration unit = null;
511
		CancelableNameEnvironment environment = null;
517
		INameEnviromentWithProgress environment = null;
512
		CancelableProblemFactory problemFactory = null;
518
		CancelableProblemFactory problemFactory = null;
513
		CompilationUnitResolver resolver = null;
519
		CompilationUnitResolver resolver = null;
514
		try {
520
		try {
515
			environment = new CancelableNameEnvironment(((JavaProject)javaProject), owner, monitor);
521
			if (javaProject == null) {
522
				Main main = new Main(new PrintWriter(System.out), new PrintWriter(System.err), false/*systemExit*/, null/*options*/, null/*progress*/);
523
				ArrayList allClasspaths = new ArrayList();
524
				try {
525
					if (sourcepaths != null) {
526
						for (int i = 0, max = classpaths.length; i < max; i++) {
527
							main.processPathEntries(
528
									Main.DEFAULT_SIZE_CLASSPATH,
529
									allClasspaths, classpaths[i], null, true, false);
530
						}
531
					}
532
					if (classpaths != null) {
533
						for (int i = 0, max = classpaths.length; i < max; i++) {
534
							main.processPathEntries(
535
									Main.DEFAULT_SIZE_CLASSPATH,
536
									allClasspaths, classpaths[i], null, false, false);
537
						}
538
					}
539
					ArrayList pendingErrors = main.pendingErrors;
540
					if (pendingErrors != null && pendingErrors.size() != 0) {
541
						throw new IllegalStateException("invalid environment settings"); //$NON-NLS-1$
542
					}
543
				} catch (IllegalArgumentException e) {
544
					throw new IllegalStateException("invalid environment settings"); //$NON-NLS-1$
545
				}
546
				Classpath[] allEntries = new Classpath[allClasspaths.size()];
547
				allClasspaths.toArray(allEntries);
548
				environment = new NameEnviromentWithProgress(allEntries, null, monitor);
549
			} else {
550
				environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
551
			}
516
			problemFactory = new CancelableProblemFactory(monitor);
552
			problemFactory = new CancelableProblemFactory(monitor);
517
			CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
553
			CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
518
			boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
554
			boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
Lines 547-572 Link Here
547
				return unitDeclaration;
583
				return unitDeclaration;
548
			}
584
			}
549
			if (NameLookup.VERBOSE) {
585
			if (NameLookup.VERBOSE) {
550
				System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
586
				if (environment instanceof CancelableNameEnvironment) {
551
				System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
587
					CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
588
					System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
589
					System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
590
				}
552
			}
591
			}
553
			return unit;
592
			return unit;
554
		} finally {
593
		} finally {
555
			if (environment != null) {
594
			if (environment != null) {
556
				environment.monitor = null; // don't hold a reference to this external object
595
				// don't hold a reference to this external object
596
				environment.setMonitor(null);
557
			}
597
			}
558
			if (problemFactory != null) {
598
			if (problemFactory != null) {
559
				problemFactory.monitor = null; // don't hold a reference to this external object
599
				problemFactory.monitor = null; // don't hold a reference to this external object
560
			}
600
			}
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
		}
601
		}
571
	}
602
	}
572
	public static IBinding[] resolve(
603
	public static IBinding[] resolve(
Lines 680-686 Link Here
680
		}
711
		}
681
	}
712
	}
682
713
683
	private void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTRequestor astRequestor, int apiLevel, Map compilerOptions, WorkingCopyOwner owner, int flags) {
714
	private void resolve(
715
			ICompilationUnit[] compilationUnits,
716
			String[] bindingKeys,
717
			ASTRequestor astRequestor,
718
			int apiLevel,
719
			Map compilerOptions,
720
			WorkingCopyOwner owner,
721
			int flags) {
684
722
685
		// temporarily connect ourselves to the ASTResolver - must disconnect when done
723
		// temporarily connect ourselves to the ASTResolver - must disconnect when done
686
		astRequestor.compilationUnitResolver = this;
724
		astRequestor.compilationUnitResolver = this;
(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (-1 / +5 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-248 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;
(-)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 (-1 / +5 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-517 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;
517
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(
521
			return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement(
(-)dom/org/eclipse/jdt/core/dom/VariableBinding.java (-1 / +5 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-207 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;
(-)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