KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > ForceReturnAction


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.actions;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.debug.core.DebugException;
15 import org.eclipse.debug.ui.InspectPopupDialog;
16 import org.eclipse.jdt.core.Signature;
17 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
18 import org.eclipse.jdt.debug.core.IJavaStackFrame;
19 import org.eclipse.jdt.debug.core.IJavaValue;
20 import org.eclipse.jdt.debug.eval.IEvaluationResult;
21 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
22 import org.eclipse.jdt.internal.debug.ui.display.JavaInspectExpression;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 /**
27  * Action for force return from a method.
28  *
29  * @since 3.3
30  */

31 public class ForceReturnAction extends EvaluateAction {
32     
33     private IJavaStackFrame fTargetFrame = null;
34
35     /* (non-Javadoc)
36      * @see org.eclipse.jdt.internal.debug.ui.actions.EvaluateAction#displayResult(org.eclipse.jdt.debug.eval.IEvaluationResult)
37      */

38     protected void displayResult(final IEvaluationResult result) {
39         evaluationCleanup();
40         
41         final Display display = JDIDebugUIPlugin.getStandardDisplay();
42         // error with evaluation
43
if (result.hasErrors()) {
44             display.asyncExec(new Runnable JavaDoc() {
45                 public void run() {
46                     if (display.isDisposed()) {
47                         return;
48                     }
49                     reportErrors(result);
50                 }
51             });
52             return;
53         }
54
55         // force return with the result
56
try {
57             IJavaStackFrame frame = fTargetFrame;
58             IJavaValue value = result.getValue();
59             frame.forceReturn(value);
60             if (!Signature.SIG_VOID.equals(value)) {
61                 display.asyncExec(new Runnable JavaDoc() {
62                     public void run() {
63                         if (display.isDisposed()) {
64                             return;
65                         }
66                         IWorkbenchPart part = getTargetPart();
67                         InspectPopupDialog dialog = new InspectPopupDialog(getShell(), getPopupAnchor(getStyledText(part)), null, new JavaInspectExpression(result));
68                         dialog.open();
69                     }
70                 });
71             }
72         } catch (DebugException e) {
73             final IStatus status = e.getStatus();
74             display.asyncExec(new Runnable JavaDoc() {
75                 public void run() {
76                     if (display.isDisposed()) {
77                         return;
78                     }
79                     JDIDebugUIPlugin.statusDialog(status);
80                 }
81             });
82         }
83     }
84
85     protected void run() {
86         IJavaStackFrame stackFrame= getStackFrameContext();
87         if (stackFrame != null) {
88             try {
89                 String JavaDoc returnType = Signature.getReturnType(stackFrame.getSignature());
90                 if (Signature.SIG_VOID.equals(returnType)) {
91                     // no evaluation required for void methods
92
stackFrame.forceReturn(((IJavaDebugTarget)stackFrame.getDebugTarget()).voidValue());
93                     return;
94                 }
95             } catch (DebugException e) {
96                 JDIDebugUIPlugin.statusDialog(e.getStatus());
97                 return;
98             }
99         }
100         fTargetFrame = stackFrame;
101         // perform evaluation otherwise
102
super.run();
103     }
104     
105     
106     
107     
108
109 }
110
Popular Tags