View | Details | Raw Unified | Return to bug 233568
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaProject.java (+1 lines)
Lines 1390-1395 Link Here
1390
							manager.deltaState.addClasspathValidation(JavaProject.this);
1390
							manager.deltaState.addClasspathValidation(JavaProject.this);
1391
						}
1391
						}
1392
						manager.resetProjectOptions(JavaProject.this);
1392
						manager.resetProjectOptions(JavaProject.this);
1393
						JavaProject.this.resetCaches(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568
1393
    				}
1394
    				}
1394
    			}
1395
    			}
1395
    		};
1396
    		};
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-59 / +70 lines)
Lines 1282-1348 Link Here
1282
         */
1282
         */
1283
        public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
1283
        public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
1284
        	String propertyName = event.getKey();
1284
        	String propertyName = event.getKey();
1285
        	if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
1285
        	if (propertyName.startsWith(JavaCore.PLUGIN_ID)) {
1286
        		String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
1286
	        	if (propertyName.startsWith(CP_VARIABLE_PREFERENCES_PREFIX)) {
1287
        		JavaModelManager manager = getJavaModelManager();
1287
	        		String varName = propertyName.substring(CP_VARIABLE_PREFERENCES_PREFIX.length());
1288
        		if (manager.variablesWithInitializer.contains(varName)) {
1288
	        		JavaModelManager manager = getJavaModelManager();
1289
        			// revert preference value as we will not apply it to JavaCore classpath variable
1289
	        		if (manager.variablesWithInitializer.contains(varName)) {
1290
        			String oldValue = (String) event.getOldValue();
1290
	        			// revert preference value as we will not apply it to JavaCore classpath variable
1291
        			if (oldValue == null) {
1291
	        			String oldValue = (String) event.getOldValue();
1292
        				// unexpected old value => remove variable from set
1292
	        			if (oldValue == null) {
1293
        				manager.variablesWithInitializer.remove(varName);
1293
	        				// unexpected old value => remove variable from set
1294
        			} else {
1294
	        				manager.variablesWithInitializer.remove(varName);
1295
        				manager.getInstancePreferences().put(varName, oldValue);
1295
	        			} else {
1296
        			}
1296
	        				manager.getInstancePreferences().put(varName, oldValue);
1297
        		} else {
1297
	        			}
1298
        			String newValue = (String)event.getNewValue();
1298
	        		} else {
1299
        			IPath newPath;
1299
	        			String newValue = (String)event.getNewValue();
1300
        			if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1300
	        			IPath newPath;
1301
        				newPath = new Path(newValue);
1301
	        			if (newValue != null && !(newValue = newValue.trim()).equals(CP_ENTRY_IGNORE)) {
1302
        			} else {
1302
	        				newPath = new Path(newValue);
1303
        				newPath = null;
1303
	        			} else {
1304
        			}
1304
	        				newPath = null;
1305
        			try {
1305
	        			}
1306
        				SetVariablesOperation operation = new SetVariablesOperation(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/);
1306
	        			try {
1307
        				operation.runOperation(null/*no progress available*/);
1307
	        				SetVariablesOperation operation = new SetVariablesOperation(new String[] {varName}, new IPath[] {newPath}, false/*don't update preferences*/);
1308
        			} catch (JavaModelException e) {
1308
	        				operation.runOperation(null/*no progress available*/);
1309
        				Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$
1309
	        			} catch (JavaModelException e) {
1310
        			}
1310
	        				Util.log(e, "Could not set classpath variable " + varName + " to " + newPath); //$NON-NLS-1$ //$NON-NLS-2$
1311
        		}
1311
	        			}
1312
        	} else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) {
1312
	        		}
1313
        		recreatePersistedContainer(propertyName, (String)event.getNewValue(), false);
1313
	        	} else if (propertyName.startsWith(CP_CONTAINER_PREFERENCES_PREFIX)) {
1314
        	} else if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) ||
1314
	        		recreatePersistedContainer(propertyName, (String)event.getNewValue(), false);
1315
				propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER) ||
1315
	        	} else if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) ||
1316
				propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE) ||
1316
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER) ||
1317
				propertyName.equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER) ||
1317
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE) ||
1318
				propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH) ||
1318
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER) ||
1319
				propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS) ||
1319
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH) ||
1320
				propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS) ||
1320
					propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS) ||
1321
				propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) ||
1321
					propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS) ||
1322
				propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) ||
1322
					propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) ||
1323
				propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL)) {
1323
					propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) ||
1324
				JavaModelManager manager = JavaModelManager.getJavaModelManager();
1324
					propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL)) {
1325
				IJavaModel model = manager.getJavaModel();
1325
					JavaModelManager manager = JavaModelManager.getJavaModelManager();
1326
				IJavaProject[] projects;
1326
					IJavaModel model = manager.getJavaModel();
1327
				try {
1327
					IJavaProject[] projects;
1328
					projects = model.getJavaProjects();
1328
					try {
1329
					for (int i = 0, pl = projects.length; i < pl; i++) {
1329
						projects = model.getJavaProjects();
1330
						JavaProject javaProject = (JavaProject) projects[i];
1330
						for (int i = 0, pl = projects.length; i < pl; i++) {
1331
						manager.deltaState.addClasspathValidation(javaProject);
1331
							JavaProject javaProject = (JavaProject) projects[i];
1332
						try {
1332
							manager.deltaState.addClasspathValidation(javaProject);
1333
							// need to touch the project to force validation by DeltaProcessor
1333
							try {
1334
				            javaProject.getProject().touch(null);
1334
								// need to touch the project to force validation by DeltaProcessor
1335
				        } catch (CoreException e) {
1335
					            javaProject.getProject().touch(null);
1336
				            // skip
1336
					        } catch (CoreException e) {
1337
				        }
1337
					            // skip
1338
					        }
1339
						}
1340
					} catch (JavaModelException e) {
1341
						// skip
1338
					}
1342
					}
1339
				} catch (JavaModelException e) {
1343
	        	} else if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
1340
					// skip
1344
					String libName = propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length());
1345
					UserLibraryManager manager = JavaModelManager.getUserLibraryManager();
1346
	        		manager.updateUserLibrary(libName, (String)event.getNewValue());
1347
	        	}
1348
	        }
1349
        	// Reset all project caches (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 )
1350
        	try {
1351
        		IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
1352
	        	for (int i = 0, length = projects.length; i < length; i++) {
1353
					((JavaProject) projects[i]).resetCaches();
1341
				}
1354
				}
1342
        	} else if (propertyName.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) {
1355
        	} catch (JavaModelException e) {
1343
				String libName = propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length());
1356
        		// cannot retrieve Java projects
1344
				UserLibraryManager manager = JavaModelManager.getUserLibraryManager();
1345
        		manager.updateUserLibrary(libName, (String)event.getNewValue());
1346
        	}
1357
        	}
1347
        }
1358
        }
1348
	}
1359
	}
(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+105 lines)
Lines 13-18 Link Here
13
13
14
import java.io.File;
14
import java.io.File;
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.util.Hashtable;
16
17
17
import junit.framework.Test;
18
import junit.framework.Test;
18
19
Lines 1084-1089 Link Here
1084
	);
1085
	);
1085
}
1086
}
1086
/*
1087
/*
1088
 * Ensures that changing the source level to make a type valid doesn't report an error any longer
1089
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 )
1090
 */
1091
public void testChangeSourceLevel1() throws Exception {
1092
	try {
1093
		IJavaProject p = createJavaProject("P1", new String[] {"src"}, new String[] {"JCL15_LIB", "/P1/lib.jar"}, "bin", "1.5");
1094
		Util.createJar(new String[] {
1095
				"p/enum/X.java",
1096
				"package p.enum;\n" +
1097
				"public class X{\n" +
1098
				"}"
1099
			}, 
1100
			p.getProject().getLocation().append("lib.jar").toOSString(),
1101
			"1.3");
1102
		refresh(p);
1103
		setUpWorkingCopy(
1104
			"/P1/src/p1/X.java",
1105
			"package p1;\n" +
1106
			"public class X {\n" +
1107
			"  p.enum.X field;\n" +
1108
			"}");
1109
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
1110
		/* At this point, the following error is reported:
1111
		"----------\n" + 
1112
		"1. ERROR in /P1/src/p1/X.java (at line 3)\n" + 
1113
		"	p.enum.X field;\n" + 
1114
		"	  ^^^^\n" + 
1115
		"Syntax error on token \"enum\", Identifier expected\n" + 
1116
		"----------\n"
1117
		*/
1118
		
1119
		this.problemRequestor.reset();
1120
		p.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
1121
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, true/*force problem detection*/, null, null);
1122
		assertProblems(
1123
			"Unexpected problems", 
1124
			"----------\n" + 
1125
			"1. WARNING in /P1/src/p1/X.java (at line 3)\n" + 
1126
			"	p.enum.X field;\n" + 
1127
			"	  ^^^^\n" + 
1128
			"\'enum\' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on\n" + 
1129
			"----------\n"
1130
		);
1131
	} finally {
1132
		deleteProject("P1");
1133
	}
1134
}
1135
/*
1136
 * Ensures that changing the source level to make a type valid doesn't report an error any longer
1137
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568 )
1138
 */
1139
public void testChangeSourceLevel2() throws Exception {
1140
	Hashtable defaultOptions = null;
1141
	try {
1142
		defaultOptions = JavaCore.getOptions();
1143
		Hashtable newOptions = new Hashtable();
1144
		newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
1145
		JavaCore.setOptions(newOptions);
1146
		IJavaProject p = createJavaProject("P1", new String[] {"src"}, new String[] {"JCL15_LIB", "/P1/lib.jar"}, "bin");
1147
		Util.createJar(new String[] {
1148
				"p/enum/X.java",
1149
				"package p.enum;\n" +
1150
				"public class X{\n" +
1151
				"}"
1152
			}, 
1153
			p.getProject().getLocation().append("lib.jar").toOSString(),
1154
			"1.3");
1155
		refresh(p);
1156
		setUpWorkingCopy(
1157
			"/P1/src/p1/X.java",
1158
			"package p1;\n" +
1159
			"public class X {\n" +
1160
			"  p.enum.X field;\n" +
1161
			"}");
1162
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
1163
		/* At this point, the following error is reported:
1164
		"----------\n" + 
1165
		"1. ERROR in /P1/src/p1/X.java (at line 3)\n" + 
1166
		"	p.enum.X field;\n" + 
1167
		"	  ^^^^\n" + 
1168
		"Syntax error on token \"enum\", Identifier expected\n" + 
1169
		"----------\n"
1170
		*/
1171
		
1172
		this.problemRequestor.reset();
1173
		newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
1174
		JavaCore.setOptions(newOptions);
1175
		this.workingCopy.reconcile(ICompilationUnit.NO_AST, true/*force problem detection*/, null, null);
1176
		assertProblems(
1177
			"Unexpected problems", 
1178
			"----------\n" + 
1179
			"1. WARNING in /P1/src/p1/X.java (at line 3)\n" + 
1180
			"	p.enum.X field;\n" + 
1181
			"	  ^^^^\n" + 
1182
			"\'enum\' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on\n" + 
1183
			"----------\n"
1184
		);
1185
	} finally {
1186
		deleteProject("P1");
1187
		if (defaultOptions != null)
1188
			JavaCore.setOptions(defaultOptions);
1189
	}
1190
}
1191
/*
1087
 * Ensures that changing a binary folder used as class folder in 2 projects doesn't cause the old binary to be seen
1192
 * Ensures that changing a binary folder used as class folder in 2 projects doesn't cause the old binary to be seen
1088
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
1193
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
1089
 */
1194
 */
(-)src/org/eclipse/jdt/core/tests/util/Util.java (-1 / +2 lines)
Lines 184-190 Link Here
184
                problemFactory);
184
                problemFactory);
185
        batchCompiler.options.produceReferenceInfo = true;
185
        batchCompiler.options.produceReferenceInfo = true;
186
        batchCompiler.compile(compilationUnits(pathsAndContents)); // compile all files together
186
        batchCompiler.compile(compilationUnits(pathsAndContents)); // compile all files together
187
        System.err.print(requestor.problemLog); // problem log empty if no problems
187
        if (requestor.hasErrors)
188
	        System.err.print(requestor.problemLog); // problem log empty if no problems
188
}
189
}
189
public static String[] concatWithClassLibs(String[] classpaths, boolean inFront) {
190
public static String[] concatWithClassLibs(String[] classpaths, boolean inFront) {
190
    String[] classLibs = getJavaClassLibs();
191
    String[] classLibs = getJavaClassLibs();

Return to bug 233568