メインクラスを探す その 3

面倒くさいので、handleSearchButtonSelected メソッドをそのままコピー & ペーストで CreateJarDialog クラスに持ってきてしまいました。

もちろん、そのままだとコンパイルエラーが出てしまいます。

javaProject がないというエラーにはすぐに対処できるのですが、よく分からないのが次の部分。

        MainMethodSearchEngine engine = new MainMethodSearchEngine();

        IType[] types = null;
        try {
            types = engine.searchMainMethods(getLaunchConfigurationDialog(), searchScope, fConsiderInheritedMainButton.getSelection());
        } catch (InvocationTargetException e) {
            setErrorMessage(e.getMessage());
            return;
        } catch (InterruptedException e) {
            setErrorMessage(e.getMessage());
            return;
        }


JavaMainTab クラスの getLaunchConfigurationDialog メソッドは、単にフィールドで保持している ILaunchConfigurationDialog オブジェクトを返すというものです。でも、これをセットしているがどこだか分からないのです。それに、こんなオブジェクトを使う意味がよく分からないし ^^;;

だいたい、MainMethodSearchEngine クラスもインターナルなんですよね。

しかたないので、MainMethodSearchEngine クラスのコードを見てみると、ILaunchConfigurationDialog インタフェースではなくて、その親インタフェースの IRunnableContext インタフェースが引数になっていました。

で、ようするにプログレスを示すために IRunnableContext オブジェクトが必要であることがなんとなく分かりました。

	public IType[] searchMainMethods(IRunnableContext context, final IJavaSearchScope scope, final boolean includeSubtypes) throws InvocationTargetException, InterruptedException  {		
		final IType[][] res= new IType[1][];
		
		IRunnableWithProgress runnable= new IRunnableWithProgress() {
			public void run(IProgressMonitor pm) throws InvocationTargetException {
				res[0]= searchMainMethods(pm, scope, includeSubtypes);
			}
		};
		context.run(true, true, runnable);
		
		return res[0];
	}

しかし、どうやれば IRunnableContext オブジェクトを作れるのか?

IRunnableContext インタフェースをインプリメントしたクラスとしては、ApplicationWindow, ProgressMonitorDialog, WizardDialog クラスがあります。しかし、単なる Dialog クラスはなし... orz

って、当たり前か。