1 19 20 package org.netbeans.modules.debugger.jpda.ui.actions; 21 22 import com.sun.jdi.AbsentInformationException; 23 import com.sun.jdi.ThreadReference; 24 25 import java.util.Collections ; 26 import java.util.Set ; 27 import javax.swing.SwingUtilities ; 28 import org.netbeans.api.debugger.ActionsManager; 29 30 31 import org.netbeans.api.debugger.DebuggerManager; 32 import org.netbeans.spi.debugger.ContextProvider; 33 import org.netbeans.api.debugger.jpda.CallStackFrame; 34 import org.netbeans.api.debugger.jpda.JPDADebugger; 35 import org.netbeans.api.debugger.jpda.JPDAThread; 36 37 import org.netbeans.modules.debugger.jpda.ui.SourcePath; 38 39 40 45 public class MakeCallerCurrentActionProvider extends JPDADebuggerAction { 46 47 private ContextProvider lookupProvider; 48 49 50 public MakeCallerCurrentActionProvider (ContextProvider lookupProvider) { 51 super ( 52 (JPDADebugger) lookupProvider.lookupFirst 53 (null, JPDADebugger.class) 54 ); 55 this.lookupProvider = lookupProvider; 56 getDebuggerImpl ().addPropertyChangeListener 57 (JPDADebugger.PROP_CURRENT_CALL_STACK_FRAME, this); 58 } 59 60 public Set getActions () { 61 return Collections.singleton (ActionsManager.ACTION_MAKE_CALLER_CURRENT); 62 } 63 64 public void doAction (Object action) { 65 JPDAThread t = getDebuggerImpl ().getCurrentThread (); 66 if (t == null) return; 67 int i = getCurrentCallStackFrameIndex (getDebuggerImpl ()); 68 if (i >= (t.getStackDepth () - 1)) return; 69 setCurrentCallStackFrameIndex (getDebuggerImpl (), ++i, lookupProvider); 70 } 71 72 protected void checkEnabled (int debuggerState) { 73 if (debuggerState == getDebuggerImpl ().STATE_STOPPED) { 74 JPDAThread t = getDebuggerImpl ().getCurrentThread (); 75 if (t != null) { 76 int i = getCurrentCallStackFrameIndex (getDebuggerImpl ()); 77 setEnabled ( 78 ActionsManager.ACTION_MAKE_CALLER_CURRENT, 79 i < (t.getStackDepth () - 1) 80 ); 81 return; 82 } 83 } 84 setEnabled ( 85 ActionsManager.ACTION_MAKE_CALLER_CURRENT, 86 false 87 ); 88 } 89 90 static int getCurrentCallStackFrameIndex (JPDADebugger debuggerImpl) { 91 try { 92 JPDAThread t = debuggerImpl.getCurrentThread (); 93 if (t == null) return -1; 94 CallStackFrame csf = debuggerImpl.getCurrentCallStackFrame (); 95 if (csf == null) return -1; 96 CallStackFrame s[] = t.getCallStack (); 97 int i, k = s.length; 98 for (i = 0; i < k; i++) 99 if (csf.equals (s [i])) return i; 100 } catch (AbsentInformationException e) { 101 } 102 return -1; 103 } 104 105 static void setCurrentCallStackFrameIndex ( 106 JPDADebugger debuggerImpl, 107 int index, 108 final ContextProvider lookupProvider 109 ) { 110 try { 111 JPDAThread t = debuggerImpl.getCurrentThread (); 112 if (t == null) return; 113 if (t.getStackDepth () <= index) return; 114 final CallStackFrame csf = t.getCallStack (index, index + 1) [0]; 115 csf.makeCurrent (); 116 } catch (AbsentInformationException e) { 117 } 118 } 119 } 120 | Popular Tags |