1 19 20 package org.netbeans.modules.debugger.jpda.breakpoints; 21 22 import com.sun.jdi.Field; 23 import com.sun.jdi.ReferenceType; 24 import com.sun.jdi.VMDisconnectedException; 25 import com.sun.jdi.event.Event; 26 import com.sun.jdi.event.ModificationWatchpointEvent; 27 import com.sun.jdi.event.WatchpointEvent; 28 import com.sun.jdi.event.LocatableEvent; 29 import com.sun.jdi.event.AccessWatchpointEvent; 30 import com.sun.jdi.request.AccessWatchpointRequest; 31 import com.sun.jdi.request.ModificationWatchpointRequest; 32 import org.netbeans.api.debugger.Breakpoint.VALIDITY; 33 import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint; 34 import org.netbeans.api.debugger.jpda.FieldBreakpoint; 35 import org.netbeans.api.debugger.Session; 36 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 37 import org.openide.util.NbBundle; 38 39 44 public class FieldBreakpointImpl extends ClassBasedBreakpoint { 45 46 47 private FieldBreakpoint breakpoint; 48 49 50 public FieldBreakpointImpl (FieldBreakpoint breakpoint, JPDADebuggerImpl debugger, Session session) { 51 super (breakpoint, debugger, session); 52 this.breakpoint = breakpoint; 53 set (); 54 } 55 56 protected void setRequests () { 57 boolean access = (breakpoint.getBreakpointType () & 58 FieldBreakpoint.TYPE_ACCESS) != 0; 59 if (access && !getVirtualMachine().canWatchFieldAccess()) { 60 setValidity(VALIDITY.INVALID, 61 NbBundle.getMessage(FieldBreakpointImpl.class, "MSG_NoFieldAccess")); 62 return ; 63 } 64 boolean modification = (breakpoint.getBreakpointType () & 65 FieldBreakpoint.TYPE_MODIFICATION) != 0; 66 if (modification && !getVirtualMachine().canWatchFieldModification()) { 67 setValidity(VALIDITY.INVALID, 68 NbBundle.getMessage(FieldBreakpointImpl.class, "MSG_NoFieldModification")); 69 return ; 70 } 71 setClassRequests ( 72 new String [] {breakpoint.getClassName ()}, 73 new String [0], 74 ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED 75 ); 76 checkLoadedClasses (breakpoint.getClassName ()); 77 } 78 79 protected void classLoaded (ReferenceType referenceType) { 80 Field f = referenceType.fieldByName (breakpoint.getFieldName ()); 81 if (f == null) { 82 setValidity(VALIDITY.INVALID, 83 NbBundle.getMessage(FieldBreakpointImpl.class, "MSG_NoField", referenceType.name(), breakpoint.getFieldName ())); 84 return ; 85 } 86 try { 87 if ( (breakpoint.getBreakpointType () & 88 FieldBreakpoint.TYPE_ACCESS) != 0 89 ) { 90 AccessWatchpointRequest awr = getEventRequestManager (). 91 createAccessWatchpointRequest (f); 92 addEventRequest (awr); 93 } 94 if ( (breakpoint.getBreakpointType () & 95 FieldBreakpoint.TYPE_MODIFICATION) != 0 96 ) { 97 ModificationWatchpointRequest mwr = getEventRequestManager (). 98 createModificationWatchpointRequest (f); 99 addEventRequest (mwr); 100 } 101 setValidity(VALIDITY.VALID, null); 102 } catch (VMDisconnectedException e) { 103 } 104 } 105 106 public boolean exec (Event event) { 107 if (event instanceof ModificationWatchpointEvent) 108 return perform ( 109 breakpoint.getCondition (), 110 ((WatchpointEvent) event).thread (), 111 ((LocatableEvent) event).location ().declaringType (), 112 ((ModificationWatchpointEvent) event).valueToBe () 113 ); 114 if (event instanceof AccessWatchpointEvent) 115 return perform ( 116 breakpoint.getCondition (), 117 ((WatchpointEvent) event).thread (), 118 ((LocatableEvent) event).location ().declaringType (), 119 ((AccessWatchpointEvent) event).valueCurrent () 120 ); 121 return super.exec (event); 122 } 123 } 124 125 | Popular Tags |