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

(-)model/org/eclipse/jdt/core/JavaCore.java (-64 / +14 lines)
Lines 64-73 Link Here
64
import org.eclipse.core.runtime.*;
64
import org.eclipse.core.runtime.*;
65
import org.eclipse.core.runtime.jobs.ISchedulingRule;
65
import org.eclipse.core.runtime.jobs.ISchedulingRule;
66
import org.eclipse.core.runtime.jobs.Job;
66
import org.eclipse.core.runtime.jobs.Job;
67
import org.eclipse.core.runtime.preferences.DefaultScope;
68
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
67
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
69
import org.eclipse.core.runtime.preferences.IPreferencesService;
68
import org.eclipse.core.runtime.preferences.IPreferencesService;
70
import org.eclipse.core.runtime.preferences.InstanceScope;
71
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
69
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
72
import org.eclipse.jdt.internal.core.*;
70
import org.eclipse.jdt.internal.core.*;
73
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
71
import org.eclipse.jdt.internal.core.util.MementoTokenizer;
Lines 992-1005 Link Here
992
	 * @since 3.0
990
	 * @since 3.0
993
	 */
991
	 */
994
	public static final String PRIVATE = "private"; //$NON-NLS-1$
992
	public static final String PRIVATE = "private"; //$NON-NLS-1$
995
	
996
	/**
997
	 * New Preferences API
998
	 * @since 3.1
999
	 */
1000
	public static final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
1001
	static final int PREF_INSTANCE = 0;
1002
	static final int PREF_DEFAULT = 1;
1003
993
1004
	/**
994
	/**
1005
	 * Creates the Java core plug-in.
995
	 * Creates the Java core plug-in.
Lines 2301-2308 Link Here
2301
		Hashtable defaultOptions = new Hashtable(10);
2291
		Hashtable defaultOptions = new Hashtable(10);
2302
2292
2303
		// see JavaCorePreferenceInitializer#initializeDefaultPluginPreferences() for changing default settings
2293
		// see JavaCorePreferenceInitializer#initializeDefaultPluginPreferences() for changing default settings
2304
		IEclipsePreferences defaultPreferences = getDefaultPreferences();
2294
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
2305
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2295
		IEclipsePreferences defaultPreferences = manager.getDefaultPreferences();
2296
		HashSet optionNames = manager.optionNames;
2306
		
2297
		
2307
		// initialize preferences to their default
2298
		// initialize preferences to their default
2308
		Iterator iterator = optionNames.iterator();
2299
		Iterator iterator = optionNames.iterator();
Lines 2319-2344 Link Here
2319
		
2310
		
2320
		return defaultOptions;
2311
		return defaultOptions;
2321
	}
2312
	}
2322
 
2323
	/**
2324
	 * @since 3.1
2325
	 */
2326
	public static IEclipsePreferences getInstancePreferences() {
2327
		if (preferencesLookup[PREF_INSTANCE] == null) {
2328
			preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
2329
		}
2330
		return preferencesLookup[PREF_INSTANCE];
2331
	}
2332
 
2333
	/**
2334
	 * @since 3.1
2335
	 */
2336
	public static IEclipsePreferences getDefaultPreferences() {
2337
		if (preferencesLookup[PREF_DEFAULT] == null) {
2338
			preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
2339
		}
2340
		return preferencesLookup[PREF_DEFAULT];
2341
	}
2342
2313
2343
	/**
2314
	/**
2344
	 * Returns the workspace root default charset encoding.
2315
	 * Returns the workspace root default charset encoding.
Lines 2395-2403 Link Here
2395
			return ERROR;
2366
			return ERROR;
2396
		}
2367
		}
2397
		String propertyName = optionName;
2368
		String propertyName = optionName;
2398
		if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){
2369
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
2370
		if (manager.optionNames.contains(propertyName)){
2399
			IPreferencesService service = Platform.getPreferencesService();
2371
			IPreferencesService service = Platform.getPreferencesService();
2400
			String value =  service.get(optionName, null, preferencesLookup);
2372
			String value =  service.get(optionName, null, manager.preferencesLookup);
2401
			return value==null ? null : value.trim();
2373
			return value==null ? null : value.trim();
2402
		}
2374
		}
2403
		return null;
2375
		return null;
Lines 2419-2432 Link Here
2419
2391
2420
		// init
2392
		// init
2421
		Hashtable options = new Hashtable(10);
2393
		Hashtable options = new Hashtable(10);
2422
		HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames;
2394
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
2395
		HashSet optionNames = manager.optionNames;
2423
		IPreferencesService service = Platform.getPreferencesService();
2396
		IPreferencesService service = Platform.getPreferencesService();
2424
2397
2425
		// set options using preferences service lookup
2398
		// set options using preferences service lookup
2426
		Iterator iterator = optionNames.iterator();
2399
		Iterator iterator = optionNames.iterator();
2427
		while (iterator.hasNext()) {
2400
		while (iterator.hasNext()) {
2428
		    String propertyName = (String) iterator.next();
2401
		    String propertyName = (String) iterator.next();
2429
		    String propertyValue = service.get(propertyName, null, preferencesLookup);
2402
		    String propertyValue = service.get(propertyName, null, manager.preferencesLookup);
2430
		    if (propertyValue != null) {
2403
		    if (propertyValue != null) {
2431
			    options.put(propertyName, propertyValue);
2404
			    options.put(propertyName, propertyValue);
2432
		    }
2405
		    }
Lines 3987-3994 Link Here
3987
	public static void setOptions(Hashtable newOptions) {
3960
	public static void setOptions(Hashtable newOptions) {
3988
		
3961
		
3989
		try {
3962
		try {
3990
			IEclipsePreferences defaultPreferences = getDefaultPreferences();
3963
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
3991
			IEclipsePreferences instancePreferences = getInstancePreferences();
3964
			IEclipsePreferences defaultPreferences = manager.getDefaultPreferences();
3965
			IEclipsePreferences instancePreferences = manager.getInstancePreferences();
3992
3966
3993
			if (newOptions == null){
3967
			if (newOptions == null){
3994
				instancePreferences.clear();
3968
				instancePreferences.clear();
Lines 4064-4097 Link Here
4064
			// request state folder creation (workaround 19885)
4038
			// request state folder creation (workaround 19885)
4065
			JavaCore.getPlugin().getStateLocation();
4039
			JavaCore.getPlugin().getStateLocation();
4066
4040
4067
			// Listen to instance preferences node removal from parent in order to refresh stored one
4041
			// Initialize eclipse preferences
4068
			IEclipsePreferences.INodeChangeListener listener = new IEclipsePreferences.INodeChangeListener() {
4042
			manager.initializePreferences();
4069
				public void added(IEclipsePreferences.NodeChangeEvent event) {
4070
					// do nothing
4071
				}
4072
				public void removed(IEclipsePreferences.NodeChangeEvent event) {
4073
					if (event.getChild() == preferencesLookup[PREF_INSTANCE]) {
4074
						preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
4075
					}
4076
				}
4077
			};
4078
			((IEclipsePreferences) getInstancePreferences().parent()).addNodeChangeListener(listener);
4079
4080
			// Listen to default preferences node removal from parent in order to refresh stored one
4081
			listener = new IEclipsePreferences.INodeChangeListener() {
4082
				public void added(IEclipsePreferences.NodeChangeEvent event) {
4083
					// do nothing
4084
				}
4085
				public void removed(IEclipsePreferences.NodeChangeEvent event) {
4086
					if (event.getChild() == preferencesLookup[PREF_DEFAULT]) {
4087
						preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
4088
					}
4089
				}
4090
			};
4091
			((IEclipsePreferences) getDefaultPreferences().parent()).addNodeChangeListener(listener);
4092
4043
4093
			// retrieve variable values
4044
			// retrieve variable values
4094
			getInstancePreferences().addPreferenceChangeListener(new JavaModelManager.EclipsePreferencesListener());
4095
			manager.loadVariablesAndContainers();
4045
			manager.loadVariablesAndContainers();
4096
4046
4097
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
4047
			final IWorkspace workspace = ResourcesPlugin.getWorkspace();
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-14 / +68 lines)
Lines 20-26 Link Here
20
20
21
import org.eclipse.core.resources.*;
21
import org.eclipse.core.resources.*;
22
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.*;
23
import org.eclipse.core.runtime.preferences.DefaultScope;
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
25
import org.eclipse.core.runtime.preferences.InstanceScope;
24
import org.eclipse.jdt.core.*;
26
import org.eclipse.jdt.core.*;
25
import org.eclipse.jdt.core.compiler.CharOperation;
27
import org.eclipse.jdt.core.compiler.CharOperation;
26
import org.eclipse.jdt.core.compiler.IProblem;
28
import org.eclipse.jdt.core.compiler.IProblem;
Lines 150-156 Link Here
150
	
152
	
151
	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
153
	public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0];
152
	
154
	
155
	// Preferences
153
	public HashSet optionNames = new HashSet(20);
156
	public HashSet optionNames = new HashSet(20);
157
	public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
158
	static final int PREF_INSTANCE = 0;
159
	static final int PREF_DEFAULT = 1;
154
160
155
	/**
161
	/**
156
	 * Returns whether the given full path (for a package) conflicts with the output location
162
	 * Returns whether the given full path (for a package) conflicts with the output location
Lines 908-913 Link Here
908
	}
914
	}
909
915
910
	/**
916
	/**
917
	 * Get workpsace eclipse preference for JavaCore plugin.
918
	 */
919
	public IEclipsePreferences getInstancePreferences() {
920
		return preferencesLookup[PREF_INSTANCE];
921
	}
922
 
923
	/**
924
	 * Get default eclipse preference for JavaCore plugin.
925
	 */
926
	public IEclipsePreferences getDefaultPreferences() {
927
		return preferencesLookup[PREF_DEFAULT];
928
	}
929
930
	/**
911
	 * Returns the handle to the active Java Model.
931
	 * Returns the handle to the active Java Model.
912
	 */
932
	 */
913
	public final JavaModel getJavaModel() {
933
	public final JavaModel getJavaModel() {
Lines 1379-1385 Link Here
1379
		}
1399
		}
1380
		return container;
1400
		return container;
1381
	}
1401
	}
1382
	
1402
1403
	/**
1404
	 * Initialize preferences lookups for JavaCore plugin.
1405
	 */
1406
	public void initializePreferences() {
1407
		
1408
		// Create lookups
1409
		preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
1410
		preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(JavaCore.PLUGIN_ID);
1411
1412
		// Listen to instance preferences node removal from parent in order to refresh stored one
1413
		IEclipsePreferences.INodeChangeListener listener = new IEclipsePreferences.INodeChangeListener() {
1414
			public void added(IEclipsePreferences.NodeChangeEvent event) {
1415
				// do nothing
1416
			}
1417
			public void removed(IEclipsePreferences.NodeChangeEvent event) {
1418
				if (event.getChild() == preferencesLookup[PREF_INSTANCE]) {
1419
					preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
1420
					preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
1421
				}
1422
			}
1423
		};
1424
		((IEclipsePreferences) preferencesLookup[PREF_INSTANCE].parent()).addNodeChangeListener(listener);
1425
		preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
1426
1427
		// Listen to default preferences node removal from parent in order to refresh stored one
1428
		listener = new IEclipsePreferences.INodeChangeListener() {
1429
			public void added(IEclipsePreferences.NodeChangeEvent event) {
1430
				// do nothing
1431
			}
1432
			public void removed(IEclipsePreferences.NodeChangeEvent event) {
1433
				if (event.getChild() == preferencesLookup[PREF_DEFAULT]) {
1434
					preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(JavaCore.PLUGIN_ID);
1435
				}
1436
			}
1437
		};
1438
		((IEclipsePreferences) preferencesLookup[PREF_DEFAULT].parent()).addNodeChangeListener(listener);
1439
	}
1440
1383
	public synchronized char[] intern(char[] array) {
1441
	public synchronized char[] intern(char[] array) {
1384
		return this.charArraySymbols.add(array);
1442
		return this.charArraySymbols.add(array);
1385
	}
1443
	}
Lines 1473-1479 Link Here
1473
		}
1531
		}
1474
		
1532
		
1475
		// load variables and containers from preferences into cache
1533
		// load variables and containers from preferences into cache
1476
		IEclipsePreferences preferences = JavaCore.getInstancePreferences();
1534
		IEclipsePreferences preferences = getInstancePreferences();
1477
1535
1478
		// only get variable from preferences not set to their default
1536
		// only get variable from preferences not set to their default
1479
		try {
1537
		try {
Lines 1802-1807 Link Here
1802
		
1860
		
1803
	    // save container values on snapshot/full save
1861
	    // save container values on snapshot/full save
1804
		IJavaProject[] projects = getJavaModel().getJavaProjects();
1862
		IJavaProject[] projects = getJavaModel().getJavaProjects();
1863
		IEclipsePreferences preferences = getInstancePreferences();
1805
		for (int i = 0, length = projects.length; i < length; i++) {
1864
		for (int i = 0, length = projects.length; i < length; i++) {
1806
		    IJavaProject project = projects[i];
1865
		    IJavaProject project = projects[i];
1807
			// clone while iterating (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59638)
1866
			// clone while iterating (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59638)
Lines 1822-1837 Link Here
1822
				} catch(JavaModelException e){
1881
				} catch(JavaModelException e){
1823
					// could not encode entry: leave it as CP_ENTRY_IGNORE
1882
					// could not encode entry: leave it as CP_ENTRY_IGNORE
1824
				}
1883
				}
1825
				JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary...
1884
				preferences.put(containerKey, containerString);
1826
				JavaCore.getInstancePreferences().put(containerKey, containerString);
1827
			}
1885
			}
1828
		}
1886
		}
1829
		try {
1887
		try {
1830
			JavaCore.getInstancePreferences().flush();
1888
			preferences.flush();
1831
		} catch (BackingStoreException e) {
1889
		} catch (BackingStoreException e) {
1832
			// TODO (frederic) see if it's necessary to report this exception
1890
			IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$
1833
			// IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$
1891
			throw new CoreException(status);
1834
			// throw new CoreException(status);
1835
		}
1892
		}
1836
		
1893
		
1837
		if (context.getKind() == ISaveContext.FULL_SAVE) {
1894
		if (context.getKind() == ISaveContext.FULL_SAVE) {
Lines 2166-2179 Link Here
2166
2223
2167
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
2224
		String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName;
2168
		String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString();
2225
		String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString();
2169
		JavaCore.getDefaultPreferences().put(variableKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary...
2226
		getInstancePreferences().put(variableKey, variableString);
2170
		JavaCore.getInstancePreferences().put(variableKey, variableString);
2171
		try {
2227
		try {
2172
			JavaCore.getInstancePreferences().flush();
2228
			getInstancePreferences().flush();
2173
		} catch (BackingStoreException e) {
2229
		} catch (BackingStoreException e) {
2174
			// TODO (frederic) see if it's necessary to report this exception
2230
			// ignore exception
2175
//			IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$
2176
//			throw new CoreException(status);
2177
		}
2231
		}
2178
	}
2232
	}
2179
}
2233
}
(-)model/org/eclipse/jdt/internal/core/UserLibraryManager.java (-5 / +4 lines)
Lines 124-130 Link Here
124
		if (userLibraries == null) {
124
		if (userLibraries == null) {
125
			userLibraries= new HashMap();
125
			userLibraries= new HashMap();
126
			// load variables and containers from preferences into cache
126
			// load variables and containers from preferences into cache
127
			IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences();
127
			IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
128
			instancePreferences.addPreferenceChangeListener(listener);
128
			instancePreferences.addPreferenceChangeListener(listener);
129
129
130
			// only get variable from preferences not set to their default
130
			// only get variable from preferences not set to their default
Lines 143-149 Link Here
143
					}
143
					}
144
				}
144
				}
145
			} catch (BackingStoreException e) {
145
			} catch (BackingStoreException e) {
146
				// TODO (frederic) see if it's necessary to report this exception
146
				// nothing to do in this case
147
			}
147
			}
148
		}
148
		}
149
		return userLibraries;
149
		return userLibraries;
Lines 182-188 Link Here
182
			}
182
			}
183
		}
183
		}
184
		
184
		
185
		IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences();
185
		IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences();
186
		String containerKey = CP_USERLIBRARY_PREFERENCES_PREFIX+name;
186
		String containerKey = CP_USERLIBRARY_PREFERENCES_PREFIX+name;
187
		String containerString = CP_ENTRY_IGNORE;
187
		String containerString = CP_ENTRY_IGNORE;
188
		if (library != null) {
188
		if (library != null) {
Lines 194-206 Link Here
194
		}
194
		}
195
		instancePreferences.removePreferenceChangeListener(listener);
195
		instancePreferences.removePreferenceChangeListener(listener);
196
		try {
196
		try {
197
			JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary...
198
			instancePreferences.put(containerKey, containerString);
197
			instancePreferences.put(containerKey, containerString);
199
			if (save) {
198
			if (save) {
200
				try {
199
				try {
201
					instancePreferences.flush();
200
					instancePreferences.flush();
202
				} catch (BackingStoreException e) {
201
				} catch (BackingStoreException e) {
203
					// TODO (frederic) see if it's necessary to report this exception
202
					// nothing to do in this case
204
				}
203
				}
205
			}
204
			}
206
			if (rebind) {
205
			if (rebind) {

Return to bug 91497