Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.452 diff -u -r1.452 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 8 Apr 2005 20:30:28 -0000 1.452 +++ model/org/eclipse/jdt/core/JavaCore.java 15 Apr 2005 15:01:18 -0000 @@ -64,10 +64,8 @@ import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.core.*; import org.eclipse.jdt.internal.core.util.MementoTokenizer; @@ -992,14 +990,6 @@ * @since 3.0 */ public static final String PRIVATE = "private"; //$NON-NLS-1$ - - /** - * New Preferences API - * @since 3.1 - */ - public static final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; - static final int PREF_INSTANCE = 0; - static final int PREF_DEFAULT = 1; /** * Creates the Java core plug-in. @@ -2301,8 +2291,9 @@ Hashtable defaultOptions = new Hashtable(10); // see JavaCorePreferenceInitializer#initializeDefaultPluginPreferences() for changing default settings - IEclipsePreferences defaultPreferences = getDefaultPreferences(); - HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences defaultPreferences = manager.getDefaultPreferences(); + HashSet optionNames = manager.optionNames; // initialize preferences to their default Iterator iterator = optionNames.iterator(); @@ -2319,26 +2310,6 @@ return defaultOptions; } - - /** - * @since 3.1 - */ - public static IEclipsePreferences getInstancePreferences() { - if (preferencesLookup[PREF_INSTANCE] == null) { - preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID); - } - return preferencesLookup[PREF_INSTANCE]; - } - - /** - * @since 3.1 - */ - public static IEclipsePreferences getDefaultPreferences() { - if (preferencesLookup[PREF_DEFAULT] == null) { - preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID); - } - return preferencesLookup[PREF_DEFAULT]; - } /** * Returns the workspace root default charset encoding. @@ -2395,9 +2366,10 @@ return ERROR; } String propertyName = optionName; - if (JavaModelManager.getJavaModelManager().optionNames.contains(propertyName)){ + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + if (manager.optionNames.contains(propertyName)){ IPreferencesService service = Platform.getPreferencesService(); - String value = service.get(optionName, null, preferencesLookup); + String value = service.get(optionName, null, manager.preferencesLookup); return value==null ? null : value.trim(); } return null; @@ -2419,14 +2391,15 @@ // init Hashtable options = new Hashtable(10); - HashSet optionNames = JavaModelManager.getJavaModelManager().optionNames; + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + HashSet optionNames = manager.optionNames; IPreferencesService service = Platform.getPreferencesService(); // set options using preferences service lookup Iterator iterator = optionNames.iterator(); while (iterator.hasNext()) { String propertyName = (String) iterator.next(); - String propertyValue = service.get(propertyName, null, preferencesLookup); + String propertyValue = service.get(propertyName, null, manager.preferencesLookup); if (propertyValue != null) { options.put(propertyName, propertyValue); } @@ -3987,8 +3960,9 @@ public static void setOptions(Hashtable newOptions) { try { - IEclipsePreferences defaultPreferences = getDefaultPreferences(); - IEclipsePreferences instancePreferences = getInstancePreferences(); + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences defaultPreferences = manager.getDefaultPreferences(); + IEclipsePreferences instancePreferences = manager.getInstancePreferences(); if (newOptions == null){ instancePreferences.clear(); @@ -4064,34 +4038,10 @@ // request state folder creation (workaround 19885) JavaCore.getPlugin().getStateLocation(); - // Listen to instance preferences node removal from parent in order to refresh stored one - IEclipsePreferences.INodeChangeListener listener = new IEclipsePreferences.INodeChangeListener() { - public void added(IEclipsePreferences.NodeChangeEvent event) { - // do nothing - } - public void removed(IEclipsePreferences.NodeChangeEvent event) { - if (event.getChild() == preferencesLookup[PREF_INSTANCE]) { - preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID); - } - } - }; - ((IEclipsePreferences) getInstancePreferences().parent()).addNodeChangeListener(listener); - - // Listen to default preferences node removal from parent in order to refresh stored one - listener = new IEclipsePreferences.INodeChangeListener() { - public void added(IEclipsePreferences.NodeChangeEvent event) { - // do nothing - } - public void removed(IEclipsePreferences.NodeChangeEvent event) { - if (event.getChild() == preferencesLookup[PREF_DEFAULT]) { - preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID); - } - } - }; - ((IEclipsePreferences) getDefaultPreferences().parent()).addNodeChangeListener(listener); + // Initialize eclipse preferences + manager.initializePreferences(); // retrieve variable values - getInstancePreferences().addPreferenceChangeListener(new JavaModelManager.EclipsePreferencesListener()); manager.loadVariablesAndContainers(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.258 diff -u -r1.258 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 13 Apr 2005 16:50:12 -0000 1.258 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 15 Apr 2005 15:01:25 -0000 @@ -20,7 +20,9 @@ import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jdt.core.*; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; @@ -150,7 +152,11 @@ public final static ICompilationUnit[] NO_WORKING_COPY = new ICompilationUnit[0]; + // Preferences public HashSet optionNames = new HashSet(20); + public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; + static final int PREF_INSTANCE = 0; + static final int PREF_DEFAULT = 1; /** * Returns whether the given full path (for a package) conflicts with the output location @@ -908,6 +914,20 @@ } /** + * Get workpsace eclipse preference for JavaCore plugin. + */ + public IEclipsePreferences getInstancePreferences() { + return preferencesLookup[PREF_INSTANCE]; + } + + /** + * Get default eclipse preference for JavaCore plugin. + */ + public IEclipsePreferences getDefaultPreferences() { + return preferencesLookup[PREF_DEFAULT]; + } + + /** * Returns the handle to the active Java Model. */ public final JavaModel getJavaModel() { @@ -1379,7 +1399,45 @@ } return container; } - + + /** + * Initialize preferences lookups for JavaCore plugin. + */ + public void initializePreferences() { + + // Create lookups + preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(JavaCore.PLUGIN_ID); + preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(JavaCore.PLUGIN_ID); + + // Listen to instance preferences node removal from parent in order to refresh stored one + IEclipsePreferences.INodeChangeListener listener = new IEclipsePreferences.INodeChangeListener() { + public void added(IEclipsePreferences.NodeChangeEvent event) { + // do nothing + } + public void removed(IEclipsePreferences.NodeChangeEvent event) { + if (event.getChild() == preferencesLookup[PREF_INSTANCE]) { + preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(JavaCore.PLUGIN_ID); + preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener()); + } + } + }; + ((IEclipsePreferences) preferencesLookup[PREF_INSTANCE].parent()).addNodeChangeListener(listener); + preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener()); + + // Listen to default preferences node removal from parent in order to refresh stored one + listener = new IEclipsePreferences.INodeChangeListener() { + public void added(IEclipsePreferences.NodeChangeEvent event) { + // do nothing + } + public void removed(IEclipsePreferences.NodeChangeEvent event) { + if (event.getChild() == preferencesLookup[PREF_DEFAULT]) { + preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(JavaCore.PLUGIN_ID); + } + } + }; + ((IEclipsePreferences) preferencesLookup[PREF_DEFAULT].parent()).addNodeChangeListener(listener); + } + public synchronized char[] intern(char[] array) { return this.charArraySymbols.add(array); } @@ -1473,7 +1531,7 @@ } // load variables and containers from preferences into cache - IEclipsePreferences preferences = JavaCore.getInstancePreferences(); + IEclipsePreferences preferences = getInstancePreferences(); // only get variable from preferences not set to their default try { @@ -1802,6 +1860,7 @@ // save container values on snapshot/full save IJavaProject[] projects = getJavaModel().getJavaProjects(); + IEclipsePreferences preferences = getInstancePreferences(); for (int i = 0, length = projects.length; i < length; i++) { IJavaProject project = projects[i]; // clone while iterating (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59638) @@ -1822,16 +1881,14 @@ } catch(JavaModelException e){ // could not encode entry: leave it as CP_ENTRY_IGNORE } - JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary... - JavaCore.getInstancePreferences().put(containerKey, containerString); + preferences.put(containerKey, containerString); } } try { - JavaCore.getInstancePreferences().flush(); + preferences.flush(); } catch (BackingStoreException e) { - // TODO (frederic) see if it's necessary to report this exception - // IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$ - // throw new CoreException(status); + IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$ + throw new CoreException(status); } if (context.getKind() == ISaveContext.FULL_SAVE) { @@ -2166,14 +2223,11 @@ String variableKey = CP_VARIABLE_PREFERENCES_PREFIX+variableName; String variableString = variablePath == null ? CP_ENTRY_IGNORE : variablePath.toString(); - JavaCore.getDefaultPreferences().put(variableKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary... - JavaCore.getInstancePreferences().put(variableKey, variableString); + getInstancePreferences().put(variableKey, variableString); try { - JavaCore.getInstancePreferences().flush(); + getInstancePreferences().flush(); } catch (BackingStoreException e) { - // TODO (frederic) see if it's necessary to report this exception -// IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, IStatus.ERROR, "Problems while saving context", e); //$NON-NLS-1$ -// throw new CoreException(status); + // ignore exception } } } Index: model/org/eclipse/jdt/internal/core/UserLibraryManager.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/UserLibraryManager.java,v retrieving revision 1.5 diff -u -r1.5 UserLibraryManager.java --- model/org/eclipse/jdt/internal/core/UserLibraryManager.java 23 Feb 2005 02:47:29 -0000 1.5 +++ model/org/eclipse/jdt/internal/core/UserLibraryManager.java 15 Apr 2005 15:01:25 -0000 @@ -124,7 +124,7 @@ if (userLibraries == null) { userLibraries= new HashMap(); // load variables and containers from preferences into cache - IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences(); + IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences(); instancePreferences.addPreferenceChangeListener(listener); // only get variable from preferences not set to their default @@ -143,7 +143,7 @@ } } } catch (BackingStoreException e) { - // TODO (frederic) see if it's necessary to report this exception + // nothing to do in this case } } return userLibraries; @@ -182,7 +182,7 @@ } } - IEclipsePreferences instancePreferences = JavaCore.getInstancePreferences(); + IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences(); String containerKey = CP_USERLIBRARY_PREFERENCES_PREFIX+name; String containerString = CP_ENTRY_IGNORE; if (library != null) { @@ -194,13 +194,12 @@ } instancePreferences.removePreferenceChangeListener(listener); try { - JavaCore.getDefaultPreferences().put(containerKey, CP_ENTRY_IGNORE); // TODO (frederic) verify if this is really necessary... instancePreferences.put(containerKey, containerString); if (save) { try { instancePreferences.flush(); } catch (BackingStoreException e) { - // TODO (frederic) see if it's necessary to report this exception + // nothing to do in this case } } if (rebind) {