1 11 package org.eclipse.debug.internal.core.commands; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IAdaptable; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.debug.core.IRequest; 20 import org.eclipse.debug.core.commands.IEnabledStateRequest; 21 import org.eclipse.debug.core.model.IStackFrame; 22 import org.eclipse.debug.core.model.IStep; 23 24 29 public abstract class StepCommand extends DebugCommand { 30 31 protected void doExecute(Object [] targets, IProgressMonitor monitor, IRequest request) throws CoreException { 32 for (int i = 0; i < targets.length; i++) { 33 step(targets[i]); 34 } 35 } 36 37 protected abstract void step(Object target) throws CoreException ; 38 39 protected boolean isExecutable(Object [] targets, IProgressMonitor monitor, IEnabledStateRequest collector) throws CoreException { 40 if (isThreadCompatible(targets)) { 41 for (int i = 0; i < targets.length; i++) { 42 if (!isSteppable(targets[i])) { 43 return false; 44 } 45 } 46 return true; 47 } else { 48 return false; 49 } 50 } 51 52 protected abstract boolean isSteppable(Object target) throws CoreException; 53 54 protected boolean isThreadCompatible(Object [] targets) { 55 if (targets.length == 1) { 56 return true; 57 } 58 Set threads = new HashSet (targets.length); 60 for (int i = 0; i < targets.length; i++) { 61 Object object = targets[i]; 62 IStackFrame frame = null; 63 if (object instanceof IStackFrame) { 64 frame = (IStackFrame) object; 65 } else if (object instanceof IAdaptable) { 66 frame = (IStackFrame)((IAdaptable)object).getAdapter(IStackFrame.class); 67 } 68 if (frame != null) { 69 if (!threads.add(frame.getThread())) { 70 return false; 71 } 72 } 73 } 74 return true; 75 } 76 77 protected Object getTarget(Object element) { 78 if (element instanceof IStep) { 79 return element; 80 } else if (element instanceof IAdaptable) { 81 return ((IAdaptable) element).getAdapter(IStep.class); 82 } 83 return null; 84 } 85 86 } 87 | Popular Tags |