Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 267055 Details for
Bug 511443
[JUnit 5][content assist][quick fix] Set default favorites for static imports
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
junitImports.patch (text/plain), 7.67 KB, created by
Noopur Gupta
on 2017-03-01 09:56:13 EST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Noopur Gupta
Created:
2017-03-01 09:56:13 EST
Size:
7.67 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java >index 8257678..bd7153d 100644 >--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java >+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitPlugin.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2011 IBM Corporation and others. >+ * Copyright (c) 2000, 2017 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -16,7 +16,11 @@ > > import java.net.URL; > import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.HashSet; > import java.util.List; >+import java.util.Set; >+import java.util.stream.Collectors; > > import org.osgi.framework.Bundle; > import org.osgi.framework.BundleContext; >@@ -45,6 +49,8 @@ > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.plugin.AbstractUIPlugin; >+ >+import org.eclipse.jdt.ui.PreferenceConstants; > > /** > * The plug-in runtime class for the JUnit plug-in. >@@ -187,18 +193,50 @@ > return null; > } > >- /** >- * @see AbstractUIPlugin#start(BundleContext) >- */ > @Override > public void start(BundleContext context) throws Exception { > super.start(context); > fBundleContext= context; >+ setCodeassistFavoriteStaticMembers(); > } > >- /** >- * @see AbstractUIPlugin#stop(BundleContext) >- */ >+ private void setCodeassistFavoriteStaticMembers() { >+ Set<String> favoritesToAdd= new HashSet<>(); >+ favoritesToAdd.add("org.junit.Assert.*"); //$NON-NLS-1$ >+ favoritesToAdd.add("org.junit.Assume.*"); //$NON-NLS-1$ >+ favoritesToAdd.add("org.junit.jupiter.api.Assertions.*"); //$NON-NLS-1$ >+ favoritesToAdd.add("org.junit.jupiter.api.Assumptions.*"); //$NON-NLS-1$ >+ favoritesToAdd.add("org.junit.jupiter.api.DynamicTest.*"); //$NON-NLS-1$ >+ >+ // default value >+ Set<String> defaultFavorites= new HashSet<>(); >+ String defaultPreferenceValue= PreferenceConstants.getPreferenceStore().getDefaultString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS); >+ if (defaultPreferenceValue != null && defaultPreferenceValue.length() > 0) { >+ defaultFavorites.addAll(Arrays.asList(defaultPreferenceValue.split(";"))); //$NON-NLS-1$ >+ } >+ defaultFavorites.addAll(favoritesToAdd); >+ String newDefaultPreferenceValue= defaultFavorites.stream().collect(Collectors.joining(";")); //$NON-NLS-1$ >+ PreferenceConstants.getPreferenceStore().setDefault(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, newDefaultPreferenceValue); >+ >+ // current value >+ if (JUnitUIPreferencesConstants.isCodeassistFavoriteStaticMembersMigrated()) { >+ return; >+ } >+ Set<String> currentFavorites= new HashSet<>(); >+ String currentPreferenceValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS); >+ if (currentPreferenceValue != null && currentPreferenceValue.length() > 0) { >+ currentFavorites.addAll(Arrays.asList(currentPreferenceValue.split(";"))); //$NON-NLS-1$ >+ } >+ favoritesToAdd.removeAll(currentFavorites); >+ if (!favoritesToAdd.isEmpty()) { >+ String newPreferenceValue= currentPreferenceValue + ";" + favoritesToAdd.stream().collect(Collectors.joining(";")); //$NON-NLS-1$ //$NON-NLS-2$ >+ PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, newPreferenceValue); >+ } >+ >+ // set as migrated >+ JUnitUIPreferencesConstants.setCodeassistFavoriteStaticMembersMigrated(true); >+ } >+ > @Override > public void stop(BundleContext context) throws Exception { > fIsStopped= true; >diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java >index 3009998..a85676f 100644 >--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java >+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitQuickFixProcessor.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2016 IBM Corporation and others. >+ * Copyright (c) 2000, 2017 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -65,6 +65,7 @@ > import org.eclipse.jdt.ui.CodeStyleConfiguration; > import org.eclipse.jdt.ui.ISharedImages; > import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.jdt.ui.PreferenceConstants; > import org.eclipse.jdt.ui.text.java.ClasspathFixProcessor; > import org.eclipse.jdt.ui.text.java.ClasspathFixProcessor.ClasspathFixProposal; > import org.eclipse.jdt.ui.text.java.IInvocationContext; >@@ -103,7 +104,10 @@ > if (IProblem.UndefinedType == id) { > res= getAddJUnitToBuildPathProposals(context, problem, res); > } else if (id == IProblem.UndefinedMethod) { >- res= getAddAssertImportProposals(context, problem, res); >+ String currentPreferenceValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS); >+ if (!currentPreferenceValue.contains("org.junit.Assert.*")) { //$NON-NLS-1$ >+ res= getAddAssertImportProposals(context, problem, res); >+ } > } > } > if (res == null || res.isEmpty()) { >diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java >index e107968..f02d975 100644 >--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java >+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/JUnitUIPreferencesConstants.java >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2010, 2016 IBM Corporation and others. >+ * Copyright (c) 2010, 2017 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -16,6 +16,8 @@ > import org.eclipse.core.runtime.preferences.IEclipsePreferences; > import org.eclipse.core.runtime.preferences.InstanceScope; > >+import org.eclipse.jdt.internal.junit.JUnitCorePlugin; >+ > /** > * Defines constants which are used to refer to values in the plugin's preference store. > * >@@ -30,6 +32,8 @@ > > public static final boolean SHOW_IN_ALL_VIEWS_DEFAULT= false; // would need a PreferenceInitializer if this was changed to true! > >+ private static final String CODEASSIST_FAVORITE_STATIC_MEMBERS_MIGRATED= JUnitPlugin.PLUGIN_ID + ".content_assist_favorite_static_members_migrated"; //$NON-NLS-1$ >+ > private JUnitUIPreferencesConstants() { > // no instance > } >@@ -47,4 +51,18 @@ > JUnitPlugin.log(e); > } > } >+ >+ public static boolean isCodeassistFavoriteStaticMembersMigrated() { >+ return Platform.getPreferencesService().getBoolean(JUnitCorePlugin.CORE_PLUGIN_ID, CODEASSIST_FAVORITE_STATIC_MEMBERS_MIGRATED, false, null); >+ } >+ >+ public static void setCodeassistFavoriteStaticMembersMigrated(boolean migrated) { >+ IEclipsePreferences preferences= InstanceScope.INSTANCE.getNode(JUnitCorePlugin.CORE_PLUGIN_ID); >+ preferences.putBoolean(CODEASSIST_FAVORITE_STATIC_MEMBERS_MIGRATED, migrated); >+ try { >+ preferences.flush(); >+ } catch (BackingStoreException e) { >+ JUnitPlugin.log(e); >+ } >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 511443
:
266558
| 267055