1 11 package org.eclipse.jdt.internal.debug.core.breakpoints; 12 13 import java.util.Map ; 14 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.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.debug.core.DebugException; 23 import org.eclipse.debug.core.model.IBreakpoint; 24 import org.eclipse.jdt.debug.core.IJavaClassPrepareBreakpoint; 25 import org.eclipse.jdt.debug.core.IJavaObject; 26 import org.eclipse.jdt.debug.core.IJavaThread; 27 import org.eclipse.jdt.debug.core.JDIDebugModel; 28 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 29 import org.eclipse.jdt.internal.debug.core.model.JDIThread; 30 31 import com.sun.jdi.ObjectReference; 32 import com.sun.jdi.ReferenceType; 33 import com.sun.jdi.ThreadReference; 34 import com.sun.jdi.event.ClassPrepareEvent; 35 import com.sun.jdi.request.ClassPrepareRequest; 36 import com.sun.jdi.request.EventRequest; 37 38 43 public class JavaClassPrepareBreakpoint extends JavaBreakpoint implements IJavaClassPrepareBreakpoint { 44 45 private static final String JAVA_CLASS_PREPARE_BREAKPOINT= "org.eclipse.jdt.debug.javaClassPrepareBreakpointMarker"; 47 53 protected static final String MEMBER_TYPE = "org.eclipse.jdt.debug.core.memberType"; 55 72 public JavaClassPrepareBreakpoint(final IResource resource, final String typeName, final int memberType, final int charStart, final int charEnd, final boolean add, final Map attributes) throws DebugException { 73 IWorkspaceRunnable wr= new IWorkspaceRunnable() { 74 75 public void run(IProgressMonitor monitor) throws CoreException { 76 setMarker(resource.createMarker(JAVA_CLASS_PREPARE_BREAKPOINT)); 78 79 attributes.put(IBreakpoint.ID, getModelIdentifier()); 81 attributes.put(IMarker.CHAR_START, new Integer (charStart)); 82 attributes.put(IMarker.CHAR_END, new Integer (charEnd)); 83 attributes.put(TYPE_NAME, typeName); 84 attributes.put(MEMBER_TYPE, new Integer (memberType)); 85 attributes.put(ENABLED, Boolean.TRUE); 86 attributes.put(SUSPEND_POLICY, new Integer (getDefaultSuspendPolicy())); 87 88 ensureMarker().setAttributes(attributes); 89 90 register(add); 91 } 92 93 }; 94 run(getMarkerRule(resource), wr); 95 } 96 97 public JavaClassPrepareBreakpoint() { 98 } 99 100 103 protected void createRequests(JDIDebugTarget target) throws CoreException { 104 if (target.isTerminated() || shouldSkipBreakpoint()) { 105 return; 106 } 107 String referenceTypeName= getTypeName(); 108 if (referenceTypeName == null) { 109 return; 110 } 111 112 ClassPrepareRequest request = target.createClassPrepareRequest(referenceTypeName, null, false); 113 configureRequestHitCount(request); 114 updateEnabledState(request, target); 115 registerRequest(request, target); 116 incrementInstallCount(); 118 } 119 120 125 protected void deregisterRequest(EventRequest request, JDIDebugTarget target) throws CoreException { 126 target.removeJDIEventListener(this, request); 127 if (getMarker().exists()) { 132 decrementInstallCount(); 133 } 134 } 135 136 142 protected void addInstanceFilter(EventRequest request, ObjectReference object) { 143 } 144 150 protected EventRequest[] newRequests(JDIDebugTarget target, ReferenceType type) throws CoreException { 151 return null; 152 } 153 159 protected void setRequestThreadFilter(EventRequest request, ThreadReference thread) { 160 } 161 164 public boolean handleClassPrepareEvent(ClassPrepareEvent event, JDIDebugTarget target) { 165 try { 166 if (isEnabled() && event.referenceType().name().equals(getTypeName())) { 167 ThreadReference threadRef= event.thread(); 168 JDIThread thread= target.findThread(threadRef); 169 if (thread == null || thread.isIgnoringBreakpoints()) { 170 return true; 171 } 172 return handleBreakpointEvent(event, target, thread); 173 } 174 } catch (CoreException e) { 175 } 176 return true; 177 } 178 181 public int getMemberType() throws CoreException { 182 return ensureMarker().getAttribute(MEMBER_TYPE, IJavaClassPrepareBreakpoint.TYPE_CLASS); 183 } 184 185 188 public boolean supportsInstanceFilters() { 189 return false; 190 } 191 194 public void addInstanceFilter(IJavaObject object) throws CoreException { 195 throw new CoreException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, JDIDebugBreakpointMessages.JavaClassPrepareBreakpoint_2, null)); 196 } 197 200 public void setThreadFilter(IJavaThread thread) throws CoreException { 201 throw new CoreException(new Status(IStatus.ERROR, JDIDebugModel.getPluginIdentifier(), DebugException.REQUEST_FAILED, JDIDebugBreakpointMessages.JavaClassPrepareBreakpoint_3, null)); 202 } 203 206 public boolean supportsThreadFilters() { 207 return false; 208 } 209 } 210 | Popular Tags |