1111import org .eclipse .jdt .core .IMethod ;
1212import org .eclipse .jdt .core .IType ;
1313import org .eclipse .jdt .core .JavaCore ;
14+ import org .eclipse .swt .widgets .Display ;
1415import org .eclipse .ui .IEditorPart ;
1516import org .moreunit .core .util .StringConstants ;
1617import org .moreunit .elements .CorrespondingMemberRequest .MemberType ;
@@ -81,7 +82,7 @@ private TypeFacade(IFile file)
8182
8283 protected TypeFacade (IEditorPart editorPart )
8384 {
84- this (( IFile ) editorPart .getEditorInput ().getAdapter (IFile .class ));
85+ this (editorPart .getEditorInput ().getAdapter (IFile .class ));
8586 }
8687
8788 public IType getType ()
@@ -103,7 +104,7 @@ public ICompilationUnit getCompilationUnit()
103104 * to make a choice via a dialog. If no member is found <tt>null</tt> is
104105 * returned, or a wizard opens to create a new type if
105106 * <tt>createIfNecessary</tt> is true.
106- *
107+ *
107108 * @param request the details of the request for corresponding member.
108109 * @return one corresponding member or <code>null</code>
109110 * @see CorrespondingMemberRequest
@@ -165,7 +166,7 @@ else if(request.shouldCreateClassIfNoResult())
165166
166167 private Collection <IMethod > findCorrespondingMethodsInClasses (CorrespondingMemberRequest request , Collection <IType > classes )
167168 {
168- Collection <IMethod > proposedMethods = new LinkedHashSet <IMethod >();
169+ Collection <IMethod > proposedMethods = new LinkedHashSet <>();
169170
170171 if (request .shouldReturn (MemberType .TYPE_OR_METHOD ))
171172 {
@@ -200,40 +201,16 @@ else if(request.shouldCreateClassIfNoResult())
200201 return null ;
201202 }
202203
203- abstract protected Collection <IMethod > getCorrespondingMethodsInClasses (IMethod method , Collection <IType > classes );
204+ protected abstract Collection <IMethod > getCorrespondingMethodsInClasses (IMethod method , Collection <IType > classes );
204205
205206 public final Collection <IType > getCorrespondingClasses (boolean alsoIncludeLikelyMatches )
206207 {
207208 return getCorrespondingTypeSearcher ().getMatches (alsoIncludeLikelyMatches );
208209 }
209210
210- abstract protected MethodCallFinder getCallRelationshipFinder (IMethod method , Collection <IType > searchScope );
211+ protected abstract MethodCallFinder getCallRelationshipFinder (IMethod method , Collection <IType > searchScope );
211212
212- abstract protected NewClassyWizard newCorrespondingClassWizard (IType fromType );
213-
214- private IMember openDialog (CorrespondingMemberRequest request , Collection <IType > proposedClasses , Collection <IMethod > proposedMethods , boolean perfectMatches )
215- {
216- String promptText = request .getPromptText ();
217- String infoText = null ;
218- if (! perfectMatches )
219- {
220- promptText = String .format ("%s %s%s" , promptText , StringConstants .NEWLINE , "We could find the following classes, but their packages do not match:" );
221- infoText = "Please note that theses classes will not be considered for other MoreUnit features such as test launching or refactoring." ;
222- }
223-
224- IMember startMember = request .getCurrentMethod () != null ? request .getCurrentMethod () : getType ();
225- IMember defaultSelection = getDefaultSelection (proposedClasses , proposedMethods , startMember );
226- MemberContentProvider contentProvider = new MemberContentProvider (proposedClasses , proposedMethods , defaultSelection ).withAction (new CreateNewClassAction ()
227- {
228- @ Override
229- public IType execute ()
230- {
231- return newCorrespondingClassWizard (getType ()).open ();
232- }
233- });
234-
235- return new ChooseDialog <IMember >(promptText , infoText , contentProvider ).getChoice ();
236- }
213+ protected abstract NewClassyWizard newCorrespondingClassWizard (IType fromType );
237214
238215 private IMember getDefaultSelection (Collection <IType > proposedClasses , Collection <IMethod > proposedMethods , IMember startMember )
239216 {
@@ -311,13 +288,39 @@ public IMember getCorrespondingMember()
311288 {
312289 return openDialog (request , proposedClasses , proposedMethods , perfectMatches );
313290 }
291+
292+ private IMember openDialog (CorrespondingMemberRequest request , Collection <IType > proposedClasses , Collection <IMethod > proposedMethods , boolean perfectMatches )
293+ {
294+ String promptText = request .getPromptText ();
295+ String infoText = null ;
296+ if (! perfectMatches )
297+ {
298+ promptText = String .format ("%s %s%s" , promptText , StringConstants .NEWLINE , "We could find the following classes, but their packages do not match:" );
299+ infoText = "Please note that theses classes will not be considered for other MoreUnit features such as test launching or refactoring." ;
300+ }
301+
302+ IMember startMember = request .getCurrentMethod () != null ? request .getCurrentMethod () : getType ();
303+ IMember defaultSelection = getDefaultSelection (proposedClasses , proposedMethods , startMember );
304+ MemberContentProvider contentProvider = new MemberContentProvider (proposedClasses , proposedMethods , defaultSelection ).withAction (new CreateNewClassAction ()
305+ {
306+ @ Override
307+ public IType execute ()
308+ {
309+ return newCorrespondingClassWizard (getType ()).open ();
310+ }
311+ });
312+
313+ String finalPromptTest = promptText ;
314+ String finalInfoText = infoText ;
315+ return Display .getDefault ().syncCall (() -> new ChooseDialog <IMember >(finalPromptTest , finalInfoText , contentProvider ).getChoice ());
316+ }
314317 }
315318
316319 private class OpenNewClassWizard implements OneCorrespondingMemberAction
317320 {
318321 public IMember getCorrespondingMember ()
319322 {
320- return newCorrespondingClassWizard (getType ()).open ();
323+ return Display . getDefault (). syncCall (() -> newCorrespondingClassWizard (getType ()).open () );
321324 }
322325 }
323326}
0 commit comments