1 19 20 package org.netbeans.modules.debugger.jpda.actions; 21 22 import com.sun.jdi.AbsentInformationException; 23 import java.util.Collections ; 24 import java.util.Set ; 25 import org.netbeans.api.debugger.ActionsManager; 26 27 import org.netbeans.spi.debugger.ContextProvider; 28 import org.netbeans.api.debugger.jpda.JPDADebugger; 29 import org.netbeans.api.debugger.jpda.JPDAThread; 30 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 31 32 33 38 public class PopToHereActionProvider extends JPDADebuggerActionProvider { 39 40 private ContextProvider lookupProvider; 41 42 43 public PopToHereActionProvider (ContextProvider lookupProvider) { 44 super ( 45 (JPDADebuggerImpl) lookupProvider.lookupFirst 46 (null, JPDADebugger.class) 47 ); 48 this.lookupProvider = lookupProvider; 49 setProviderToDisableOnLazyAction(this); 50 } 51 52 public Set getActions () { 53 return Collections.singleton (ActionsManager.ACTION_POP_TOPMOST_CALL); 54 } 55 56 public void doAction (Object action) { 57 runAction(); 58 } 59 60 public void postAction(Object action, final Runnable actionPerformedNotifier) { 61 doLazyAction(new Runnable () { 62 public void run() { 63 try { 64 runAction(); 65 } finally { 66 actionPerformedNotifier.run(); 67 } 68 } 69 }); 70 } 71 72 public void runAction() { 73 try { 74 JPDAThread t = getDebuggerImpl ().getCurrentThread (); 75 t.getCallStack (0, 1) [0].popFrame (); 76 } catch (AbsentInformationException ex) { 77 } 78 } 79 80 protected void checkEnabled (int debuggerState) { 81 if (!getDebuggerImpl().canPopFrames()) { 82 setEnabled ( 83 ActionsManager.ACTION_POP_TOPMOST_CALL, 84 false 85 ); 86 return; 87 } 88 synchronized (getDebuggerImpl().LOCK) { 89 if (debuggerState == getDebuggerImpl ().STATE_STOPPED) { 90 JPDAThread t = getDebuggerImpl ().getCurrentThread (); 91 if (t == null) { 92 setEnabled ( 93 ActionsManager.ACTION_POP_TOPMOST_CALL, 94 false 95 ); 96 return; 97 } 98 synchronized (t) { 99 if (!t.isSuspended()) { 100 setEnabled ( 101 ActionsManager.ACTION_POP_TOPMOST_CALL, 102 false 103 ); 104 } else { 105 setEnabled ( 106 ActionsManager.ACTION_POP_TOPMOST_CALL, 107 t.getStackDepth () > 1 108 ); 109 } 110 } 111 return; 112 } 113 setEnabled ( 114 ActionsManager.ACTION_POP_TOPMOST_CALL, 115 false 116 ); 117 } 118 } 119 } 120 | Popular Tags |