Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2024 Google, Inc. and others.
* Copyright (c) 2011, 2025 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -17,14 +17,14 @@
import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils;
import org.eclipse.wb.internal.core.utils.jdt.core.SubtypesScope;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.IColorManager;
import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
import org.eclipse.jdt.ui.text.JavaTextTools;
Expand All @@ -38,14 +38,8 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;

import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;

import java.lang.reflect.Method;

/**
* Helper class for various JDT UI utils.
*
Expand All @@ -56,7 +50,6 @@
public final class JdtUiUtils {
private static IPreferenceStore m_combinedPreferenceStore;
private static JavaTextTools m_javaTextTools;
private static AbstractUIPlugin m_javaPlugin;

////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -89,21 +82,10 @@ public static SourceViewer createJavaSourceViewer(Composite parent, int style) {
}

/**
* @return the instance of "org.eclipse.jdt.ui" activator class, which is the instance of
* org.eclipse.jdt.internal.ui.JavaPlugin when version > 3.2
*/
private static AbstractUIPlugin getJavaPlugin() {
if (m_javaPlugin == null) {
m_javaPlugin = ExecutionUtils.runObject(() -> getJavaPlugin0());
}
return m_javaPlugin;
}

/**
* @return the JavaPlugin instance depending on eclipse version (using preprocessor).
* @return the preference store of the {@code org.eclipse.jdt.ui} plugin.
*/
private static AbstractUIPlugin getJavaPlugin0() throws Exception {
return getBundleActivator("org.eclipse.jdt.ui");
private static IPreferenceStore getJavaPreferenceStore() {
return PreferenceConstants.getPreferenceStore();
}

/**
Expand All @@ -115,7 +97,7 @@ private static IPreferenceStore getCombinedPreferenceStore() {
IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
m_combinedPreferenceStore =
new ChainedPreferenceStore(new IPreferenceStore[]{
getJavaPlugin().getPreferenceStore(),
getJavaPreferenceStore(),
new PreferencesAdapter(JavaCore.getPlugin().getPluginPreferences()),
generalTextStore});
}
Expand All @@ -129,7 +111,7 @@ private static IPreferenceStore getCombinedPreferenceStore() {
private static JavaTextTools getJavaTextTools() {
if (m_javaTextTools == null) {
m_javaTextTools =
new JavaTextTools(getJavaPlugin().getPreferenceStore(),
new JavaTextTools(getJavaPreferenceStore(),
JavaCore.getPlugin().getPluginPreferences());
}
return m_javaTextTools;
Expand Down Expand Up @@ -223,21 +205,4 @@ public static String selectTypeName(Shell shell, IJavaProject javaProject) throw
IType type = selectClassType(shell, javaProject);
return type != null ? type.getFullyQualifiedName() : null;
}

////////////////////////////////////////////////////////////////////////////
//
// Misc
//
////////////////////////////////////////////////////////////////////////////
/**
* @return the bundle activator by "getDefault()" method using reflection.
*/
public static AbstractUIPlugin getBundleActivator(String bundleName) throws Exception {
Bundle bundle = Platform.getBundle(bundleName);
String pluginActivatorClassName = bundle.getHeaders().get(Constants.BUNDLE_ACTIVATOR);
Class<?> pluginClass = bundle.loadClass(pluginActivatorClassName);
// get the it's instance using "getDefault" method. Possibly it is the usage of internal API :)
Method getDefaultMethod = pluginClass.getMethod("getDefault", new Class[0]);
return (AbstractUIPlugin) getDefaultMethod.invoke(null, new Object[0]);
}
}
Original file line number Diff line number Diff line change
@@ -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 which is available at
Expand Down Expand Up @@ -28,6 +28,7 @@
* @since 3.0
* @coverage core.util.jdt.ui
*/
@Deprecated
public class PreferencesAdapter implements IPreferenceStore {
/**
* Property change listener. Listens for events of type
Expand Down
Loading