Bug 167638 - [launching] main method search for launching returns types without main methods
Summary: [launching] main method search for launching returns types without main methods
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3 M5   Edit
Assignee: Darin Wright CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-12 09:47 EST by Michael Rennie CLA
Modified: 2007-01-05 11:26 EST (History)
1 user (show)

See Also:


Attachments
screen shot (112.29 KB, image/png)
2006-12-12 09:54 EST, Michael Rennie CLA
no flags Details
dialog (13.41 KB, patch)
2006-12-13 17:46 EST, Michael Rennie CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Rennie CLA 2006-12-12 09:47:55 EST
with the fix in for bug 163984, we have the main method search for launching showing type from our context in the type dialog, but now we see types that do not contain main methods as well.

use the Run As... menu item on the following code and you will see all of the types from below available in the type dialog, where we should only see Test Inner and Inner3.

will attach screen shot.

package a;

/**
 */
public class Test {
	static class Inner extends Object {
		/**
		 * @param args
		 */
		public static void main (String[] args) {}
	}
	
	static class Inner3 extends Inner {}
	/**
	 */
	static class Inner2 extends Object {}
	/**
	 * @param args
	 */
	public static void main(String[] args) {}
}
Comment 1 Michael Rennie CLA 2006-12-12 09:54:13 EST
Created attachment 55491 [details]
screen shot

shows the code snippet above and the resulting type dialog - notice Inner2 is there and the default selected, but it is the only type without a main method in it...
Comment 2 Michael Rennie CLA 2006-12-12 14:57:48 EST
It seems that our MainMethodSearch engine returns the correct ITypes, in this case Test, Inner, and Inner3, but when passed in as a search scope to JavaUI.createTypeDialog(...) all of the child types of Test are shown as well.

There should be some way to specify whether or not to show all child types of a specified type passed in to the dialog.

sending to JDT Core for comment
Comment 3 Frederic Fusier CLA 2006-12-13 09:30:22 EST
This is not a SearchEngine issue, neither while search main method declarations nor while searching for all types.

Problem seems to come from MainMethodeSearchEngine in org.eclipse.jdt.internal.debug.ui.launcher.
Method searchMainMethods(IProgressMonitor, IJavaSearchScope, boolean), there's a call to addSubTypes(List, IProgressMonitor, IJavaSearchScope) method if includesSubtypes flag is ON. This method add all types sub-types as soon as the given scope encloses them without testing if sub-types have a main method!

This explain why all sub-types are added in the given test case
=> move (back) to JDT/Debug to fix this issue...
Comment 4 Frederic Fusier CLA 2006-12-13 11:38:26 EST
(In reply to comment #2)
> It seems that our MainMethodSearch engine returns the correct ITypes, in this
> case Test, Inner, and Inner3, but when passed in as a search scope to
> JavaUI.createTypeDialog(...) all of the child types of Test are shown as well.
> 
> There should be some way to specify whether or not to show all child types of a
> specified type passed in to the dialog.
> 
> sending to JDT Core for comment
> 
Sorry, Michael, I missed this comment due to wrong notification order from Bugzilla :-(

In fact you're right, your MainMethodSearchEngine found the correct types....

The problem here is that your use an OpenType dialog after with a scope which includes top level type 'Test' => this scope will enclose _all_ its sub-types without any possible restriction!

So, the question is why do you use this kind of dialog instead of a specific one?

IMO, the best solution would be to write a specific dialog MainMethodSelectionDialog inheriting from ElementListSelectionDialog with elements initialized using MainMethodSearchEngine...
Comment 5 Michael Rennie CLA 2006-12-13 11:51:09 EST
Frederic, instead of us making our own dialog, could you guys add in some API that would allow users of the OpenType dialog to specify whether to include all subtypes of a type passed to the dialog? Something as simple as new flag perhaps indicating whether to include all subtypes?

It seems that we would have to copy a pile of code to mimic the OpenType but with one minor change....
Comment 6 Frederic Fusier CLA 2006-12-13 12:44:46 EST
(In reply to comment #5)
> Frederic, instead of us making our own dialog, could you guys add in some API
> that would allow users of the OpenType dialog to specify whether to include all
> subtypes of a type passed to the dialog? Something as simple as new flag
> perhaps indicating whether to include all subtypes?
> 
This would really not be so simple... Modify IJavaSearchScope API is not possible as this is an implementable interface => clients would be broken!

> It seems that we would have to copy a pile of code to mimic the OpenType but
> with one minor change....
> 
I really do not understand why you want to mimic OpenType dialog, it does stuff you really do not need. The main functionality of this dialog is to search type from a given pattern (using searchAllTypeNames). But in your case you already have the types before opening the dialog. What you just need is to select one of them...

With a specific dialog, I guess you should not have too much code...
I would say something similar than org.eclipse.jdt.internal.junit.ui.TestMethodSelectionDialog
Comment 7 Michael Rennie CLA 2006-12-13 17:46:34 EST
Created attachment 55619 [details]
dialog

here is an implemetation of a MainMethodSelectionDialog, with label provider MainMethodLabelProvider, and changes to JavaMainTab and JavaLaunchShortcut
Comment 8 Darin Wright CLA 2006-12-19 12:00:57 EST
The open type dialog is designed to perform searching on a scope. Suggestion is to investigate the use of a FilteredItemsSelectionDialog that is similar to the open type dialog, since our search is already complete.
Comment 9 Michael Rennie CLA 2007-01-02 15:35:03 EST
fixed in HEAD

see MainMethodSelectionDialog
Comment 10 Michael Rennie CLA 2007-01-02 15:36:02 EST
please verify Darin W
Comment 11 Darin Wright CLA 2007-01-05 11:26:54 EST
Verified.