From daaa3f321588a9227274321bf15115be6c16323f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Sat, 18 Jan 2025 12:36:00 +0200 Subject: [PATCH] Migrate ContentAssistHistory to IEclipsePreferences Long deprecated o.e.core.runtime.Preferences class would better not be used anymore. --- .../contentassist/ContentAssistHistoryTest.java | 9 +++++---- .../ui/org/eclipse/jdt/internal/ui/JavaPlugin.java | 4 ++-- .../ui/text/java/ContentAssistHistory.java | 14 +++++++------- .../ui/org/eclipse/jdt/ui/PreferenceConstants.java | 5 +++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ContentAssistHistoryTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ContentAssistHistoryTest.java index 118d86c3517..aa707084177 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ContentAssistHistoryTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/ContentAssistHistoryTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2020 IBM Corporation and others. + * Copyright (c) 2005, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -25,7 +25,8 @@ import org.junit.Rule; import org.junit.Test; -import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IType; @@ -228,14 +229,14 @@ public void testReadOnlyHistory() { } @Test - public void testLoadStore() throws Exception { + public void testLoadStoreIEclipsePreferences() throws Exception { ContentAssistHistory history= new ContentAssistHistory(); history.remember(fgListT, fgArrayListT); history.remember(fgCharSequenceT, fgStringT); - Preferences prefs= new Preferences(); + IEclipsePreferences prefs= InstanceScope.INSTANCE.getNode("org.eclipse.jdt.text.testsa"); String key= "myKey"; ContentAssistHistory.store(history, prefs, key); ContentAssistHistory loaded= ContentAssistHistory.load(prefs, key); diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java index 91d35681f96..d95a28904d9 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/JavaPlugin.java @@ -493,7 +493,7 @@ public void stop(BundleContext context) throws Exception { } if (fContentAssistHistory != null) { - ContentAssistHistory.store(fContentAssistHistory, getPluginPreferences(), PreferenceConstants.CODEASSIST_LRU_HISTORY); + ContentAssistHistory.store(fContentAssistHistory, InstanceScope.INSTANCE.getNode(JavaPlugin.getPluginId()), PreferenceConstants.CODEASSIST_LRU_HISTORY); fContentAssistHistory= null; } @@ -1045,7 +1045,7 @@ public ContentAssistHistory getContentAssistHistory() { return fContentAssistHistory; } try { - fContentAssistHistory= ContentAssistHistory.load(getPluginPreferences(), PreferenceConstants.CODEASSIST_LRU_HISTORY); + fContentAssistHistory= ContentAssistHistory.load(InstanceScope.INSTANCE.getNode(JavaPlugin.getPluginId()), PreferenceConstants.CODEASSIST_LRU_HISTORY); } catch (CoreException x) { log(x); } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistHistory.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistHistory.java index be49cd74d62..e4132c3d91f 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistHistory.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ContentAssistHistory.java @@ -51,7 +51,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.jdt.core.Flags; import org.eclipse.jdt.core.IType; @@ -455,12 +455,12 @@ private IProgressMonitor getProgressMonitor() { * @param preferences the preferences to store the history into * @param key the key under which to store the history * @throws CoreException if serialization fails - * @see #load(Preferences, String) on how to restore a history stored by this method + * @see #load(IEclipsePreferences, String) on how to restore a history stored by this method */ - public static void store(ContentAssistHistory history, Preferences preferences, String key) throws CoreException { + public static void store(ContentAssistHistory history, IEclipsePreferences preferences, String key) throws CoreException { StringWriter writer= new StringWriter(); new ReaderWriter().store(history, new StreamResult(writer)); - preferences.setValue(key, writer.toString()); + preferences.put(key, writer.toString()); } /** @@ -471,11 +471,11 @@ public static void store(ContentAssistHistory history, Preferences preferences, * @return the deserialized history, or null if there is nothing stored under the * given key * @throws CoreException if deserialization fails - * @see #store(ContentAssistHistory, Preferences, String) on how to store a history such that it + * @see #store(ContentAssistHistory, IEclipsePreferences, String) on how to store a history such that it * can be read by this method */ - public static ContentAssistHistory load(Preferences preferences, String key) throws CoreException { - String value= preferences.getString(key); + public static ContentAssistHistory load(IEclipsePreferences preferences, String key) throws CoreException { + String value= preferences.get(key, ""); //$NON-NLS-1$ if (value != null && value.length() > 0) { return new ReaderWriter().load(new InputSource(new StringReader(value))); } diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java index 8c32e3d7bf7..0cc78f9cd48 100644 --- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java +++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2023 IBM Corporation and others. + * Copyright (c) 2000, 2025 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -26,6 +26,7 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.action.Action; @@ -3776,7 +3777,7 @@ private PreferenceConstants() { * Value is an XML encoded version of the history. *

* - * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistHistory#load(org.eclipse.core.runtime.Preferences, String) + * @see org.eclipse.jdt.internal.ui.text.java.ContentAssistHistory#load(IEclipsePreferences, String) * @since 3.2 */ public static final String CODEASSIST_LRU_HISTORY= "content_assist_lru_history"; //$NON-NLS-1$