Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 511443 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java (-7 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
2
 * Copyright (c) 2000, 2017 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-22 Link Here
16
16
17
import java.net.URL;
17
import java.net.URL;
18
import java.util.ArrayList;
18
import java.util.ArrayList;
19
import java.util.Arrays;
20
import java.util.HashSet;
19
import java.util.List;
21
import java.util.List;
22
import java.util.Set;
23
import java.util.stream.Collectors;
20
24
21
import org.osgi.framework.Bundle;
25
import org.osgi.framework.Bundle;
22
import org.osgi.framework.BundleContext;
26
import org.osgi.framework.BundleContext;
Lines 45-50 Link Here
45
import org.eclipse.ui.IWorkbenchWindow;
49
import org.eclipse.ui.IWorkbenchWindow;
46
import org.eclipse.ui.PartInitException;
50
import org.eclipse.ui.PartInitException;
47
import org.eclipse.ui.plugin.AbstractUIPlugin;
51
import org.eclipse.ui.plugin.AbstractUIPlugin;
52
53
import org.eclipse.jdt.ui.PreferenceConstants;
48
54
49
/**
55
/**
50
 * The plug-in runtime class for the JUnit plug-in.
56
 * The plug-in runtime class for the JUnit plug-in.
Lines 187-204 Link Here
187
		return null;
193
		return null;
188
	}
194
	}
189
195
190
	/**
191
	 * @see AbstractUIPlugin#start(BundleContext)
192
	 */
193
	@Override
196
	@Override
194
	public void start(BundleContext context) throws Exception {
197
	public void start(BundleContext context) throws Exception {
195
		super.start(context);
198
		super.start(context);
196
		fBundleContext= context;
199
		fBundleContext= context;
200
		setCodeassistFavoriteStaticMembers();
197
	}
201
	}
198
202
199
	/**
203
	private void setCodeassistFavoriteStaticMembers() {
200
	 * @see AbstractUIPlugin#stop(BundleContext)
204
		Set<String> favoritesToAdd= new HashSet<>();
201
	 */
205
		favoritesToAdd.add("org.junit.Assert.*"); //$NON-NLS-1$
206
		favoritesToAdd.add("org.junit.Assume.*"); //$NON-NLS-1$
207
		favoritesToAdd.add("org.junit.jupiter.api.Assertions.*"); //$NON-NLS-1$
208
		favoritesToAdd.add("org.junit.jupiter.api.Assumptions.*"); //$NON-NLS-1$
209
		favoritesToAdd.add("org.junit.jupiter.api.DynamicTest.*"); //$NON-NLS-1$
210
211
		// default value
212
		Set<String> defaultFavorites= new HashSet<>();
213
		String defaultPreferenceValue= PreferenceConstants.getPreferenceStore().getDefaultString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS);
214
		if (defaultPreferenceValue != null && defaultPreferenceValue.length() > 0) {
215
			defaultFavorites.addAll(Arrays.asList(defaultPreferenceValue.split(";"))); //$NON-NLS-1$
216
		}
217
		defaultFavorites.addAll(favoritesToAdd);
218
		String newDefaultPreferenceValue= defaultFavorites.stream().collect(Collectors.joining(";")); //$NON-NLS-1$
219
		PreferenceConstants.getPreferenceStore().setDefault(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, newDefaultPreferenceValue);
220
221
		// current value
222
		if (JUnitUIPreferencesConstants.isCodeassistFavoriteStaticMembersMigrated()) {
223
			return;
224
		}
225
		Set<String> currentFavorites= new HashSet<>();
226
		String currentPreferenceValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS);
227
		if (currentPreferenceValue != null && currentPreferenceValue.length() > 0) {
228
			currentFavorites.addAll(Arrays.asList(currentPreferenceValue.split(";"))); //$NON-NLS-1$
229
		}
230
		favoritesToAdd.removeAll(currentFavorites);
231
		if (!favoritesToAdd.isEmpty()) {
232
			String newPreferenceValue= currentPreferenceValue + ";" + favoritesToAdd.stream().collect(Collectors.joining(";")); //$NON-NLS-1$ //$NON-NLS-2$
233
			PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, newPreferenceValue);
234
		}
235
236
		// set as migrated
237
		JUnitUIPreferencesConstants.setCodeassistFavoriteStaticMembersMigrated(true);
238
	}
239
202
	@Override
240
	@Override
203
	public void stop(BundleContext context) throws Exception {
241
	public void stop(BundleContext context) throws Exception {
204
		fIsStopped= true;
242
		fIsStopped= true;
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java (-2 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2016 IBM Corporation and others.
2
 * Copyright (c) 2000, 2017 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 65-70 Link Here
65
import org.eclipse.jdt.ui.CodeStyleConfiguration;
65
import org.eclipse.jdt.ui.CodeStyleConfiguration;
66
import org.eclipse.jdt.ui.ISharedImages;
66
import org.eclipse.jdt.ui.ISharedImages;
67
import org.eclipse.jdt.ui.JavaUI;
67
import org.eclipse.jdt.ui.JavaUI;
68
import org.eclipse.jdt.ui.PreferenceConstants;
68
import org.eclipse.jdt.ui.text.java.ClasspathFixProcessor;
69
import org.eclipse.jdt.ui.text.java.ClasspathFixProcessor;
69
import org.eclipse.jdt.ui.text.java.ClasspathFixProcessor.ClasspathFixProposal;
70
import org.eclipse.jdt.ui.text.java.ClasspathFixProcessor.ClasspathFixProposal;
70
import org.eclipse.jdt.ui.text.java.IInvocationContext;
71
import org.eclipse.jdt.ui.text.java.IInvocationContext;
Lines 103-109 Link Here
103
			if (IProblem.UndefinedType == id) {
104
			if (IProblem.UndefinedType == id) {
104
				res= getAddJUnitToBuildPathProposals(context, problem, res);
105
				res= getAddJUnitToBuildPathProposals(context, problem, res);
105
			} else if (id == IProblem.UndefinedMethod) {
106
			} else if (id == IProblem.UndefinedMethod) {
106
				res= getAddAssertImportProposals(context, problem, res);
107
				String currentPreferenceValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS);
108
				if (!currentPreferenceValue.contains("org.junit.Assert.*")) { //$NON-NLS-1$
109
					res= getAddAssertImportProposals(context, problem, res);
110
				}
107
			}
111
			}
108
		}
112
		}
109
		if (res == null || res.isEmpty()) {
113
		if (res == null || res.isEmpty()) {
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010, 2016 IBM Corporation and others.
2
 * Copyright (c) 2010, 2017 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
16
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
17
import org.eclipse.core.runtime.preferences.InstanceScope;
17
import org.eclipse.core.runtime.preferences.InstanceScope;
18
18
19
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
20
19
/**
21
/**
20
 * Defines constants which are used to refer to values in the plugin's preference store.
22
 * Defines constants which are used to refer to values in the plugin's preference store.
21
 * 
23
 * 
Lines 30-35 Link Here
30
32
31
	public static final boolean SHOW_IN_ALL_VIEWS_DEFAULT= false; // would need a PreferenceInitializer if this was changed to true!
33
	public static final boolean SHOW_IN_ALL_VIEWS_DEFAULT= false; // would need a PreferenceInitializer if this was changed to true!
32
34
35
	private static final String CODEASSIST_FAVORITE_STATIC_MEMBERS_MIGRATED= JUnitPlugin.PLUGIN_ID + ".content_assist_favorite_static_members_migrated"; //$NON-NLS-1$
36
33
	private JUnitUIPreferencesConstants() {
37
	private JUnitUIPreferencesConstants() {
34
		// no instance
38
		// no instance
35
	}
39
	}
Lines 47-50 Link Here
47
			JUnitPlugin.log(e);
51
			JUnitPlugin.log(e);
48
		}
52
		}
49
	}
53
	}
54
55
	public static boolean isCodeassistFavoriteStaticMembersMigrated() {
56
		return Platform.getPreferencesService().getBoolean(JUnitCorePlugin.CORE_PLUGIN_ID, CODEASSIST_FAVORITE_STATIC_MEMBERS_MIGRATED, false, null);
57
	}
58
59
	public static void setCodeassistFavoriteStaticMembersMigrated(boolean migrated) {
60
		IEclipsePreferences preferences= InstanceScope.INSTANCE.getNode(JUnitCorePlugin.CORE_PLUGIN_ID);
61
		preferences.putBoolean(CODEASSIST_FAVORITE_STATIC_MEMBERS_MIGRATED, migrated);
62
		try {
63
			preferences.flush();
64
		} catch (BackingStoreException e) {
65
			JUnitPlugin.log(e);
66
		}
67
	}
50
}
68
}

Return to bug 511443