1 11 package org.eclipse.jdt.internal.debug.core.breakpoints; 12 13 14 import java.util.Map ; 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.IWorkspaceRunnable; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.jdt.debug.core.IJavaMethodEntryBreakpoint; 21 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 22 import com.sun.jdi.ClassType; 23 import com.sun.jdi.Location; 24 import com.sun.jdi.Method; 25 import com.sun.jdi.ReferenceType; 26 import com.sun.jdi.request.BreakpointRequest; 27 import com.sun.jdi.request.EventRequest; 28 29 32 33 public class JavaMethodEntryBreakpoint extends JavaLineBreakpoint implements IJavaMethodEntryBreakpoint { 34 35 private static final String JAVA_METHOD_ENTRY_BREAKPOINT = "org.eclipse.jdt.debug.javaMethodEntryBreakpointMarker"; 37 42 private static final String METHOD_NAME = "org.eclipse.jdt.debug.core.methodName"; 44 49 private static final String METHOD_SIGNATURE = "org.eclipse.jdt.debug.core.methodSignature"; 51 54 private String fMethodName = null; 55 56 59 private String fMethodSignature = null; 60 61 64 public JavaMethodEntryBreakpoint() { 65 } 66 67 public JavaMethodEntryBreakpoint(final IResource resource, final String typeName, final String methodName, final String methodSignature, final int lineNumber, final int charStart, final int charEnd, final int hitCount, final boolean register, final Map attributes) throws CoreException { 68 IWorkspaceRunnable wr= new IWorkspaceRunnable() { 69 public void run(IProgressMonitor monitor) throws CoreException { 70 setMarker(resource.createMarker(JAVA_METHOD_ENTRY_BREAKPOINT)); 72 73 addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd); 75 addMethodNameAndSignature(attributes, methodName, methodSignature); 76 addTypeNameAndHitCount(attributes, typeName, hitCount); 77 attributes.put(SUSPEND_POLICY, new Integer (getDefaultSuspendPolicy())); 79 ensureMarker().setAttributes(attributes); 80 81 register(register); 82 } 83 84 }; 85 run(getMarkerRule(resource), wr); 86 } 87 88 93 private void addMethodNameAndSignature(Map attributes, String methodName, String methodSignature) { 94 if (methodName != null) { 95 attributes.put(METHOD_NAME, methodName); 96 } 97 if (methodSignature != null) { 98 attributes.put(METHOD_SIGNATURE, methodSignature); 99 } 100 fMethodName= methodName; 101 fMethodSignature= methodSignature; 102 } 103 104 107 public String getMethodName() { 108 return fMethodName; 109 } 110 111 114 public String getMethodSignature() { 115 return fMethodSignature; 116 } 117 118 123 public void setMarker(IMarker marker) throws CoreException { 124 super.setMarker(marker); 125 fMethodName = marker.getAttribute(METHOD_NAME, null); 126 fMethodSignature = marker.getAttribute(METHOD_SIGNATURE, null); 127 } 128 129 132 public boolean supportsCondition() { 133 return false; 134 } 135 136 139 protected EventRequest[] newRequests(JDIDebugTarget target, ReferenceType type) throws CoreException { 140 try { 141 if (type instanceof ClassType) { 142 ClassType clazz = (ClassType)type; 143 Method method = clazz.concreteMethodByName(getMethodName(), getMethodSignature()); 144 if (method == null) { 145 return null; 146 } 147 Location location = method.location(); 148 if (location == null || location.codeIndex() == -1) { 149 return null; 150 } 151 BreakpointRequest req = type.virtualMachine().eventRequestManager().createBreakpointRequest(location); 152 configureRequest(req, target); 153 return new EventRequest[]{req}; 154 } 155 return null; 156 } catch (RuntimeException e) { 157 target.internalError(e); 158 return null; 159 } 160 } 161 } 162 | Popular Tags |