違うPluginのクラスメソッドを呼ぶための簡単な方法
なるほどね。継承しちゃえばいいのか。
Quick JUnit - Quick PDE JUnit - junit.extensions.eclipse.quick.pde.ExtensionSupport
package junit.extensions.eclipse.quick.pde; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.ui.ILaunchShortcut; public class ExtensionSupport extends junit.extensions.eclipse.quick.ExtensionSupport { public static ILaunchShortcut createJUnitWorkbenchShortcut() throws CoreException { return createLaunchShortcut("org.eclipse.pde.ui"); //$NON-NLS-1$ } }
Quick JUnit - Quick JUnit - junit.extensions.eclipse.quick.ExtensionSupport
package junit.extensions.eclipse.quick; ... public class ExtensionSupport { ... protected static ILaunchShortcut createLaunchShortcut(final String namespace) throws CoreException { final IExtensionRegistry reg = Platform.getExtensionRegistry(); final IExtensionPoint point = reg.getExtensionPoint("org.eclipse.debug.ui.launchShortcuts"); //$NON-NLS-1$ final IExtension[] extensions = point.getExtensions(); for (int i = 0; i < extensions.length; ++i) { if (namespace.equals(extensions[i].getNamespaceIdentifier())) { final IConfigurationElement[] elements = extensions[i].getConfigurationElements(); ILaunchShortcut shortcut = (ILaunchShortcut) elements[0] .createExecutableExtension("class"); //$NON-NLS-1$ if (shortcut != null) { return shortcut; } } } throw new RuntimeException("LaunchShortcut not found. namespace:" + namespace); //$NON-NLS-1$ } ... }
継承しちゃえば子クラスのクラスローダーから親クラスのクラスローダーに処理を委譲するのは可能なのね。普通にクラスメソッド*1として呼び出そうとすると、呼び出し側のクラスローダーにそのクラスがある訳ではないので、ClassNotFoundExceptionが投げられる気ガス。というか、僕はそれで結構悩まされてBuddy-Policyを学んだけれども。
*1:static修飾子のついてるメソッドのこと。静的メソッドとか色々呼ばれますが、クラスメソッドが一番意を表している気がする。