### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java,v retrieving revision 1.54 diff -u -r1.54 FileSystem.java --- batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java 27 Aug 2009 15:27:01 -0000 1.54 +++ batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java 4 Feb 2010 22:43:07 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -126,7 +126,7 @@ } initializeKnownFileNames(initialFileNames); } -FileSystem(Classpath[] paths, String[] initialFileNames) { +protected FileSystem(Classpath[] paths, String[] initialFileNames) { final int length = paths.length; int counter = 0; this.classpaths = new FileSystem.Classpath[length]; Index: dom/org/eclipse/jdt/core/dom/ASTParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java,v retrieving revision 1.95 diff -u -r1.95 ASTParser.java --- dom/org/eclipse/jdt/core/dom/ASTParser.java 3 Dec 2009 14:29:11 -0000 1.95 +++ dom/org/eclipse/jdt/core/dom/ASTParser.java 4 Feb 2010 22:43:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -203,15 +203,25 @@ * null if none. Defaults to none. */ private String unitName = null; + + /** + * Classpath entries to use to resolve bindings when no java project are available. + */ + private String[] classpaths; - /** + /** + * Sourcepath entries to use to resolve bindings when no java project are available. + */ + private String[] sourcepaths; + + /** * Creates a new AST parser for the given API level. *

* N.B. This constructor is package-private. *

* * @param level the API level; one of the LEVEL constants - * declared on AST + * declared on AST */ ASTParser(int level) { if ((level != AST.JLS2_INTERNAL) @@ -219,7 +229,7 @@ throw new IllegalArgumentException(); } this.apiLevel = level; - initializeDefaults(); + initializeDefaults(); } /** @@ -236,6 +246,8 @@ this.workingCopyOwner = DefaultWorkingCopyOwner.PRIMARY; this.unitName = null; this.project = null; + this.classpaths = null; + this.sourcepaths = null; this.partial = false; Map options = JavaCore.getOptions(); options.remove(JavaCore.COMPILER_TASK_TAGS); // no need to parse task tags @@ -260,6 +272,21 @@ public void setBindingsRecovery(boolean enabled) { this.bindingsRecovery = enabled; } + + /** + * Set the environment that can be used when no IJavaProject are available. + * + *

The user has to be sure to include all required types on the classpaths for binary types + * or on the sourcepaths for source types to resolve the given source code.

+ * + * @param classpathEntries the given classpath entries to be used to resolve bindings + * @param sourcepathEntries the given sourcepath entries to be used to resolve bindings + * @since 3.6 + */ + public void setEnvironment(String[] classpathEntries, String[] sourcepathEntries) { + this.classpaths = classpathEntries; + this.sourcepaths = sourcepathEntries; + } /** * Sets the compiler options to be used when parsing. *

@@ -689,21 +716,21 @@ * in the case of severe parsing errors * @exception IllegalStateException if the settings provided * are insufficient, contradictory, or otherwise unsupported - */ + */ public ASTNode createAST(IProgressMonitor monitor) { - ASTNode result = null; - if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$ + ASTNode result = null; + if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$ try { if (this.rawSource == null && this.typeRoot == null) { - throw new IllegalStateException("source not specified"); //$NON-NLS-1$ - } - result = internalCreateAST(monitor); + throw new IllegalStateException("source not specified"); //$NON-NLS-1$ + } + result = internalCreateAST(monitor); } finally { - // re-init defaults to allow reuse (and avoid leaking) - initializeDefaults(); - if (monitor != null) monitor.done(); + // reset to defaults to allow reuse (and avoid leaking) + initializeDefaults(); + if (monitor != null) monitor.done(); } - return result; + return result; } /** @@ -783,7 +810,7 @@ CompilationUnitResolver.parse(compilationUnits, requestor, this.apiLevel, this.compilerOptions, flags, monitor); } } finally { - // re-init defaults to allow reuse (and avoid leaking) + // reset to defaults to allow reuse (and avoid leaking) initializeDefaults(); } } @@ -830,14 +857,14 @@ public IBinding[] createBindings(IJavaElement[] elements, IProgressMonitor monitor) { try { if (this.project == null) - throw new IllegalStateException("project not specified"); //$NON-NLS-1$ + throw new IllegalStateException("project or classpath not specified"); //$NON-NLS-1$ int flags = 0; if (this.statementsRecovery) flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY; if (this.bindingsRecovery) flags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY; if (this.ignoreMethodBodies) flags |= ICompilationUnit.IGNORE_METHOD_BODIES; return CompilationUnitResolver.resolve(elements, this.apiLevel, this.compilerOptions, this.project, this.workingCopyOwner, flags, monitor); } finally { - // re-init defaults to allow reuse (and avoid leaking) + // reset to defaults to allow reuse (and avoid leaking) initializeDefaults(); } } @@ -935,7 +962,7 @@ throw new IllegalStateException(String.valueOf(stringWriter.getBuffer())); } } else if (this.rawSource != null) { - needToResolveBindings = this.resolveBindings && this.unitName != null && this.project != null && this.compilerOptions != null; + needToResolveBindings = this.resolveBindings && this.unitName != null && (this.project != null || this.classpaths != null || this.sourcepaths != null) && this.compilerOptions != null; sourceUnit = new BasicCompilationUnit(this.rawSource, null, this.unitName == null ? "" : this.unitName, this.project); //$NON-NLS-1$ } else { throw new IllegalStateException(); @@ -954,6 +981,8 @@ CompilationUnitResolver.resolve( sourceUnit, this.project, + this.classpaths, + this.sourcepaths, searcher, this.compilerOptions, this.workingCopyOwner, Index: dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java,v retrieving revision 1.139 diff -u -r1.139 CompilationUnitResolver.java --- dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 27 Nov 2009 17:51:16 -0000 1.139 +++ dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java 4 Feb 2010 22:43:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.core.dom; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -32,6 +33,8 @@ import org.eclipse.jdt.internal.compiler.IProblemFactory; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.Main; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; import org.eclipse.jdt.internal.compiler.env.AccessRestriction; import org.eclipse.jdt.internal.compiler.env.INameEnvironment; import org.eclipse.jdt.internal.compiler.env.ISourceType; @@ -50,6 +53,7 @@ import org.eclipse.jdt.internal.core.BinaryMember; import org.eclipse.jdt.internal.core.CancelableNameEnvironment; import org.eclipse.jdt.internal.core.CancelableProblemFactory; +import org.eclipse.jdt.internal.core.INameEnviromentWithProgress; import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.NameLookup; import org.eclipse.jdt.internal.core.SourceRefElement; @@ -491,7 +495,7 @@ } finally { if (monitor != null) monitor.done(); if (environment != null) { - environment.monitor = null; // don't hold a reference to this external object + environment.setMonitor(null); // don't hold a reference to this external object } if (problemFactory != null) { problemFactory.monitor = null; // don't hold a reference to this external object @@ -501,6 +505,8 @@ public static CompilationUnitDeclaration resolve( org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject, + String[] classpaths, + String[] sourcepaths, NodeSearcher nodeSearcher, Map options, WorkingCopyOwner owner, @@ -508,11 +514,41 @@ IProgressMonitor monitor) throws JavaModelException { CompilationUnitDeclaration unit = null; - CancelableNameEnvironment environment = null; + INameEnviromentWithProgress environment = null; CancelableProblemFactory problemFactory = null; CompilationUnitResolver resolver = null; try { - environment = new CancelableNameEnvironment(((JavaProject)javaProject), owner, monitor); + if (javaProject == null) { + Main main = new Main(new PrintWriter(System.out), new PrintWriter(System.err), false/*systemExit*/, null/*options*/, null/*progress*/); + ArrayList allClasspaths = new ArrayList(); + try { + if (sourcepaths != null) { + for (int i = 0, max = classpaths.length; i < max; i++) { + main.processPathEntries( + Main.DEFAULT_SIZE_CLASSPATH, + allClasspaths, classpaths[i], null, true, false); + } + } + if (classpaths != null) { + for (int i = 0, max = classpaths.length; i < max; i++) { + main.processPathEntries( + Main.DEFAULT_SIZE_CLASSPATH, + allClasspaths, classpaths[i], null, false, false); + } + } + ArrayList pendingErrors = main.pendingErrors; + if (pendingErrors != null && pendingErrors.size() != 0) { + throw new IllegalStateException("invalid environment settings"); //$NON-NLS-1$ + } + } catch (IllegalArgumentException e) { + throw new IllegalStateException("invalid environment settings"); //$NON-NLS-1$ + } + Classpath[] allEntries = new Classpath[allClasspaths.size()]; + allClasspaths.toArray(allEntries); + environment = new NameEnviromentWithProgress(allEntries, null, monitor); + } else { + environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor); + } problemFactory = new CancelableProblemFactory(monitor); CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0; @@ -547,26 +583,21 @@ return unitDeclaration; } if (NameLookup.VERBOSE) { - System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ + if (environment instanceof CancelableNameEnvironment) { + CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment; + System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ + System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ + } } return unit; } finally { if (environment != null) { - environment.monitor = null; // don't hold a reference to this external object + // don't hold a reference to this external object + environment.setMonitor(null); } if (problemFactory != null) { problemFactory.monitor = null; // don't hold a reference to this external object } - // first unit cleanup is done by caller, but cleanup all enqueued requested units (not processed) -// if (resolver != null) { -// for (int i = 1; i < resolver.totalUnits; i++) { // could be more requested units -// CompilationUnitDeclaration parsedUnit = resolver.unitsToProcess[i]; -// if (parsedUnit.scope != null) -// parsedUnit.scope.faultInTypes(); // force resolution of signatures, so clients can query DOM AST -// parsedUnit.cleanUp(); -// } -// } } } public static IBinding[] resolve( @@ -680,7 +711,14 @@ } } - private void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTRequestor astRequestor, int apiLevel, Map compilerOptions, WorkingCopyOwner owner, int flags) { + private void resolve( + ICompilationUnit[] compilationUnits, + String[] bindingKeys, + ASTRequestor astRequestor, + int apiLevel, + Map compilerOptions, + WorkingCopyOwner owner, + int flags) { // temporarily connect ourselves to the ASTResolver - must disconnect when done astRequestor.compilationUnitResolver = this; Index: dom/org/eclipse/jdt/core/dom/MethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java,v retrieving revision 1.93 diff -u -r1.93 MethodBinding.java --- dom/org/eclipse/jdt/core/dom/MethodBinding.java 27 Jun 2008 16:03:47 -0000 1.93 +++ dom/org/eclipse/jdt/core/dom/MethodBinding.java 4 Feb 2010 22:43:08 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.jdt.core.dom; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding; @@ -243,6 +244,9 @@ } private JavaElement getUnresolvedJavaElement() { + if (JavaCore.getPlugin() == null) { + return null; + } if (!(this.resolver instanceof DefaultBindingResolver)) return null; DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver; Index: dom/org/eclipse/jdt/core/dom/NameEnviromentWithProgress.java =================================================================== RCS file: dom/org/eclipse/jdt/core/dom/NameEnviromentWithProgress.java diff -N dom/org/eclipse/jdt/core/dom/NameEnviromentWithProgress.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ dom/org/eclipse/jdt/core/dom/NameEnviromentWithProgress.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.dom; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; +import org.eclipse.jdt.internal.core.INameEnviromentWithProgress; +import org.eclipse.jdt.internal.core.NameLookup; + +/** + * Batch name environment that is cancelable using a monitor. + * @since 3.6 + */ +class NameEnviromentWithProgress extends FileSystem implements INameEnviromentWithProgress { + IProgressMonitor monitor; + + public NameEnviromentWithProgress(Classpath[] paths, String[] initialFileNames, IProgressMonitor monitor) { + super(paths, initialFileNames); + setMonitor(monitor); + } + private void checkCanceled() { + if (this.monitor != null && this.monitor.isCanceled()) { + if (NameLookup.VERBOSE) + System.out.println(Thread.currentThread() + " CANCELLING LOOKUP "); //$NON-NLS-1$ + throw new AbortCompilation(true/*silent*/, new OperationCanceledException()); + } + } + public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { + checkCanceled(); + return super.findType(typeName, packageName); + } + public NameEnvironmentAnswer findType(char[][] compoundName) { + checkCanceled(); + return super.findType(compoundName); + } + public boolean isPackage(char[][] compoundName, char[] packageName) { + checkCanceled(); + return super.isPackage(compoundName, packageName); + } + + public void setMonitor(IProgressMonitor monitor) { + this.monitor = monitor; + } +} Index: dom/org/eclipse/jdt/core/dom/TypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/TypeBinding.java,v retrieving revision 1.145 diff -u -r1.145 TypeBinding.java --- dom/org/eclipse/jdt/core/dom/TypeBinding.java 7 Mar 2009 00:59:01 -0000 1.145 +++ dom/org/eclipse/jdt/core/dom/TypeBinding.java 4 Feb 2010 22:43:10 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.jdt.core.dom; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.Wildcard; @@ -512,6 +513,9 @@ return getUnresolvedJavaElement(this.binding); } private JavaElement getUnresolvedJavaElement(org.eclipse.jdt.internal.compiler.lookup.TypeBinding typeBinding ) { + if (JavaCore.getPlugin() == null) { + return null; + } if (this.resolver instanceof DefaultBindingResolver) { DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver; return org.eclipse.jdt.internal.core.util.Util.getUnresolvedJavaElement( Index: dom/org/eclipse/jdt/core/dom/VariableBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java,v retrieving revision 1.62 diff -u -r1.62 VariableBinding.java --- dom/org/eclipse/jdt/core/dom/VariableBinding.java 27 Jun 2008 16:03:48 -0000 1.62 +++ dom/org/eclipse/jdt/core/dom/VariableBinding.java 4 Feb 2010 22:43:10 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.jdt.core.dom; import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.util.IModifierConstants; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -202,6 +203,9 @@ } private JavaElement getUnresolvedJavaElement() { + if (JavaCore.getPlugin() == null) { + return null; + } if (isField()) { if (this.resolver instanceof DefaultBindingResolver) { DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver; Index: model/org/eclipse/jdt/internal/core/CancelableNameEnvironment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CancelableNameEnvironment.java,v retrieving revision 1.11 diff -u -r1.11 CancelableNameEnvironment.java --- model/org/eclipse/jdt/internal/core/CancelableNameEnvironment.java 7 Mar 2009 01:08:08 -0000 1.11 +++ model/org/eclipse/jdt/internal/core/CancelableNameEnvironment.java 4 Feb 2010 22:43:10 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2009 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,12 +19,12 @@ import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; -public class CancelableNameEnvironment extends SearchableEnvironment { - public IProgressMonitor monitor; +public class CancelableNameEnvironment extends SearchableEnvironment implements INameEnviromentWithProgress { + private IProgressMonitor monitor; public CancelableNameEnvironment(JavaProject project, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { super(project, owner); - this.monitor = monitor; + setMonitor(monitor); } private void checkCanceled() { @@ -54,4 +54,8 @@ checkCanceled(); super.findTypes(prefix, findMembers, camelCaseMatch, searchFor, storage, progressMonitor); } + + public void setMonitor(IProgressMonitor monitor) { + this.monitor = monitor; + } } Index: model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java,v retrieving revision 1.65 diff -u -r1.65 CompilationUnitProblemFinder.java --- model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java 26 Nov 2009 16:20:05 -0000 1.65 +++ model/org/eclipse/jdt/internal/core/CompilationUnitProblemFinder.java 4 Feb 2010 22:43:10 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -229,7 +229,7 @@ throw new JavaModelException(e, IJavaModelStatusConstants.COMPILER_FAILURE); } finally { if (environment != null) - environment.monitor = null; // don't hold a reference to this external object + environment.setMonitor(null); // don't hold a reference to this external object if (problemFactory != null) problemFactory.monitor = null; // don't hold a reference to this external object // NB: unit.cleanUp() is done by caller Index: model/org/eclipse/jdt/internal/core/INameEnviromentWithProgress.java =================================================================== RCS file: model/org/eclipse/jdt/internal/core/INameEnviromentWithProgress.java diff -N model/org/eclipse/jdt/internal/core/INameEnviromentWithProgress.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ model/org/eclipse/jdt/internal/core/INameEnviromentWithProgress.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,8 @@ +package org.eclipse.jdt.internal.core; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; + +public interface INameEnviromentWithProgress extends INameEnvironment { + void setMonitor(IProgressMonitor monitor); +} #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java,v retrieving revision 1.83 diff -u -r1.83 TestAll.java --- src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java 21 Oct 2009 16:19:39 -0000 1.83 +++ src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java 4 Feb 2010 22:43:11 -0000 @@ -15,6 +15,7 @@ import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.jdt.core.tests.dom.StandAloneASTParserTest; import org.eclipse.jdt.core.tests.junit.extension.TestCase; import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -101,6 +102,7 @@ // Build final test suite TestSuite all = new TestSuite(TestAll.class.getName()); + all.addTest(new TestSuite(StandAloneASTParserTest.class)); int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) { ArrayList tests_1_3 = (ArrayList)standardTests.clone(); Index: src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java =================================================================== RCS file: src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java diff -N src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.dom; + +import java.util.List; + +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest; +import org.eclipse.jdt.core.tests.util.Util; + +public class StandAloneASTParserTest extends AbstractRegressionTest { + public StandAloneASTParserTest(String name) { + super(name); + } + public ASTNode runConversion( + int astLevel, + String source, + boolean resolveBindings, + boolean statementsRecovery, + boolean bindingsRecovery, + String unitName) { + + ASTParser parser = ASTParser.newParser(astLevel); + parser.setSource(source.toCharArray()); + parser.setEnvironment(Util.getJavaClassLibs(), null); + parser.setResolveBindings(resolveBindings); + parser.setStatementsRecovery(statementsRecovery); + parser.setBindingsRecovery(bindingsRecovery); + parser.setCompilerOptions(getCompilerOptions()); + parser.setUnitName(unitName); + return parser.createAST(null); + } + public void test1() { + String contents = + "package p;\n" + + "public class X {\n" + + " public int i;\n" + + " public static void main(String[] args) {\n" + + " int length = args.length;\n" + + " System.out.println(length);\n" + + " }\n" + + "}"; + ASTNode node = runConversion(AST.JLS3, contents, true, true, true, "p/X.java"); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + CompilationUnit unit = (CompilationUnit) node; + List types = unit.types(); + TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0); + ITypeBinding binding = typeDeclaration.resolveBinding(); + assertNotNull("No binding", binding); + assertNull("Got a java element", binding.getJavaElement()); + assertEquals("Wrong name", "p.X", binding.getQualifiedName()); + MethodDeclaration methodDeclaration = (MethodDeclaration) typeDeclaration.bodyDeclarations().get(1); + IMethodBinding methodBinding = methodDeclaration.resolveBinding(); + assertNotNull("No binding", methodBinding); + assertNull("Got a java element", methodBinding.getJavaElement()); + Block body = methodDeclaration.getBody(); + VariableDeclarationStatement statement = (VariableDeclarationStatement) body.statements().get(0); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0); + IVariableBinding variableBinding = fragment.resolveBinding(); + assertNotNull("No binding", variableBinding); + assertNull("Got a java element", variableBinding.getJavaElement()); + ExpressionStatement statement2 = (ExpressionStatement) body.statements().get(1); + Expression expression = statement2.getExpression(); + MethodInvocation invocation = (MethodInvocation) expression; + Expression expression2 = invocation.getExpression(); + assertNotNull("No binding", expression2.resolveTypeBinding()); + + FieldDeclaration fieldDeclaration = (FieldDeclaration) typeDeclaration.bodyDeclarations().get(0); + VariableDeclarationFragment fragment2 = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0); + IVariableBinding variableBinding2 = fragment2.resolveBinding(); + assertNotNull("No binding", variableBinding2); + assertNull("Got a java element", variableBinding2.getJavaElement()); + } +}