KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > breakpoints > JavaMethodBreakpoint


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.core.breakpoints;
12
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.regex.Pattern JavaDoc;
17
18 import org.eclipse.core.resources.IMarker;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.resources.IWorkspaceRunnable;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.debug.core.model.IDebugTarget;
24 import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint;
25 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
26 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
27 import org.eclipse.jdt.internal.debug.core.model.JDIThread;
28
29 import com.sun.jdi.ClassType;
30 import com.sun.jdi.Location;
31 import com.sun.jdi.Method;
32 import com.sun.jdi.ObjectReference;
33 import com.sun.jdi.ReferenceType;
34 import com.sun.jdi.ThreadReference;
35 import com.sun.jdi.VMDisconnectedException;
36 import com.sun.jdi.event.BreakpointEvent;
37 import com.sun.jdi.event.Event;
38 import com.sun.jdi.event.LocatableEvent;
39 import com.sun.jdi.event.MethodEntryEvent;
40 import com.sun.jdi.event.MethodExitEvent;
41 import com.sun.jdi.request.BreakpointRequest;
42 import com.sun.jdi.request.EventRequest;
43 import com.sun.jdi.request.EventRequestManager;
44 import com.sun.jdi.request.MethodEntryRequest;
45 import com.sun.jdi.request.MethodExitRequest;
46
47 public class JavaMethodBreakpoint extends JavaLineBreakpoint implements IJavaMethodBreakpoint {
48     
49     private static final String JavaDoc JAVA_METHOD_BREAKPOINT = "org.eclipse.jdt.debug.javaMethodBreakpointMarker"; //$NON-NLS-1$
50

51     /**
52      * Breakpoint attribute storing the name of the method
53      * in which a breakpoint is contained.
54      * (value <code>"org.eclipse.jdt.debug.core.methodName"</code>).
55      * This attribute is a <code>String</code>.
56      */

57     private static final String JavaDoc METHOD_NAME = "org.eclipse.jdt.debug.core.methodName"; //$NON-NLS-1$
58

59     /**
60      * Breakpoint attribute storing the signature of the method
61      * in which a breakpoint is contained.
62      * (value <code>"org.eclipse.jdt.debug.core.methodSignature"</code>).
63      * This attribute is a <code>String</code>.
64      */

65     private static final String JavaDoc METHOD_SIGNATURE = "org.eclipse.jdt.debug.core.methodSignature"; //$NON-NLS-1$
66

67     /**
68      * Breakpoint attribute storing whether this breakpoint
69      * is an entry breakpoint.
70      * (value <code>"org.eclipse.jdt.debug.core.entry"</code>).
71      * This attribute is a <code>boolean</code>.
72      */

73     private static final String JavaDoc ENTRY = "org.eclipse.jdt.debug.core.entry"; //$NON-NLS-1$
74

75     /**
76      * Breakpoint attribute storing whether this breakpoint
77      * is an exit breakpoint.
78      * (value <code>"org.eclipse.jdt.debug.core.exit"</code>).
79      * This attribute is a <code>boolean</code>.
80      */

81     private static final String JavaDoc EXIT = "org.eclipse.jdt.debug.core.exit"; //$NON-NLS-1$
82

83     /**
84      * Breakpoint attribute storing whether this breakpoint
85      * only applies to native methods.
86      * (value <code>"org.eclipse.jdt.debug.core.native"</code>).
87      * This attribute is a <code>boolean</code>.
88      */

89     private static final String JavaDoc NATIVE = "org.eclipse.jdt.debug.core.native"; //$NON-NLS-1$
90

91     /**
92      * Cache of method name attribute
93      */

94     private String JavaDoc fMethodName = null;
95     
96     /**
97      * Cache of method signature attribute
98      */

99     private String JavaDoc fMethodSignature = null;
100     
101     /**
102      * Flag indicating that this breakpoint last suspended execution
103      * due to a method entry
104      */

105     protected static final Integer JavaDoc ENTRY_EVENT= new Integer JavaDoc(0);
106     
107     /**
108      * Flag indicating that this breakpoint last suspended execution
109      * due to a method exit
110      */

111     protected static final Integer JavaDoc EXIT_EVENT= new Integer JavaDoc(1);
112     
113     /**
114      * Maps each debug target that is suspended for this breakpoint to reason that
115      * this breakpoint suspended it. Reasons include:
116      * <ol>
117      * <li>Method entry (value <code>ENTRY_EVENT</code>)</li>
118      * <li>Method exit (value <code>EXIT_EVENT</code>)</li>
119      * </ol>
120      */

121     private Map JavaDoc fLastEventTypes= new HashMap JavaDoc(10);
122     
123     /**
124      * Used to match type names
125      */

126     private Pattern JavaDoc fPattern;
127     
128     /**
129      * Cache of whether this breakpoint uses a type name pattern
130      */

131     private Boolean JavaDoc fUsesTypePattern= null;
132     
133     /**
134      * Constructs a new unconfigured method breakpoint
135      */

136     public JavaMethodBreakpoint() {
137     }
138     
139     public JavaMethodBreakpoint(final IResource resource, final String JavaDoc typePattern, final String JavaDoc methodName, final String JavaDoc methodSignature, final boolean entry, final boolean exit, final boolean nativeOnly, final int lineNumber, final int charStart, final int charEnd, final int hitCount, final boolean register, final Map JavaDoc attributes) throws CoreException {
140         IWorkspaceRunnable wr= new IWorkspaceRunnable() {
141             public void run(IProgressMonitor monitor) throws CoreException {
142                 // create the marker
143
setMarker(resource.createMarker(JAVA_METHOD_BREAKPOINT));
144                 
145                 // add attributes
146
addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd);
147                 addMethodNameAndSignature(attributes, methodName, methodSignature);
148                 addTypeNameAndHitCount(attributes, typePattern, hitCount);
149                 attributes.put(ENTRY, Boolean.valueOf(entry));
150                 attributes.put(EXIT, Boolean.valueOf(exit));
151                 attributes.put(NATIVE, Boolean.valueOf(nativeOnly));
152                 attributes.put(SUSPEND_POLICY, new Integer JavaDoc(getDefaultSuspendPolicy()));
153                 //set attributes
154
ensureMarker().setAttributes(attributes);
155                 register(register);
156             }
157             
158         };
159         run(getMarkerRule(resource), wr);
160         String JavaDoc type = convertToRegularExpression(typePattern);
161         fPattern = Pattern.compile(type);
162     }
163     
164     /**
165      * Creates and installs an entry and exit requests
166      * in the given type name, configuring the requests as appropriate
167      * for this breakpoint. The requests are then enabled based on whether
168      * this breakpoint is an entry breakpoint, exit breakpoint, or
169      * both. Finally, the requests are registered with the given target.
170      */

171     protected void createRequest(JDIDebugTarget target, String JavaDoc typePattern) throws CoreException {
172         MethodEntryRequest entryRequest= createMethodEntryRequest(target, typePattern);
173         MethodExitRequest exitRequest= createMethodExitRequest(target, typePattern);
174         
175         registerRequest(entryRequest, target);
176         registerRequest(exitRequest, target);
177     }
178     
179     /**
180      * Returns a new method entry request for this breakpoint's
181      * criteria
182      *
183      * @param the target in which to create the request
184      * @param type the type on which to create the request
185      * @return method entry request
186      * @exception CoreException if an exception occurs accessing
187      * this breakpoint's underlying marker
188      */

189     protected MethodEntryRequest createMethodEntryRequest(JDIDebugTarget target, String JavaDoc typePattern) throws CoreException {
190         return (MethodEntryRequest)createMethodRequest(target, typePattern, true);
191     }
192     
193     /**
194      * Returns a new method exit request for this breakpoint's
195      * criteria
196      *
197      * @param target the target in which to create the request
198      * @param type the type on which to create the request
199      * @return method exit request
200      * @exception CoreException if an exception occurs accessing
201      * this breakpoint's underlying marker
202      */

203     protected MethodExitRequest createMethodExitRequest(JDIDebugTarget target, String JavaDoc typePattern) throws CoreException {
204         return (MethodExitRequest)createMethodRequest(target, typePattern, false);
205     }
206     
207     /**
208      * Returns a new method entry request for this breakpoint's
209      * criteria
210      *
211      * @param the target in which to create the request
212      * @param type the type on which to create the request
213      * @return method entry request
214      * @exception CoreException if an exception occurs accessing
215      * this breakpoint's underlying marker
216      */

217     protected EventRequest createMethodEntryRequest(JDIDebugTarget target, ReferenceType type) throws CoreException {
218         return createMethodRequest(target, type, true);
219     }
220     
221     /**
222      * Returns a new method exit request for the given reference type
223      *
224      * @param target the target in which to create the request
225      * @param type the type on which to create the request
226      * @return method exit request
227      * @exception CoreException if an exception occurs accessing
228      * this breakpoint's underlying marker
229      */

230     protected EventRequest createMethodExitRequest(JDIDebugTarget target, ReferenceType type) throws CoreException {
231         return createMethodRequest(target, type, false);
232     }
233     
234     /**
235      * @see JavaMethodBreakpoint#createMethodEntryRequest(JDIDebugTarget, ReferenceType)
236      * or JavaMethodBreakpoint#createMethodExitRequest(JDIDebugTarget, ReferenceType)
237      *
238      * Returns a <code>MethodEntryRequest</code> or <code>BreakpointRequest</code>
239      * if entry is <code>true</code>, a <code>MethodExitRequest</code> if entry is
240      * <code>false</code>.
241      *
242      * @param target the debug target in which to create the request
243      * @param classFilter a filter which specifies the scope of the method request. This parameter must
244      * be either a <code>String</code> or a <code>ReferenceType</code>
245      * @param entry whether or not the request will be a method entry request. If <code>false</code>,
246      * the request will be a method exit request.
247      */

248     private EventRequest createMethodRequest(JDIDebugTarget target, Object JavaDoc classFilter, boolean entry) throws CoreException {
249         EventRequest request = null;
250         EventRequestManager manager = target.getEventRequestManager();
251         if (manager == null) {
252             target.requestFailed(JDIDebugBreakpointMessages.JavaMethodBreakpoint_Unable_to_create_breakpoint_request___VM_disconnected__1, null);
253         }
254         try {
255             if (entry) {
256                 if (classFilter instanceof ClassType && getMethodName() != null && getMethodSignature() != null) {
257                     // use a line breakpoint if possible for better performance
258
ClassType clazz = (ClassType)classFilter;
259                     if (clazz.name().equals(getTypeName())) {
260                         // only use line breakpoint when there is an exact match
261
Method method = clazz.concreteMethodByName(getMethodName(), getMethodSignature());
262                         if (method != null && !method.isNative()) {
263                             Location location = method.location();
264                             if (location != null && location.codeIndex() != -1) {
265                                 request = manager.createBreakpointRequest(location);
266                             }
267                         }
268                     }
269                 }
270                 if (request == null) {
271                     request = manager.createMethodEntryRequest();
272                     if (classFilter instanceof String JavaDoc) {
273                         ((MethodEntryRequest)request).addClassFilter((String JavaDoc)classFilter);
274                     } else if (classFilter instanceof ReferenceType) {
275                         ((MethodEntryRequest)request).addClassFilter((ReferenceType)classFilter);
276                     }
277                 }
278             } else {
279                 request= manager.createMethodExitRequest();
280                 if (classFilter instanceof String JavaDoc) {
281                     ((MethodExitRequest)request).addClassFilter((String JavaDoc)classFilter);
282                 } else if (classFilter instanceof ReferenceType) {
283                     ((MethodExitRequest)request).addClassFilter((ReferenceType)classFilter);
284                 }
285             }
286             configureRequest(request, target);
287         } catch (VMDisconnectedException e) {
288             if (!target.isAvailable()) {
289                 return null;
290             }
291             JDIDebugPlugin.log(e);
292         } catch (RuntimeException JavaDoc e) {
293             target.internalError(e);
294         }
295         return request;
296     }
297     
298     /**
299      * @see JavaBreakpoint#setRequestThreadFilter(EventRequest)
300      */

301     protected void setRequestThreadFilter(EventRequest request, ThreadReference thread) {
302         if (request instanceof MethodEntryRequest) {
303             ((MethodEntryRequest)request).addThreadFilter(thread);
304         } else if (request instanceof MethodExitRequest){
305             ((MethodExitRequest)request).addThreadFilter(thread);
306         } else if (request instanceof BreakpointRequest) {
307             ((BreakpointRequest)request).addThreadFilter(thread);
308         }
309     }
310
311     /**
312      * Configure the given request's hit count. Since method
313      * entry/exit requests do not support hit counts, we simulate
314      * a hit count by manually updating a counter stored on the
315      * request.
316      */

317     protected void configureRequestHitCount(EventRequest request) throws CoreException {
318         if (request instanceof BreakpointRequest) {
319             super.configureRequestHitCount(request);
320         } else {
321             int hitCount = getHitCount();
322             if (hitCount > 0) {
323                 request.putProperty(HIT_COUNT, new Integer JavaDoc(hitCount));
324             }
325         }
326     }
327     
328     /**
329      * @see JavaBreakpoint#updateEnabledState(EventRequest, JDIDebugTarget)
330      */

331     protected void updateEnabledState(EventRequest request, JDIDebugTarget target) throws CoreException {
332         boolean enabled= isEnabled();
333         if (request instanceof MethodEntryRequest || request instanceof BreakpointRequest) {
334             enabled= enabled && isEntry();
335         } else if (request instanceof MethodExitRequest) {
336             enabled= enabled && isExit();
337         }
338         
339         if (enabled != request.isEnabled()) {
340             internalUpdateEnabledState(request, enabled, target);
341         }
342     }
343     
344     /**
345      * Adds the method name and signature attributes to the
346      * given attribute map, and intializes the local cache
347      * of method name and signature.
348      */

349     private void addMethodNameAndSignature(Map JavaDoc attributes, String JavaDoc methodName, String JavaDoc methodSignature) {
350         if (methodName != null) {
351             attributes.put(METHOD_NAME, methodName);
352         }
353         if (methodSignature != null) {
354             attributes.put(METHOD_SIGNATURE, methodSignature);
355         }
356         fMethodName= methodName;
357         fMethodSignature= methodSignature;
358     }
359
360     /**
361      * @see IJavaMethodBreakpoint#isEntrySuspend(IDebugTarget)
362      */

363     public boolean isEntrySuspend(IDebugTarget target) {
364         Integer JavaDoc lastEventType= (Integer JavaDoc) fLastEventTypes.get(target);
365         if (lastEventType == null) {
366             return false;
367         }
368         return lastEventType.equals(ENTRY_EVENT);
369     }
370     
371     /**
372      * @see JavaBreakpoint#handleBreakpointEvent(Event, JDIDebugTarget, JDIThread)
373      */

374     public boolean handleBreakpointEvent(Event event, JDIDebugTarget target, JDIThread thread) {
375         if (event instanceof MethodEntryEvent) {
376             MethodEntryEvent entryEvent= (MethodEntryEvent) event;
377             fLastEventTypes.put(target, ENTRY_EVENT);
378             return handleMethodEvent(entryEvent, entryEvent.method(), target, thread);
379         } else if (event instanceof MethodExitEvent) {
380             MethodExitEvent exitEvent= (MethodExitEvent) event;
381             fLastEventTypes.put(target, EXIT_EVENT);
382             return handleMethodEvent(exitEvent, exitEvent.method(), target, thread);
383         } else if (event instanceof BreakpointEvent) {
384             fLastEventTypes.put(target, ENTRY_EVENT);
385             return super.handleBreakpointEvent(event, target, thread);
386         }
387         return true;
388     }
389     
390     /**
391      * Method entry/exit events are fired each time any method is invoked in a class
392      * in which a method entry/exit breakpoint has been installed.
393      * When a method entry/exit event is received by this breakpoint, ensure that
394      * the event has been fired by a method invocation that this breakpoint
395      * is interested in. If it is not, do nothing.
396      */

397     protected boolean handleMethodEvent(LocatableEvent event, Method method, JDIDebugTarget target, JDIThread thread) {
398         try {
399             if (isNativeOnly()) {
400                 if (!method.isNative()) {
401                     return true;
402                 }
403             }
404             
405             if (getMethodName() != null) {
406                 if (!method.name().equals(getMethodName())) {
407                     return true;
408                 }
409             }
410             
411             if (getMethodSignature() != null) {
412                 String JavaDoc sig = method.signature();
413                 if(sig.indexOf('$') > -1) {
414                     sig = sig.replace('$', '.');
415                 }
416                 if (!sig.equals(getMethodSignature())) {
417                     return true;
418                 }
419             }
420             
421             if (fPattern != null) {
422                 if (!fPattern.matcher(method.declaringType().name()).find()) {
423                     return true;
424                 }
425             }
426             
427             // simulate hit count
428
Integer JavaDoc count = (Integer JavaDoc)event.request().getProperty(HIT_COUNT);
429             if (count != null && handleHitCount(event, count)) {
430                 return true;
431             }
432             // no hit count
433
if (hasCondition()) {
434                 try {
435                     return handleConditionalBreakpointEvent(event, thread, target);
436                 } catch (CoreException exception) {
437                     // log error
438
return !suspendForEvent(event, thread);
439                 }
440             }
441             return !suspendForEvent(event, thread); // Resume if suspend fails
442
} catch (CoreException e) {
443             JDIDebugPlugin.log(e);
444         }
445         return true;
446     }
447     
448     /**
449      * Method breakpoints simulate hit count.
450      * When a method event is received, decrement the hit count
451      * property on the request and suspend if the hit count reaches 0.
452      */

453     private boolean handleHitCount(LocatableEvent event, Integer JavaDoc count) {
454     // decrement count and suspend if 0
455
int hitCount = count.intValue();
456         if (hitCount > 0) {
457             hitCount--;
458             count = new Integer JavaDoc(hitCount);
459             event.request().putProperty(HIT_COUNT, count);
460             if (hitCount == 0) {
461                 // the count has reached 0, breakpoint hit
462
try {
463                     // make a note that we auto-disabled the breakpoint
464
// order is important here...see methodEntryChanged
465
setExpired(true);
466                     setEnabled(false);
467                 } catch (CoreException e) {
468                     JDIDebugPlugin.log(e);
469                 }
470                 return false;
471             }
472             // count still > 0, keep running
473
return true;
474         }
475         // hit count expired, keep running
476
return true;
477     }
478     
479     /* (non-Javadoc)
480      * @see org.eclipse.jdt.debug.core.IJavaMethodEntryBreakpoint#getMethodName()
481      */

482     public String JavaDoc getMethodName() {
483         return fMethodName;
484     }
485     
486     /* (non-Javadoc)
487      * @see org.eclipse.jdt.debug.core.IJavaMethodEntryBreakpoint#getMethodSignature()
488      */

489     public String JavaDoc getMethodSignature() {
490         return fMethodSignature;
491     }
492         
493     /**
494      * @see IJavaMethodBreakpoint#isEntry()
495      */

496     public boolean isEntry() throws CoreException {
497         return ensureMarker().getAttribute(ENTRY, false);
498     }
499
500     /**
501      * @see IJavaMethodBreakpoint#isExit()
502      */

503     public boolean isExit() throws CoreException {
504         return ensureMarker().getAttribute(EXIT, false);
505     }
506
507     /**
508      * @see IJavaMethodBreakpoint#isNative()
509      */

510     public boolean isNativeOnly() throws CoreException {
511         return ensureMarker().getAttribute(NATIVE, false);
512     }
513
514     /**
515      * @see IJavaMethodBreakpoint#setEntry(boolean)
516      */

517     public void setEntry(boolean entry) throws CoreException {
518         if (isEntry() != entry) {
519             setAttribute(ENTRY, entry);
520             if (entry && !isEnabled()) {
521                 setEnabled(true);
522             } else if (!(entry || isExit())) {
523                 setEnabled(false);
524             }
525             recreate();
526         }
527     }
528
529     /**
530      * @see IJavaMethodBreakpoint#setExit(boolean)
531      */

532     public void setExit(boolean exit) throws CoreException {
533         if (isExit() != exit) {
534             setAttribute(EXIT, exit);
535             if (exit && !isEnabled()) {
536                 setEnabled(true);
537             } else if (!(exit || isEntry())) {
538                 setEnabled(false);
539             }
540             recreate();
541         }
542     }
543
544     /**
545      * @see IJavaMethodBreakpoint#setNativeOnly(boolean)
546      */

547     public void setNativeOnly(boolean nativeOnly) throws CoreException {
548         if (isNativeOnly() != nativeOnly) {
549             setAttribute(NATIVE, nativeOnly);
550             recreate();
551         }
552     }
553         
554     /**
555      * Initialize cache of attributes
556      *
557      * @see org.eclipse.debug.core.model.IBreakpoint#setMarker(IMarker)
558      */

559     public void setMarker(IMarker marker) throws CoreException {
560         super.setMarker(marker);
561         fMethodName = marker.getAttribute(METHOD_NAME, null);
562         fMethodSignature = marker.getAttribute(METHOD_SIGNATURE, null);
563         String JavaDoc typePattern= marker.getAttribute(TYPE_NAME, ""); //$NON-NLS-1$
564
if (typePattern != null) {
565             fPattern = Pattern.compile(convertToRegularExpression(typePattern));
566         }
567     }
568     
569     /**
570      * converts the specified string to one which has been formated to our needs
571      * @param stringMatcherPattern the initial pattern
572      * @return the modified pattern
573      */

574     private String JavaDoc convertToRegularExpression(String JavaDoc stringMatcherPattern) {
575         String JavaDoc regex = stringMatcherPattern.replaceAll("\\.", "\\\\."); //$NON-NLS-1$//$NON-NLS-2$
576
regex = regex.replaceAll("\\*", "\\.\\*"); //$NON-NLS-1$//$NON-NLS-2$
577
regex = regex.replaceAll("\\$", "\\\\\\$"); //$NON-NLS-1$ //$NON-NLS-2$
578
return regex;
579     }
580     
581     /**
582      * If this breakpoint is not entry or exit enabled,
583      * set the default (entry)
584      *
585      * @see org.eclipse.debug.core.model.IBreakpoint#setEnabled(boolean)
586      */

587     public void setEnabled(boolean enabled) throws CoreException {
588         if (enabled) {
589             if (!(isEntry()|| isExit())) {
590                 setDefaultEntryAndExit();
591             }
592         }
593         super.setEnabled(enabled);
594     }
595     
596     /**
597      * Sets the default entry and exit attributes of the method breakpoint
598      * The default values are:
599      * <ul>
600      * <li>entry = <code>true</code>
601      * <li>exit = <code>false</code>
602      * <ul>
603      */

604     protected void setDefaultEntryAndExit() throws CoreException {
605         Object JavaDoc[] values= new Object JavaDoc[]{Boolean.TRUE, Boolean.FALSE};
606         String JavaDoc[] attributes= new String JavaDoc[]{ENTRY, EXIT};
607         setAttributes(attributes, values);
608     }
609     
610     /* (non-Javadoc)
611      * @see org.eclipse.jdt.debug.core.IJavaLineBreakpoint#supportsCondition()
612      */

613     public boolean supportsCondition() {
614         return true;
615     }
616
617     /**
618      * @see JavaBreakpoint#addToTarget(JDIDebugTarget)
619      */

620     public void addToTarget(JDIDebugTarget target) throws CoreException {
621         if (usesTypePattern()) {
622             // pre-notification
623
fireAdding(target);
624             
625             String JavaDoc referenceTypeNamePattern= getTypeName();
626             if (referenceTypeNamePattern == null) {
627                 return;
628             }
629             
630             createRequest(target, referenceTypeNamePattern);
631         } else {
632             super.addToTarget(target);
633         }
634     }
635     /**
636      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#removeFromTarget(JDIDebugTarget)
637      */

638     public void removeFromTarget(JDIDebugTarget target) throws CoreException {
639         fLastEventTypes.remove(target);
640         super.removeFromTarget(target);
641     }
642     
643     /**
644      * Returns whether this breakpoint uses type name pattern matching.
645      *
646      * @return whether this breakpoint uses type name pattern matching
647      */

648     protected boolean usesTypePattern() throws CoreException {
649         if (fUsesTypePattern == null) {
650             String JavaDoc name = getTypeName();
651             fUsesTypePattern= Boolean.valueOf(name != null && (name.startsWith("*") || name.endsWith("*"))); //$NON-NLS-1$ //$NON-NLS-2$
652
}
653         return fUsesTypePattern.booleanValue();
654     }
655     
656     /**
657      * Used when this breakpoint is for a specific type (i.e. not using type name
658      * pattern matching).
659      *
660      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#createRequest(JDIDebugTarget, ReferenceType)
661      */

662     protected boolean createRequest(JDIDebugTarget target, ReferenceType type) throws CoreException {
663         if (!type.name().equals(getTypeName()) || shouldSkipBreakpoint()) {
664             // do not create requests for inner/outer types if this is for a specific type
665
return false;
666         }
667         EventRequest entryRequest= createMethodEntryRequest(target, type);
668         EventRequest exitRequest= createMethodExitRequest(target, type);
669         
670         registerRequest(entryRequest, target);
671         registerRequest(exitRequest, target);
672         return true;
673     }
674     /**
675      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#setTypeName(String)
676      */

677     protected void setTypeName(String JavaDoc typeName) throws CoreException {
678         fUsesTypePattern= null;
679         super.setTypeName(typeName);
680     }
681     
682     /**
683      * @see org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint#addInstanceFilter(EventRequest, ObjectReference)
684      */

685     protected void addInstanceFilter(EventRequest request, ObjectReference object) {
686         if (request instanceof MethodEntryRequest) {
687             ((MethodEntryRequest)request).addInstanceFilter(object);
688         } else if (request instanceof MethodExitRequest) {
689             ((MethodExitRequest)request).addInstanceFilter(object);
690         } else {
691             super.addInstanceFilter(request, object);
692         }
693     }
694 }
695
Popular Tags