1 package net.sourceforge.example.outline;
4 import org.eclipse.core.resources.*;
5 import net.sourceforge.phpdt.core.*;
6 import org.eclipse.jface.action.*;
7 import org.eclipse.jface.viewers.*;
8 import org.eclipse.swt.widgets.*;
9 import org.eclipse.ui.*;
11 public class Type2Console implements IObjectActionDelegate {
12 private IWorkbenchPartSite myPartSite = null;
14 private IWorkspace myWorkspace = null;
16 private IWorkbenchPart myWorkbenchPart = null;
18 private IType myType = null;
20 private Shell myShell = new Shell(); // TBReplaced with getShell()
22 public Type2Console() {
26 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
28 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
29 myWorkspace = ResourcesPlugin.getWorkspace();
30 myWorkbenchPart = targetPart;
34 * @see IActionDelegate#run(IAction)
36 public void run(IAction action) {
39 String actionId = action.getId();
40 showSourceInConsole(actionId);
42 } catch (Exception e) {
48 * @see IActionDelegate#selectionChanged(IAction, ISelection)
50 public void selectionChanged(IAction action, ISelection selection) {
51 if (selection instanceof IStructuredSelection) {
52 Object item = ((IStructuredSelection) selection).getFirstElement();
53 myType = (IType) item; // this plugin only reacts to
54 // "org.eclipse.jdt.core.IType" objects
58 private void showSourceInConsole(String actionId) throws Exception {
59 if (!(myType.isInterface() || myType.isClass())) {
60 throw new Exception("incompatible Type");
63 IMethod[] methods = myType.getMethods();
65 String fqname = myType.getFullyQualifiedName(); // a.b.c.d.MyClass
66 System.out.println(fqname + '\n');
67 for (int i = 0; i < methods.length; i++) {
68 System.out.println("Method " + i + ":"
69 + methods[i].getElementName());