misc
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / example / outline / Type2Console.java
1 package net.sourceforge.example.outline;
2
3
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.*;
10
11 public class Type2Console implements IObjectActionDelegate {
12     private IWorkbenchPartSite myPartSite = null;
13
14     private IWorkspace myWorkspace = null;
15
16     private IWorkbenchPart myWorkbenchPart = null;
17
18     private IType myType = null;
19
20     private Shell myShell = new Shell(); // TBReplaced with getShell()
21
22     public Type2Console() {
23     }
24
25     /**
26      * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
27      */
28     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
29         myWorkspace = ResourcesPlugin.getWorkspace();
30         myWorkbenchPart = targetPart;
31     }
32
33     /**
34      * @see IActionDelegate#run(IAction)
35      */
36     public void run(IAction action) {
37         try {
38
39             String actionId = action.getId();
40             showSourceInConsole(actionId);
41
42         } catch (Exception e) {
43             e.printStackTrace();
44         }
45     }
46
47     /**
48      * @see IActionDelegate#selectionChanged(IAction, ISelection)
49      */
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
55         }
56     }
57
58     private void showSourceInConsole(String actionId) throws Exception {
59         if (!(myType.isInterface() || myType.isClass())) {
60             throw new Exception("incompatible Type");
61         }
62
63         IMethod[] methods = myType.getMethods();
64
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());
70         }
71
72     }
73
74 }