### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.402 diff -u -r1.402 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 25 Apr 2008 13:20:45 -0000 1.402 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 26 May 2008 16:29:17 -0000 @@ -1390,6 +1390,7 @@ manager.deltaState.addClasspathValidation(JavaProject.this); } manager.resetProjectOptions(JavaProject.this); + JavaProject.this.resetCaches(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 } } }; Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.395 diff -u -r1.395 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 25 Apr 2008 10:09:57 -0000 1.395 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 26 May 2008 16:29:16 -0000 @@ -1282,67 +1282,78 @@ */ public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) { String propertyName = event.getKey(); - if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) { - String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length()); - JavaModelManager manager = getJavaModelManager(); - if (manager.variablesWithInitializer.contains(varName)) { - // revert preference value as we will not apply it to JavaCore classpath variable - String oldValue = (String) event.getOldValue(); - if (oldValue == null) { - // unexpected old value => remove variable from set - manager.variablesWithInitializer.remove(varName); - } else { - manager.getInstancePreferences().put(varName, oldValue); - } - } else { - String newValue = (String)event.getNewValue(); - IPath newPath; - if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) { - newPath = new Path(newValue); - } else { - newPath = null; - } - try { - SetVariablesOperation operation = new SetVariablesOperation(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/); - operation.runOperation(null/*no progress available*/); - } catch (JavaModelException e) { - Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - } else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) { - recreatePersistedContainer(propertyName, (String)event.getNewValue(), false); - } else if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) || - propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER) || - propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE) || - propertyName.equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER) || - propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH) || - propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS) || - propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS) || - propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) || - propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) || - propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL)) { - JavaModelManager manager = JavaModelManager.getJavaModelManager(); - IJavaModel model = manager.getJavaModel(); - IJavaProject[] projects; - try { - projects = model.getJavaProjects(); - for (int i = 0, pl = projects.length; i < pl; i++) { - JavaProject javaProject = (JavaProject) projects[i]; - manager.deltaState.addClasspathValidation(javaProject); - try { - // need to touch the project to force validation by DeltaProcessor - javaProject.getProject().touch(null); - } catch (CoreException e) { - // skip - } + if (propertyName.startsWith(JavaCore.PLUGIN_ID)) { + if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) { + String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length()); + JavaModelManager manager = getJavaModelManager(); + if (manager.variablesWithInitializer.contains(varName)) { + // revert preference value as we will not apply it to JavaCore classpath variable + String oldValue = (String) event.getOldValue(); + if (oldValue == null) { + // unexpected old value => remove variable from set + manager.variablesWithInitializer.remove(varName); + } else { + manager.getInstancePreferences().put(varName, oldValue); + } + } else { + String newValue = (String)event.getNewValue(); + IPath newPath; + if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) { + newPath = new Path(newValue); + } else { + newPath = null; + } + try { + SetVariablesOperation operation = new SetVariablesOperation(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/); + operation.runOperation(null/*no progress available*/); + } catch (JavaModelException e) { + Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) { + recreatePersistedContainer(propertyName, (String)event.getNewValue(), false); + } else if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) || + propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER) || + propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE) || + propertyName.equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER) || + propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH) || + propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS) || + propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS) || + propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) || + propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) || + propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL)) { + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IJavaModel model = manager.getJavaModel(); + IJavaProject[] projects; + try { + projects = model.getJavaProjects(); + for (int i = 0, pl = projects.length; i < pl; i++) { + JavaProject javaProject = (JavaProject) projects[i]; + manager.deltaState.addClasspathValidation(javaProject); + try { + // need to touch the project to force validation by DeltaProcessor + javaProject.getProject().touch(null); + } catch (CoreException e) { + // skip + } + } + } catch (JavaModelException e) { + // skip } - } catch (JavaModelException e) { - // skip + } else if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) { + String libName = propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length()); + UserLibraryManager manager = JavaModelManager.getUserLibraryManager(); + manager.updateUserLibrary(libName, (String)event.getNewValue()); + } + } + // Reset all project caches (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 ) + try { + IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); + for (int i = 0, length = projects.length; i < length; i++) { + ((JavaProject) projects[i]).resetCaches(); } - } else if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) { - String libName = propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length()); - UserLibraryManager manager = JavaModelManager.getUserLibraryManager(); - manager.updateUserLibrary(libName, (String)event.getNewValue()); + } catch (JavaModelException e) { + // cannot retrieve Java projects } } } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java,v retrieving revision 1.131 diff -u -r1.131 ReconcilerTests.java --- src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 20 May 2008 13:22:15 -0000 1.131 +++ src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java 26 May 2008 16:29:19 -0000 @@ -13,6 +13,7 @@ import java.io.File; import java.io.IOException; +import java.util.Hashtable; import junit.framework.Test; @@ -1084,6 +1085,110 @@ ); } /* + * Ensures that changing the source level to make a type valid doesn't report an error any longer + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 ) + */ +public void testChangeSourceLevel1() throws Exception { + try { + IJavaProject p = createJavaProject("P1", new String[] {"src"}, new String[] {"JCL15_LIB", "/P1/lib.jar"}, "bin", "1.5"); + Util.createJar(new String[] { + "p/enum/X.java", + "package p.enum;\n" + + "public class X{\n" + + "}" + }, + p.getProject().getLocation().append("lib.jar").toOSString(), + "1.3"); + refresh(p); + setUpWorkingCopy( + "/P1/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " p.enum.X field;\n" + + "}"); + this.workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null); + /* At this point, the following error is reported: + "----------\n" + + "1. ERROR in /P1/src/p1/X.java (at line 3)\n" + + " p.enum.X field;\n" + + " ^^^^\n" + + "Syntax error on token \"enum\", Identifier expected\n" + + "----------\n" + */ + + this.problemRequestor.reset(); + p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.workingCopy.reconcile(ICompilationUnit.NO_AST, true/*force problem detection*/, null, null); + assertProblems( + "Unexpected problems", + "----------\n" + + "1. WARNING in /P1/src/p1/X.java (at line 3)\n" + + " p.enum.X field;\n" + + " ^^^^\n" + + "\'enum\' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on\n" + + "----------\n" + ); + } finally { + deleteProject("P1"); + } +} +/* + * Ensures that changing the source level to make a type valid doesn't report an error any longer + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 ) + */ +public void testChangeSourceLevel2() throws Exception { + Hashtable defaultOptions = null; + try { + defaultOptions = JavaCore.getOptions(); + Hashtable newOptions = new Hashtable(); + newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + JavaCore.setOptions(newOptions); + IJavaProject p = createJavaProject("P1", new String[] {"src"}, new String[] {"JCL15_LIB", "/P1/lib.jar"}, "bin"); + Util.createJar(new String[] { + "p/enum/X.java", + "package p.enum;\n" + + "public class X{\n" + + "}" + }, + p.getProject().getLocation().append("lib.jar").toOSString(), + "1.3"); + refresh(p); + setUpWorkingCopy( + "/P1/src/p1/X.java", + "package p1;\n" + + "public class X {\n" + + " p.enum.X field;\n" + + "}"); + this.workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null); + /* At this point, the following error is reported: + "----------\n" + + "1. ERROR in /P1/src/p1/X.java (at line 3)\n" + + " p.enum.X field;\n" + + " ^^^^\n" + + "Syntax error on token \"enum\", Identifier expected\n" + + "----------\n" + */ + + this.problemRequestor.reset(); + newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + JavaCore.setOptions(newOptions); + this.workingCopy.reconcile(ICompilationUnit.NO_AST, true/*force problem detection*/, null, null); + assertProblems( + "Unexpected problems", + "----------\n" + + "1. WARNING in /P1/src/p1/X.java (at line 3)\n" + + " p.enum.X field;\n" + + " ^^^^\n" + + "\'enum\' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on\n" + + "----------\n" + ); + } finally { + deleteProject("P1"); + if (defaultOptions != null) + JavaCore.setOptions(defaultOptions); + } +} +/* * Ensures that changing a binary folder used as class folder in 2 projects doesn't cause the old binary to be seen * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 ) */ #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v retrieving revision 1.62 diff -u -r1.62 Util.java --- src/org/eclipse/jdt/core/tests/util/Util.java 20 Mar 2008 08:57:51 -0000 1.62 +++ src/org/eclipse/jdt/core/tests/util/Util.java 26 May 2008 16:29:20 -0000 @@ -184,7 +184,8 @@ problemFactory); batchCompiler.options.produceReferenceInfo = true; batchCompiler.compile(compilationUnits(pathsAndContents)); // compile all files together - System.err.print(requestor.problemLog); // problem log empty if no problems + if (requestor.hasErrors) + System.err.print(requestor.problemLog); // problem log empty if no problems } public static String[] concatWithClassLibs(String[] classpaths, boolean inFront) { String[] classLibs = getJavaClassLibs();