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 266558 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), 9.56 KB, created by
Noopur Gupta
on 2017-02-01 06:12:56 EST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Noopur Gupta
Created:
2017-02-01 06:12:56 EST
Size:
9.56 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..2627e1b 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,33 @@ > return null; > } > >- /** >- * @see AbstractUIPlugin#start(BundleContext) >- */ > @Override > public void start(BundleContext context) throws Exception { > super.start(context); > fBundleContext= context; >+ setDefaultFavoriteStaticMembers(); > } > >- /** >- * @see AbstractUIPlugin#stop(BundleContext) >- */ >+ private void setDefaultFavoriteStaticMembers() { >+ Set<String> favorites= new HashSet<>(); >+ favorites.add("org.junit.Assert.*"); //$NON-NLS-1$ >+ favorites.add("org.junit.Assume.*"); //$NON-NLS-1$ >+ favorites.add("org.junit.jupiter.api.Assertions.*"); //$NON-NLS-1$ >+ favorites.add("org.junit.jupiter.api.Assumptions.*"); //$NON-NLS-1$ >+ favorites.add("org.junit.jupiter.api.DynamicTest.*"); //$NON-NLS-1$ >+ >+ String currentPreferenceValue= PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS); >+ if (currentPreferenceValue != null && currentPreferenceValue.length() > 0) { >+ Set<String> currentFavorites= new HashSet<>(Arrays.asList(currentPreferenceValue.split(";"))); //$NON-NLS-1$ >+ if (currentFavorites.size() > 0) { >+ favorites.addAll(currentFavorites); >+ } >+ } >+ >+ String newPreferenceValue= favorites.stream().collect(Collectors.joining(";")); //$NON-NLS-1$ >+ PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.CODEASSIST_FAVORITE_STATIC_MEMBERS, newPreferenceValue); >+ } >+ > @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..7ae9348 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 >@@ -25,12 +25,8 @@ > > import org.eclipse.core.resources.IFile; > >-import org.eclipse.text.edits.MalformedTreeException; >-import org.eclipse.text.edits.TextEdit; >- > import org.eclipse.jface.operation.IRunnableWithProgress; > >-import org.eclipse.jface.text.BadLocationException; > import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.text.contentassist.IContextInformation; > >@@ -47,24 +43,13 @@ > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.compiler.IProblem; > import org.eclipse.jdt.core.dom.ASTNode; >-import org.eclipse.jdt.core.dom.BodyDeclaration; > import org.eclipse.jdt.core.dom.CompilationUnit; >-import org.eclipse.jdt.core.dom.IAnnotationBinding; >-import org.eclipse.jdt.core.dom.IMethodBinding; >-import org.eclipse.jdt.core.dom.ITypeBinding; > import org.eclipse.jdt.core.dom.MarkerAnnotation; >-import org.eclipse.jdt.core.dom.MethodDeclaration; > import org.eclipse.jdt.core.dom.rewrite.ImportRewrite; > >-import org.eclipse.jdt.internal.junit.BasicElementLabels; >-import org.eclipse.jdt.internal.junit.JUnitCorePlugin; >-import org.eclipse.jdt.internal.junit.Messages; > import org.eclipse.jdt.internal.junit.util.ExceptionHandler; >-import org.eclipse.jdt.internal.junit.util.JUnitStubUtility; > > import org.eclipse.jdt.ui.CodeStyleConfiguration; >-import org.eclipse.jdt.ui.ISharedImages; >-import org.eclipse.jdt.ui.JavaUI; > 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; >@@ -92,39 +77,19 @@ > > @Override > public boolean hasCorrections(ICompilationUnit unit, int problemId) { >- return problemId == IProblem.UndefinedType || problemId == IProblem.UndefinedMethod; >+ return problemId == IProblem.UndefinedType; > } > > @Override > public IJavaCompletionProposal[] getCorrections(final IInvocationContext context, IProblemLocation[] locations) { > ArrayList<IJavaCompletionProposal> res= null; > for (IProblemLocation problem : locations) { >- int id= problem.getProblemId(); >- if (IProblem.UndefinedType == id) { >- res= getAddJUnitToBuildPathProposals(context, problem, res); >- } else if (id == IProblem.UndefinedMethod) { >- res= getAddAssertImportProposals(context, problem, res); >- } >+ res= getAddJUnitToBuildPathProposals(context, problem, res); > } > if (res == null || res.isEmpty()) { > return null; > } > return res.toArray(new IJavaCompletionProposal[res.size()]); >- } >- >- private ArrayList<IJavaCompletionProposal> getAddAssertImportProposals(IInvocationContext context, IProblemLocation problem, ArrayList<IJavaCompletionProposal> proposals) { >- String[] args= problem.getProblemArguments(); >- if (args.length > 1) { >- String methodName= args[1]; >- if (ASSERT_METHOD_NAMES.contains(methodName) && isInsideJUnit4Test(context)) { >- if (proposals == null) { >- proposals= new ArrayList<>(); >- } >- proposals.add(new AddAssertProposal(context.getASTRoot(), methodName, 9)); >- proposals.add(new AddAssertProposal(context.getASTRoot(), "*", 10)); //$NON-NLS-1$ >- } >- } >- return proposals; > } > > private ArrayList<IJavaCompletionProposal> getAddJUnitToBuildPathProposals(IInvocationContext context, IProblemLocation location, ArrayList<IJavaCompletionProposal> proposals) { >@@ -189,29 +154,6 @@ > return importRewrite; > } > return null; >- } >- >- private boolean isInsideJUnit4Test(IInvocationContext context) { >- if (!JUnitStubUtility.is50OrHigher(context.getCompilationUnit().getJavaProject())) { >- return false; >- } >- >- ASTNode node= context.getCoveringNode(); >- while (node != null && !(node instanceof BodyDeclaration)) { >- node= node.getParent(); >- } >- if (node instanceof MethodDeclaration) { >- IMethodBinding binding= ((MethodDeclaration) node).resolveBinding(); >- if (binding != null) { >- IAnnotationBinding[] annotations= binding.getAnnotations(); >- for (IAnnotationBinding annotation : annotations) { >- final ITypeBinding annotationType= annotation.getAnnotationType(); >- if (annotationType != null && JUnitCorePlugin.JUNIT4_ANNOTATION_NAME.equals(annotationType.getQualifiedName())) >- return true; >- } >- } >- } >- return false; > } > > private static class JUnitClasspathFixCorrectionProposal implements IJavaCompletionProposal { >@@ -290,62 +232,6 @@ > @Override > public Image getImage() { > return fClasspathFixProposal.getImage(); >- } >- >- @Override >- public Point getSelection(IDocument document) { >- return null; >- } >- } >- >- private static class AddAssertProposal implements IJavaCompletionProposal { >- >- private final CompilationUnit fAstRoot; >- private final String fMethodName; >- private final int fRelevance; >- >- public AddAssertProposal(CompilationUnit astRoot, String methodName, int relevance) { >- fAstRoot= astRoot; >- fMethodName= methodName; >- fRelevance= relevance; >- } >- >- @Override >- public int getRelevance() { >- return fRelevance; >- } >- >- @Override >- public void apply(IDocument document) { >- try { >- ImportRewrite rewrite= CodeStyleConfiguration.createImportRewrite(fAstRoot, true); >- rewrite.addStaticImport("org.junit.Assert", fMethodName, true); //$NON-NLS-1$ >- TextEdit edit= rewrite.rewriteImports(null); >- edit.apply(document); >- } catch (MalformedTreeException e) { >- } catch (CoreException e) { >- } catch (BadLocationException e) { >- } >- } >- >- @Override >- public String getAdditionalProposalInfo() { >- return Messages.format(JUnitMessages.JUnitQuickFixProcessor_add_assert_info, BasicElementLabels.getJavaElementName("org.junit.Assert." + fMethodName)); //$NON-NLS-1$ >- } >- >- @Override >- public IContextInformation getContextInformation() { >- return null; >- } >- >- @Override >- public String getDisplayString() { >- return Messages.format(JUnitMessages.JUnitQuickFixProcessor_add_assert_description, BasicElementLabels.getJavaElementName("org.junit.Assert." + fMethodName)); //$NON-NLS-1$ >- } >- >- @Override >- public Image getImage() { >- return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_IMPDECL); > } > > @Override
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