Deleted unused commenst and unused vars.
[phpeclipse.git] / net.sourceforge.phpeclipse.tests / src / net / sourceforge / phpeclipse / example / outline / Type2Console.java
1 package net.sourceforge.phpeclipse.example.outline;
2
3 import net.sourceforge.phpdt.core.IMethod;
4 import net.sourceforge.phpdt.core.IType;
5
6 import org.eclipse.core.resources.IWorkspace;
7 import org.eclipse.core.resources.ResourcesPlugin;
8 import org.eclipse.jface.action.IAction;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.jface.viewers.IStructuredSelection;
11 import org.eclipse.swt.widgets.Shell;
12 import org.eclipse.ui.IActionDelegate;
13 import org.eclipse.ui.IObjectActionDelegate;
14 import org.eclipse.ui.IWorkbenchPart;
15 import org.eclipse.ui.IWorkbenchPartSite;
16
17 public class Type2Console implements IObjectActionDelegate {
18         private IWorkbenchPartSite myPartSite = null;
19
20         private IWorkspace myWorkspace = null;
21
22         private IWorkbenchPart myWorkbenchPart = null;
23
24         private IType myType = null;
25
26         private Shell myShell = new Shell(); // TBReplaced with getShell()
27
28         public Type2Console() {
29         }
30
31         /**
32          * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
33          */
34         public void setActivePart(IAction action, IWorkbenchPart targetPart) {
35                 myWorkspace = ResourcesPlugin.getWorkspace();
36                 myWorkbenchPart = targetPart;
37         }
38
39         /**
40          * @see IActionDelegate#run(IAction)
41          */
42         public void run(IAction action) {
43                 try {
44
45                         String actionId = action.getId();
46                         showSourceInConsole(actionId);
47
48                 } catch (Exception e) {
49                         e.printStackTrace();
50                 }
51         }
52
53         /**
54          * @see IActionDelegate#selectionChanged(IAction, ISelection)
55          */
56         public void selectionChanged(IAction action, ISelection selection) {
57                 if (selection instanceof IStructuredSelection) {
58                         Object item = ((IStructuredSelection) selection).getFirstElement();
59                         myType = (IType) item; // this plugin only reacts to
60                         // "org.eclipse.jdt.core.IType" objects
61                 }
62         }
63
64         private void showSourceInConsole(String actionId) throws Exception {
65                 System.out.println(actionId);
66                 if (!(myType.isInterface() || myType.isClass())) {
67                         throw new Exception("incompatible Type");
68                 }
69
70                 IMethod[] methods = myType.getMethods();
71
72                 String fqname = myType.getFullyQualifiedName(); // a.b.c.d.MyClass
73                 System.out.println(fqname + '\n');
74                 for (int i = 0; i < methods.length; i++) {
75                         System.out.println("Method " + i + ":"
76                                         + methods[i].getElementName());
77                 }
78
79         }
80
81 }