1) Setting a new value did not work because the short name was send to XDebug instead...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / model / XDebugBreakpoint.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 net.sourceforge.phpeclipse.xdebug.php.model;
12
13
14 import java.util.ArrayList;
15 //import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 //import java.util.Iterator;
19 import java.util.List;
20 //import java.util.Map;
21 import java.util.Set;
22
23 import org.eclipse.core.resources.IMarker;
24 import org.eclipse.core.runtime.CoreException;
25 //import org.eclipse.core.runtime.MultiStatus;
26 //import org.eclipse.core.runtime.Preferences;
27 //import org.eclipse.debug.core.DebugEvent;
28 import org.eclipse.debug.core.DebugPlugin;
29 //import org.eclipse.debug.core.IDebugEventSetListener;
30 import org.eclipse.debug.core.model.Breakpoint;
31 //import org.eclipse.debug.core.model.IDebugTarget;
32 import net.sourceforge.phpeclipse.xdebug.php.model.IXDebugBreakpoint;
33
34 //import org.eclipse.jdt.debug.core.IJavaDebugTarget;
35 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
36
37 //import org.eclipse.jdt.debug.core.IJavaThread;
38 //import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread;
39
40 //import org.eclipse.jdt.debug.core.IJavaObject;
41 //import org.eclipse.jdt.debug.core.IJavaType;
42 //import org.eclipse.jdt.debug.core.JDIDebugModel;
43 //import org.eclipse.jdt.internal.debug.core.IJDIEventListener;
44 //import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
45 //import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
46 /*import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
47 import org.eclipse.jdt.internal.debug.core.model.JDIThread;
48 import org.eclipse.jdt.internal.debug.core.model.JDIType;*/
49
50 //import com.ibm.icu.text.MessageFormat;
51 //import com.sun.jdi.ObjectReference;
52 //import com.sun.jdi.ReferenceType;
53 /*import com.sun.jdi.ThreadReference;
54 import com.sun.jdi.VMDisconnectedException;
55 import com.sun.jdi.event.ClassPrepareEvent;
56 import com.sun.jdi.event.Event;
57 import com.sun.jdi.event.LocatableEvent;
58 import com.sun.jdi.request.ClassPrepareRequest;
59 import com.sun.jdi.request.EventRequest;
60 import com.sun.jdi.request.EventRequestManager;
61 */
62 public abstract class XDebugBreakpoint extends Breakpoint implements IXDebugBreakpoint/*,*/ /*IJDIEventListener,*/ /*IDebugEventSetListener*/ {
63
64         /**
65          * Breakpoint attribute storing the expired value (value <code>"org.eclipse.jdt.debug.core.expired"</code>).
66          * This attribute is stored as a <code>boolean</code>. Once a hit count has
67          * been reached, a breakpoint is considered to be "expired".
68          */
69         protected static final String EXPIRED = "org.eclipse.jdt.debug.core.expired"; //$NON-NLS-1$
70         /**
71          * Breakpoint attribute storing a breakpoint's hit count value
72          * (value <code>"org.eclipse.jdt.debug.core.hitCount"</code>). This attribute is stored as an
73          * <code>int</code>.
74          */
75 //      protected static final String HIT_COUNT = "net.sourceforge.phpeclipse.xdebug.php.model.hitCount"; //$NON-NLS-1$
76         protected static final String HIT_COUNT = "net.sourceforge.phpeclipse.debug.hitCount";            //$NON-NLS-1$
77
78         /**
79          * Breakpoint attribute storing a breakpoint's changeID. This is used for
80          * checking whether the breakpoint properties menu was finished with a
81          * OK-button. Which means a possible change of breakpoint condition or skip
82          * count. This is necessary because in method breakpointChanged in class
83          * PHPDebugTarget we need to know, whether the breakpoint has changed or not
84          * (breakpointChanged is called also when a PHP source file is modified and
85          * saved).
86          */
87         protected static final String CHANGE_ID = "net.sourceforge.phpeclipse.debug.changeID"; //$NON-NLS-1$
88
89                                                                                                                                                                                                           //
90         /**
91          * Breakpoint attribute storing a breakpoint's condition (value
92          * <code>"net.sourceforge.phpeclipse.debug.condition"</code>). This
93          * attribute is stored as an <code>string</code>.
94          */
95         protected static final String CONDITION = "net.sourceforge.phpeclipse.debug.condition";           //$NON-NLS-1$
96
97         /**
98          * Breakpoint attribute storing whether a breakpoint's condition is enabled
99          * or not (value
100          * <code>"net.sourceforge.phpeclipse.debug.conditionEnabled"</code>).
101          * This attribute is stored as an <code>boolean</code>.
102          */
103         protected static final String CONDITION_ENABLED = "net.sourceforge.phpeclipse.debug.conditionEnabled"; //$NON-NLS-1$
104
105         /**
106          * Breakpoint attribute storing the number of debug targets a
107          * breakpoint is installed in (value <code>"org.eclipse.jdt.debug.core.installCount"</code>).
108          * This attribute is a <code>int</code>.
109          */
110         protected static final String INSTALL_COUNT = "org.eclipse.jdt.debug.core.installCount"; //$NON-NLS-1$
111
112         /**
113          * Breakpoint attribute storing the fully qualified name of the type
114          * this breakpoint is located in.
115          * (value <code>"org.eclipse.jdt.debug.core.typeName"</code>). This attribute is a <code>String</code>.
116          */
117         protected static final String TYPE_NAME = "org.eclipse.jdt.debug.core.typeName"; //$NON-NLS-1$
118
119         /**
120          * Stores the collection of requests that this breakpoint has installed in
121          * debug targets.
122          * key: a debug target
123          * value: the requests this breakpoint has installed in that target
124          */
125         protected HashMap fRequestsByTarget;
126
127         /**
128          * The list of threads (ThreadReference objects) in which this breakpoint will suspend,
129          * associated with the target in which each thread exists (JDIDebugTarget).
130          * key: targets the debug targets (IJavaDebugTarget)
131          * value: thread the filtered thread (IJavaThread) in the given target
132          */
133         //protected Map fFilteredThreadsByTarget;
134
135         /**
136          * Stores the type name that this breakpoint was last installed
137          * in. When a breakpoint is created, the TYPE_NAME attribute assigned to it
138          * is that of its top level enclosing type. When installed, the type
139          * may actually be an inner type. We need to keep track of the type
140          * type the breakpoint was installed in, in case we need to re-install
141          * the breakpoint for HCR (i.e. in case an inner type is HCR'd).
142          */
143         protected String fInstalledTypeName = null;
144
145         /**
146          * List of targets in which this breakpoint is installed.
147          * Used to prevent firing of more than one install notification
148          * when a breakpoint's requests are re-created.
149          */
150         protected Set fInstalledTargets = null;
151
152         /**
153          * List of active instance filters for this breakpoint
154          * (list of <code>IJavaObject</code>).
155          */
156         protected List fInstanceFilters = null;
157
158         /**
159          * Empty instance filters array.
160          */
161         protected static final /*IJava*/Object[] fgEmptyInstanceFilters = new /*IJava*/Object[0];
162
163         /**
164          * Property identifier for a breakpoint object on an event request
165          */
166         public static final String JAVA_BREAKPOINT_PROPERTY = "org.eclipse.jdt.debug.breakpoint"; //$NON-NLS-1$
167
168         /**
169          * JavaBreakpoint attributes
170          */
171         protected static final String[] fgExpiredEnabledAttributes= new String[]{EXPIRED, ENABLED};
172
173         public XDebugBreakpoint() {
174                 fRequestsByTarget = new HashMap(1);
175                 //fFilteredThreadsByTarget= new HashMap(1);
176         }
177
178         /* (non-Javadoc)
179          * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier()
180          */
181         public String getModelIdentifier() {
182                 return "asd"; //JDIDebugModel.getPluginIdentifier();
183         }
184
185         /* (non-Javadoc)
186          * @see org.eclipse.debug.core.model.Breakpoint#setMarker(org.eclipse.core.resources.IMarker)
187          */
188         public void setMarker(IMarker marker) throws CoreException {
189                 super.setMarker(marker);
190                 configureAtStartup();
191         }
192
193         /**
194          * Add this breakpoint to the breakpoint manager,
195          * or sets it as unregistered.
196          */
197         protected void register(boolean register) throws CoreException {
198         DebugPlugin plugin = DebugPlugin.getDefault();
199                 if (plugin != null && register) {
200             plugin.getBreakpointManager().addBreakpoint(this);
201                 } else {
202                         setRegistered(false);
203                 }
204         }
205
206         /**
207          * Add the given event request to the given debug target. If
208          * the request is the breakpoint request associated with this
209          * breakpoint, increment the install count.
210          */
211         /*protected void registerRequest(EventRequest request, XDebugTarget target) throws CoreException {
212                 if (request == null) {
213                         return;
214                 }
215                 List reqs = getRequests(target);
216                 if (reqs.isEmpty()) {
217                         fRequestsByTarget.put(target, reqs);
218                 }
219                 reqs.add(request);
220                 target.addJDIEventListener(this, request);
221                 // update the install attribute on the breakpoint
222                 if (!(request instanceof ClassPrepareRequest)) {
223                         incrementInstallCount();
224                         // notification
225                         fireInstalled(target);
226                 }
227         }*/
228
229         /**
230          * Returns a String corresponding to the reference type
231          * name to the top enclosing type in which this breakpoint
232          * is located or <code>null</code> if no reference type could be
233          * found.
234          */
235         /*protected String getEnclosingReferenceTypeName() throws CoreException {
236                 String name= getTypeName();
237                 int index = name.indexOf('$');
238                 if (index == -1) {
239                         return name;
240                 }
241                 return name.substring(0, index);
242         }*/
243
244         /**
245          * Returns the requests that this breakpoint has installed
246          * in the given target.
247          */
248         protected ArrayList getRequests(XDebugTarget target) {
249                 ArrayList list= (ArrayList)fRequestsByTarget.get(target);
250                 if (list == null) {
251                         list= new ArrayList(2);
252                 }
253                 return list;
254         }
255
256         /**
257          * Remove the given request from the given target. If the request
258          * is the breakpoint request associated with this breakpoint,
259          * decrement the install count.
260          */
261         /*protected void deregisterRequest(EventRequest request, XDebugTarget target) throws CoreException {
262                 target.removeJDIEventListener(this, request);
263                 // A request may be getting de-registered because the breakpoint has
264                 // been deleted. It may be that this occurred because of a marker deletion.
265                 // Don't try updating the marker (decrementing the install count) if
266                 // it no longer exists.
267                 if (!(request instanceof ClassPrepareRequest) && getMarker().exists()) {
268                         decrementInstallCount();
269                 }
270         }*/
271
272         /* (non-Javadoc)
273          * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#handleEvent(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
274          */
275         /*public boolean handleEvent(Event event, XDebugTarget target) {
276                 if (event instanceof ClassPrepareEvent) {
277                         return handleClassPrepareEvent((ClassPrepareEvent)event, target);
278                 }
279                 ThreadReference threadRef= ((LocatableEvent)event).thread();
280                 XDebugThread thread= target.findThread(threadRef);
281                 if (thread == null || thread.isIgnoringBreakpoints()) {
282                         return true;
283                 }
284                 return handleBreakpointEvent(event, target, thread);
285         }*/
286
287         /* (non-Javadoc)
288          * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
289          */
290         /*public void wonSuspendVote(Event event, XDebugTarget target) {
291                 ThreadReference threadRef = null;
292                 if (event instanceof ClassPrepareEvent) {
293                         threadRef = ((ClassPrepareEvent)event).thread();
294                 } else if (event instanceof LocatableEvent) {
295                         threadRef = ((LocatableEvent)event).thread();
296                 }
297                 if (threadRef == null) {
298                         return;
299                 }
300                 XDebugThread thread= target.findThread(threadRef);
301                 if (thread == null || thread.isIgnoringBreakpoints()) {
302                         return;
303                 }
304                 thread.wonSuspendVote(this);
305         }*/
306
307         /**
308          * Handle the given class prepare event, which was generated by the
309          * class prepare event installed in the given target by this breakpoint.
310          *
311          * If the class which has been loaded is a class in which this breakpoint
312          * should install, create a breakpoint request for that class.
313          */
314         /*public boolean handleClassPrepareEvent(ClassPrepareEvent event, XDebugTarget target) {
315                 try {
316                         if (!installableReferenceType(event.referenceType(), target)) {
317                                 // Don't install this breakpoint in an
318                                 // inappropriate type
319                                 return true;
320                         }
321                         createRequest(target, event.referenceType());
322                 } catch (CoreException e) {
323                         XDebugCorePlugin.log(e);
324                 }
325                 return true;
326         }*/
327
328         /**
329          * @see IJDIEventListener#handleEvent(Event, JDIDebugTarget)
330          *
331          * Handle the given event, which was generated by the breakpoint request
332          * installed in the given target by this breakpoint.
333          */
334         /*public boolean handleBreakpointEvent(Event event, XDebugTarget target, XDebugThread thread) {
335                 expireHitCount(event);
336                 return !suspend(thread); // Resume if suspend fails
337         }*/
338
339         /**
340          * Delegates to the given thread to suspend, and
341          * returns whether the thread suspended
342          * It is possible that the thread will not suspend
343          * as directed by a Java breakpoint listener.
344          *
345          * @see IJavaBreakpointListener#breakpointHit(IJavaThread, IJavaBreakpoint)
346          */
347         /*protected boolean suspend(XDebugThread thread) {
348                 return thread.handleSuspendForBreakpoint(this, true);
349         }*/
350
351         /**
352          * Returns whether the given reference type is appropriate for this
353          * breakpoint to be installed in the given target. Query registered
354          * breakpoint listeners.
355          */
356         /*protected boolean installableReferenceType(ReferenceType type, XDebugTarget target) throws CoreException {
357                 String installableType= getTypeName();
358                 String queriedType= type.name();
359                 if (installableType == null || queriedType == null) {
360                         return false;
361                 }
362                 int index= queriedType.indexOf('<');
363                 if (index != -1) {
364                         queriedType= queriedType.substring(0, index);
365                 }
366                 if (installableType.equals(queriedType)) {
367                         return queryInstallListeners(target, type);
368                 }
369                 index= queriedType.indexOf('$', 0);
370                 if (index == -1) {
371                         return false;
372                 }
373                 if (installableType.regionMatches(0, queriedType, 0, index)) {
374                         return queryInstallListeners(target, type);
375                 }
376                 return false;
377         }*/
378
379         /**
380          * Called when a breakpoint event is encountered. Expires the
381          * hit count in the event's request and updates the marker.
382          * @param event the event whose request should have its hit count
383          * expired or <code>null</code> to only update the breakpoint marker.
384          */
385         /*protected void expireHitCount(Event event) {
386                 Integer requestCount= null;
387                 EventRequest request= null;
388                 if (event != null) {
389                         request= event.request();
390                         requestCount= (Integer) request.getProperty(HIT_COUNT);
391                 }
392                 if (requestCount != null) {
393                         if (request != null) {
394                                 request.putProperty(EXPIRED, Boolean.TRUE);
395                         }
396                         try {
397                                 setAttributes(fgExpiredEnabledAttributes, new Object[]{Boolean.TRUE, Boolean.FALSE});
398                                 // make a note that we auto-disabled this breakpoint.
399                         } catch (CoreException ce) {
400                                 XDebugCorePlugin.log(ce);
401                         }
402                 }
403         }*/
404
405         /**
406          * Returns whether this breakpoint should be "skipped". Breakpoints
407          * are skipped if the breakpoint manager is disabled and the breakpoint
408          * is registered with the manager
409          *
410          * @return whether this breakpoint should be skipped
411          */
412         public boolean shouldSkipBreakpoint() throws CoreException {
413                 DebugPlugin plugin = DebugPlugin.getDefault();
414         return plugin != null && isRegistered() && !plugin.getBreakpointManager().isEnabled();
415         }
416
417         /**
418          * Attempts to create a breakpoint request for this breakpoint in the given
419          * reference type in the given target.
420          *
421          * @return Whether a request was created
422          */
423         /*protected boolean createRequest(XDebugTarget target, ReferenceType type) throws CoreException {
424                 if (shouldSkipBreakpoint()) {
425                         return false;
426                 }
427                 EventRequest[] requests= newRequests(target, type);
428                 if (requests == null) {
429                         return false;
430                 }
431                 fInstalledTypeName = type.name();
432                 for (int i = 0; i < requests.length; i++) {
433             EventRequest request = requests[i];
434             registerRequest(request, target);
435         }
436                 return true;
437         }*/
438
439         /**
440          * Configure a breakpoint request with common properties:
441          * <ul>
442          * <li><code>JAVA_BREAKPOINT_PROPERTY</code></li>
443          * <li><code>HIT_COUNT</code></li>
444          * <li><code>EXPIRED</code></li>
445          * </ul>
446          * and sets the suspend policy of the request to suspend
447          * the event thread.
448          */
449         /*protected void configureRequest(EventRequest request, XDebugTarget target) throws CoreException {
450                 request.setSuspendPolicy(getJDISuspendPolicy());
451                 request.putProperty(JAVA_BREAKPOINT_PROPERTY, this);
452                 configureRequestThreadFilter(request, target);
453                 configureRequestHitCount(request);
454                 configureInstanceFilters(request, target);
455                 // Important: only enable a request after it has been configured
456                 updateEnabledState(request, target);
457         }*/
458
459         /**
460          * Adds an instance filter to the given request. Since the implementation is
461          * request specific, subclasses must override.
462          *
463          * @param request
464          * @param object instance filter
465          */
466         //protected abstract void addInstanceFilter(EventRequest request, ObjectReference object);
467
468         /**
469          * Configure the thread filter property of the given request.
470          */
471         /*protected void configureRequestThreadFilter(EventRequest request, XDebugTarget target) {
472                 IJavaThread thread= (IJavaThread)fFilteredThreadsByTarget.get(target);
473                 if (thread == null || (!(thread instanceof JDIThread))) {
474                         return;
475                 }
476                 setRequestThreadFilter(request, ((JDIThread)thread).getUnderlyingThread());
477         }*/
478
479         /**
480          * Configure the given request's hit count
481          */
482         /*protected void configureRequestHitCount(EventRequest request) throws CoreException {
483                 int hitCount= getHitCount();
484                 if (hitCount > 0) {
485                         request.addCountFilter(hitCount);
486                         request.putProperty(HIT_COUNT, new Integer(hitCount));
487                 }
488         }*/
489
490         /*protected void configureInstanceFilters(EventRequest request, XDebugTarget target) {
491                 if (fInstanceFilters != null && !fInstanceFilters.isEmpty()) {
492                         Iterator iter = fInstanceFilters.iterator();
493                         while (iter.hasNext()) {*/
494                                 /*IJava*//*Object object = (*//*IJava*//*Object)iter.next();
495                                 if (object.getDebugTarget().equals(target)) {
496                                         addInstanceFilter(request, ((JDIObjectValue)object).getUnderlyingObject());
497                                 }
498                         }
499                 }
500         }*/
501
502         /**
503          * Creates, installs, and returns all event requests for this breakpoint
504          * in the given reference type and and target.
505          *
506          * @return the event requests created or <code>null</code> if creation failed
507          */
508         //protected abstract EventRequest[] newRequests(XDebugTarget target, ReferenceType type) throws CoreException;
509
510         /**
511          * Add this breakpoint to the given target. After it has been
512          * added to the given target, this breakpoint will suspend
513          * execution of that target as appropriate.
514          */
515         /*public void addToTarget(XDebugTarget target) throws CoreException {
516                 fireAdding(target);
517                 createRequests(target);
518         }*/
519
520         /**
521          * Creates event requests for the given target
522          */
523         /*protected void createRequests(XDebugTarget target) throws CoreException {
524                 if (target.isTerminated() || shouldSkipBreakpoint()) {
525                         return;
526                 }
527                 String referenceTypeName= getTypeName();
528                 String enclosingTypeName= getEnclosingReferenceTypeName();
529                 if (referenceTypeName == null || enclosingTypeName == null) {
530                         return;
531                 }
532                 // create request to listen to class loads
533                 if (referenceTypeName.indexOf('$') == -1) {
534                         registerRequest(target.createClassPrepareRequest(enclosingTypeName), target);
535                         //register to ensure we hear about local and anonymous inner classes
536                         registerRequest(target.createClassPrepareRequest(enclosingTypeName + "$*"), target);  //$NON-NLS-1$
537                 } else {
538                         registerRequest(target.createClassPrepareRequest(referenceTypeName), target);
539                         //register to ensure we hear about local and anonymous inner classes
540                         registerRequest(target.createClassPrepareRequest(enclosingTypeName + "$*", referenceTypeName), target);  //$NON-NLS-1$
541                 }
542
543                 // create breakpoint requests for each class currently loaded
544                 List classes= target.jdiClassesByName(referenceTypeName);
545                 if (classes.isEmpty() && enclosingTypeName.equals(referenceTypeName)) {
546                         return;
547                 }
548
549                 boolean success= false;
550                 Iterator iter = classes.iterator();
551                 while (iter.hasNext()) {
552                         ReferenceType type= (ReferenceType) iter.next();
553                         if (createRequest(target, type)) {
554                                 success= true;
555                         }
556                 }
557
558                 if (!success) {
559                         addToTargetForLocalType(target, enclosingTypeName);
560                 }
561         }*/
562
563         /**
564          * Local types (types defined in methods) are handled specially due to the
565          * different types that the local type is associated with as well as the
566          * performance problems of using ReferenceType#nestedTypes.  From the Java
567          * model perspective a local type is defined within a method of a type.
568          * Therefore the type of a breakpoint placed in a local type is the type
569          * that encloses the method where the local type was defined.
570          * The local type is enclosed within the top level type according
571          * to the VM.
572          * So if "normal" attempts to create a request when a breakpoint is
573          * being added to a target fail, we must be dealing with a local type and therefore resort
574          * to looking up all of the nested types of the top level enclosing type.
575          */
576         /*protected void addToTargetForLocalType(XDebugTarget target, String enclosingTypeName) throws CoreException {
577                 List classes= target.jdiClassesByName(enclosingTypeName);
578                 if (!classes.isEmpty()) {
579                         Iterator iter = classes.iterator();
580                         while (iter.hasNext()) {
581                                 ReferenceType type= (ReferenceType) iter.next();
582                                 Iterator nestedTypes= type.nestedTypes().iterator();
583                                 while (nestedTypes.hasNext()) {
584                                         ReferenceType nestedType= (ReferenceType) nestedTypes.next();
585                                         if (createRequest(target, nestedType)) {
586                                                 break;
587                                         }
588                                 }
589                         }
590                 }
591         }*/
592
593         /**
594          * Returns the JDI suspend policy that corresponds to this
595          * breakpoint's suspend policy
596          *
597          * @return the JDI suspend policy that corresponds to this
598          *  breakpoint's suspend policy
599          * @exception CoreException if unable to access this breakpoint's
600          *  suspend policy setting
601          */
602         /*protected int getJDISuspendPolicy() throws CoreException {
603                 int breakpointPolicy = getSuspendPolicy();
604                 if (breakpointPolicy == IXDebugBreakpoint.SUSPEND_THREAD) {
605                         return EventRequest.SUSPEND_EVENT_THREAD;
606                 }
607                 return EventRequest.SUSPEND_ALL;
608         }*/
609
610         /**
611          * returns the default suspend policy based on the pref setting on the
612          * Java-Debug pref page
613          * @return the default suspend policy
614          * @since 3.2
615          */
616         /*protected int getDefaultSuspendPolicy() {
617                 Preferences store = JDIDebugModel.getPreferences();
618                 return store.getInt(JDIDebugPlugin.PREF_DEFAULT_BREAKPOINT_SUSPEND_POLICY);
619         }*/
620
621
622         /**
623          * Returns whether the hitCount of this breakpoint is equal to the hitCount of
624          * the associated request.
625          */
626         /*protected boolean hasHitCountChanged(EventRequest request) throws CoreException {
627                 int hitCount= getHitCount();
628                 Integer requestCount= (Integer) request.getProperty(HIT_COUNT);
629                 int oldCount = -1;
630                 if (requestCount != null)  {
631                         oldCount = requestCount.intValue();
632                 }
633                 return hitCount != oldCount;
634         }*/
635
636         /**
637          * Removes this breakpoint from the given target.
638          */
639         /*public void removeFromTarget(final XDebugTarget target) throws CoreException {
640                 removeRequests(target);
641                 Object removed = fFilteredThreadsByTarget.remove(target);
642                 boolean changed = removed != null;
643                 boolean markerExists = markerExists();
644                 if (!markerExists || (markerExists && getInstallCount() == 0)) {
645                         fInstalledTypeName = null;
646                 }
647
648                 // remove instance filters
649                 if (fInstanceFilters != null && !fInstanceFilters.isEmpty()) {
650                         for (int i = 0; i < fInstanceFilters.size(); i++) {
651                                 IJavaObject object = (IJavaObject)fInstanceFilters.get(i);
652                                 if (object.getDebugTarget().equals(target)) {
653                                         fInstanceFilters.remove(i);
654                                         changed = true;
655                                 }
656                         }
657                 }
658
659                 // fire change notification if required
660                 if (changed) {
661                         fireChanged();
662                 }
663
664                 // notification
665                 fireRemoved(target);
666         }       */
667
668         /**
669          * Remove all requests that this breakpoint has installed in the given
670          * debug target.
671          */
672         /*protected void removeRequests(final XDebugTarget target) throws CoreException {
673                 // removing was previously done is a workspace runnable, but that is
674                 // not possible since it can be a resource callback (marker deletion) that
675                 // causes a breakpoint to be removed
676                 ArrayList requests= (ArrayList)getRequests(target).clone();
677                 // Iterate over a copy of the requests since this list of requests
678                 // can be changed in other threads which would cause an ConcurrentModificationException
679                 Iterator iter = requests.iterator();
680                 EventRequest req;
681                 while (iter.hasNext()) {
682                         req = (EventRequest)iter.next();
683                         try {
684                                 if (target.isAvailable() && !isExpired(req)) { // cannot delete an expired request
685                                         EventRequestManager manager = target.getEventRequestManager();
686                                         if (manager != null) {
687                                                 manager.deleteEventRequest(req); // disable & remove
688                                         }
689                                 }
690                         } catch (VMDisconnectedException e) {
691                                 if (target.isAvailable()) {
692                                         JDIDebugPlugin.log(e);
693                                 }
694                         } catch (RuntimeException e) {
695                 target.internalError(e);
696                         } finally {
697                                 deregisterRequest(req, target);
698                         }
699                 }
700                 fRequestsByTarget.remove(target);
701         }*/
702
703         /**
704          * Update the enabled state of the given request in the given target, which is associated
705          * with this breakpoint. Set the enabled state of the request
706          * to the enabled state of this breakpoint.
707          */
708         /*protected void updateEnabledState(EventRequest request, XDebugTarget target) throws CoreException  {
709                 internalUpdateEnabledState(request, isEnabled(), target);
710         }*/
711
712         /**
713          * Set the enabled state of the given request to the given
714          * value, also taking into account instance filters.
715          */
716         /*protected void internalUpdateEnabledState(EventRequest request, boolean enabled, XDebugTarget target) {
717                 if (request.isEnabled() != enabled) {
718                         // change the enabled state
719                         try {
720                                 // if the request has expired, do not disable.
721                                 // BreakpointRequests that have expired cannot be deleted.
722                                 if (!isExpired(request)) {
723                                         request.setEnabled(enabled);
724                                 }
725                         //} catch (VMDisconnectedException e) {
726                         } catch (RuntimeException e) {
727                                 //target.internalError(e);
728                         }
729                 }
730         }*/
731
732         /**
733          * Returns whether this breakpoint has expired.
734          */
735         public boolean isExpired() throws CoreException {
736                 return ensureMarker().getAttribute(EXPIRED, false);
737         }
738
739         /**
740          * Returns whether the given request is expired
741          */
742         /*protected boolean isExpired(EventRequest request) {
743                 Boolean requestExpired= (Boolean) request.getProperty(EXPIRED);
744                 if (requestExpired == null) {
745                                 return false;
746                 }
747                 return requestExpired.booleanValue();
748         }*/
749
750         /* (non-Javadoc)
751          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#isInstalled()
752          */
753         public boolean isInstalled() throws CoreException {
754                 return ensureMarker().getAttribute(INSTALL_COUNT, 0) > 0;
755         }
756
757         /**
758          * Increments the install count of this breakpoint
759          */
760         protected void incrementInstallCount() throws CoreException {
761                 int count = getInstallCount();
762                 setAttribute(INSTALL_COUNT, count + 1);
763         }
764
765         /**
766          * Returns the <code>INSTALL_COUNT</code> attribute of this breakpoint
767          * or 0 if the attribute is not set.
768          */
769         public int getInstallCount() throws CoreException {
770                 return ensureMarker().getAttribute(INSTALL_COUNT, 0);
771         }
772
773         /**
774          * Decrements the install count of this breakpoint.
775          */
776         protected void decrementInstallCount() throws CoreException {
777                 int count= getInstallCount();
778                 if (count > 0) {
779                         setAttribute(INSTALL_COUNT, count - 1);
780                 }
781                 if (count == 1) {
782                         if (isExpired()) {
783                                 // if breakpoint was auto-disabled, re-enable it
784                                 setAttributes(fgExpiredEnabledAttributes,
785                                                 new Object[]{Boolean.FALSE, Boolean.TRUE});
786                         }
787                 }
788         }
789
790         /**
791          * Sets the type name in which to install this breakpoint.
792          */
793         protected void setTypeName(String typeName) throws CoreException {
794                 setAttribute(TYPE_NAME, typeName);
795         }
796
797         /* (non-Javadoc)
798          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#getTypeName()
799          */
800         public String getTypeName() throws CoreException {
801                 if (fInstalledTypeName == null) {
802                         return ensureMarker().getAttribute(TYPE_NAME, null);
803                 }
804                 return fInstalledTypeName;
805         }
806
807         /**
808          * Resets the install count attribute on this breakpoint's marker
809          * to "0".  Resets the expired attribute on all breakpoint markers to <code>false</code>.
810          * Resets the enabled attribute on the breakpoint marker to <code>true</code>.
811          * If a workbench crashes, the attributes could have been persisted
812          * in an incorrect state.
813          */
814         private void configureAtStartup() throws CoreException {
815                 List attributes= null;
816                 List values= null;
817                 if (isInstalled()) {
818                         attributes= new ArrayList(3);
819                         values= new ArrayList(3);
820                         attributes.add(INSTALL_COUNT);
821                         values.add(new Integer(0));
822                 }
823                 if (isExpired()) {
824                         if (attributes == null) {
825                                 attributes= new ArrayList(3);
826                                 values= new ArrayList(3);
827                         }
828                         // if breakpoint was auto-disabled, re-enable it
829                         attributes.add(EXPIRED);
830                         values.add(Boolean.FALSE);
831                         attributes.add(ENABLED);
832                         values.add(Boolean.TRUE);
833                 }
834                 if (attributes != null) {
835                         String[] strAttributes= new String[attributes.size()];
836                         setAttributes((String[])attributes.toArray(strAttributes), values.toArray());
837                 }
838         }
839
840         /* (non-Javadoc)
841          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#getHitCount()
842          */
843         public int getHitCount() throws CoreException {
844                 return ensureMarker().getAttribute(HIT_COUNT, -1);
845         }
846
847         /* (non-Javadoc)
848          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#setHitCount(int)
849          */
850         public void setHitCount(int count) throws CoreException {
851                 if (getHitCount() != count) {
852                         if (!isEnabled() && count > -1) {
853                                 setAttributes(new String []{ENABLED, HIT_COUNT, EXPIRED},
854                                         new Object[]{Boolean.TRUE, new Integer(count), Boolean.FALSE});
855                         } else {
856                                 setAttributes(new String[]{HIT_COUNT, EXPIRED},
857                                         new Object[]{new Integer(count), Boolean.FALSE});
858                         }
859                         ///recreate();
860                 }
861         }
862
863         protected String getMarkerMessage(int hitCount, int suspendPolicy) {
864                 StringBuffer buff= new StringBuffer();
865                 /*if (hitCount > 0){
866                         buff.append(MessageFormat.format(JDIDebugBreakpointMessages.JavaBreakpoint___Hit_Count___0___1, new Object[]{Integer.toString(hitCount)}));
867                         buff.append(' ');
868                 }
869                 String suspendPolicyString;
870                 if (suspendPolicy == IJavaBreakpoint.SUSPEND_THREAD) {
871                         suspendPolicyString= JDIDebugBreakpointMessages.JavaBreakpoint__suspend_policy__thread__1;
872                 } else {
873                         suspendPolicyString= JDIDebugBreakpointMessages.JavaBreakpoint__suspend_policy__VM__2;
874                 }
875
876                 buff.append(suspendPolicyString);*/
877                 return buff.toString();
878         }
879
880         /**
881          * Sets whether this breakpoint's hit count has expired.
882          */
883         public void setExpired(boolean expired) throws CoreException {
884                 setAttribute(EXPIRED, expired);
885         }
886
887         /* (non-Javadoc)
888          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#getSuspendPolicy()
889          */
890         /*public int getSuspendPolicy() throws CoreException {
891                 return ensureMarker().getAttribute(SUSPEND_POLICY, IJavaBreakpoint.SUSPEND_THREAD);
892         }*/
893
894         /* (non-Javadoc)
895          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#setSuspendPolicy(int)
896          */
897         /*public void setSuspendPolicy(int suspendPolicy) throws CoreException {
898                 if(getSuspendPolicy() != suspendPolicy) {
899                         setAttribute(SUSPEND_POLICY, suspendPolicy);
900                         recreate();
901                 }
902         }*/
903
904         /**
905          * Notifies listeners this breakpoint is to be added to the
906          * given target.
907          *
908          * @param target debug target
909          */
910         /*protected void fireAdding(XDebugTarget target) {
911                 XDebugCorePlugin plugin = XDebugCorePlugin.getDefault();
912         if (plugin != null)
913             plugin.fireBreakpointAdding(target, this);
914         }*/
915
916         /**
917          * Notifies listeners this breakpoint has been removed from the
918          * given target.
919          *
920          * @param target debug target
921          */
922         /*protected void fireRemoved(XDebugTarget target) {
923                 XDebugCorePlugin plugin = XDebugCorePlugin.getDefault();
924         if (plugin != null) {
925             plugin.fireBreakpointRemoved(target, this);
926             setInstalledIn(target, false);
927         }
928         }*/
929
930         /**
931          * Notifies listeners this breakpoint has been installed in the
932          * given target.
933          *
934          * @param target debug target
935          */
936         /*protected void fireInstalled(XDebugTarget target) {
937                 XDebugCorePlugin plugin = XDebugCorePlugin.getDefault();
938                 if (plugin!= null && !isInstalledIn(target)) {
939             plugin.fireBreakpointInstalled(target, this);
940                         setInstalledIn(target, true);
941                 }
942         }       */
943
944         /**
945          * Returns whether this breakpoint is installed in the given target.
946          *
947          * @param target
948          * @return whether this breakpoint is installed in the given target
949          */
950         protected boolean isInstalledIn(XDebugTarget target) {
951                 return fInstalledTargets != null && fInstalledTargets.contains(target);
952         }
953
954         /**
955          * Sets this breakpoint as installed in the given target
956          *
957          * @param target
958          * @param installed whether installed
959          */
960         protected void setInstalledIn(XDebugTarget target, boolean installed) {
961                 if (installed) {
962                         if (fInstalledTargets == null) {
963                                 fInstalledTargets = new HashSet();
964                         }
965                         fInstalledTargets.add(target);
966                 } else {
967                         if (fInstalledTargets != null) {
968                                 fInstalledTargets.remove(target);
969                         }
970                 }
971         }
972
973         /* (non-Javadoc)
974          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#setThreadFilter(org.eclipse.jdt.debug.core.IJavaThread)
975          */
976         /*public void setThreadFilter(IJavaThread thread) throws CoreException {
977                 if (!(thread.getDebugTarget() instanceof JDIDebugTarget) || !(thread instanceof JDIThread)) {
978                         return;
979                 }
980                 JDIDebugTarget target= (JDIDebugTarget)thread.getDebugTarget();
981                 if (thread != fFilteredThreadsByTarget.put(target, thread) ) {
982                         // recreate the breakpoint only if it is not the same thread
983
984                         // Other breakpoints set attributes on the underlying
985                         // marker and the marker changes are eventually
986                         // propagated to the target. The target then asks the
987                         // breakpoint to update its request. Since thread filters
988                         // are transient properties, they are not set on
989                         // the marker. Thus we must update the request
990                         // here.
991                         recreate(target);
992                         fireChanged();
993                 }
994         }*/
995
996         /* (non-Javadoc)
997          * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
998          */
999         /*public void handleDebugEvents(DebugEvent[] events) {
1000                 for (int i = 0; i < events.length; i++) {
1001                         DebugEvent event = events[i];
1002                         if (event.getKind() == DebugEvent.TERMINATE) {
1003                                 Object source= event.getSource();
1004                                 if (!(source instanceof JDIThread)) {
1005                                         return;
1006                                 }
1007                                 try {
1008                                         cleanupForThreadTermination((JDIThread)source);
1009                                 } catch (VMDisconnectedException exception) {
1010                                         // Thread death often occurs at shutdown.
1011                                         // A VMDisconnectedException trying to
1012                                         // update the breakpoint request is
1013                                         // acceptable.
1014                                 }
1015                         }
1016                 }
1017         }*/
1018
1019         /**
1020          * Removes cached information relevant to this thread which has
1021          * terminated.
1022          *
1023          * Remove thread filters for terminated threads
1024          *
1025          * Subclasses may override but need to call super.
1026          */
1027         /*protected void cleanupForThreadTermination(JDIThread thread) {
1028                 JDIDebugTarget target= (JDIDebugTarget)thread.getDebugTarget();
1029                 try {
1030                         if (thread == getThreadFilter(target)) {
1031                                 removeThreadFilter(target);
1032                         }
1033                 } catch (CoreException exception) {
1034                         JDIDebugPlugin.log(exception);
1035                 }
1036         }*/
1037
1038         /**
1039          * EventRequest does not support thread filters, so they
1040          * can't be set generically here. However, each of the breakpoint
1041          * subclasses of EventRequest do support thread filters. So
1042          * subclasses can set thread filters on their specific
1043          * request type.
1044          */
1045         //protected abstract void setRequestThreadFilter(EventRequest request, ThreadReference thread);
1046
1047         /* (non-Javadoc)
1048          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#getThreadFilter(org.eclipse.jdt.debug.core.IJavaDebugTarget)
1049          */
1050         /*public IJavaThread getThreadFilter(IJavaDebugTarget target) {
1051                 return (IJavaThread)fFilteredThreadsByTarget.get(target);
1052         }*/
1053
1054         /* (non-Javadoc)
1055          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#getThreadFilters()
1056          */
1057         /*public IJavaThread[] getThreadFilters() {
1058                 IJavaThread[] threads= null;
1059                 Collection values= fFilteredThreadsByTarget.values();
1060                 threads= new IJavaThread[values.size()];
1061                 values.toArray(threads);
1062                 return threads;
1063         }*/
1064
1065         /* (non-Javadoc)
1066          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#removeThreadFilter(org.eclipse.jdt.debug.core.IJavaDebugTarget)
1067          */
1068         /*public void removeThreadFilter(XDebugTarget javaTarget) throws CoreException {
1069                 if (!(javaTarget instanceof XDebugTarget)) {
1070                         return;
1071                 }
1072                 XDebugTarget target= (XDebugTarget)javaTarget;
1073                 if (fFilteredThreadsByTarget.remove(target) != null) {
1074                         recreate(target);
1075                         fireChanged();
1076                 }
1077         }*/
1078
1079         /**
1080          * Returns whether this breakpoint should be installed in the given reference
1081          * type in the given target according to registered breakpoint listeners.
1082          *
1083          * @param target debug target
1084          * @param type reference type or <code>null</code> if this breakpoint is
1085          *  not installed in a specific type
1086          */
1087         /*protected boolean queryInstallListeners(XDebugTarget target, ReferenceType type) {
1088         XDebugCorePlugin plugin = XDebugCorePlugin.getDefault();
1089         if (plugin != null) {
1090             IJavaType jt = null;
1091             if (type != null) {
1092                 jt = JDIType.createType(target, type);
1093             }
1094             return plugin.fireInstalling(target, this, jt);
1095         }
1096         return false;
1097         }*/
1098
1099         /* (non-Javadoc)
1100          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#addInstanceFilter(org.eclipse.jdt.debug.core.IJavaObject)
1101          */
1102         public void addInstanceFilter(/*IJava*/Object object) throws CoreException {
1103                 if (fInstanceFilters == null) {
1104                         fInstanceFilters= new ArrayList();
1105                 }
1106                 if (!fInstanceFilters.contains(object)) {
1107                         fInstanceFilters.add(object);
1108                         ///recreate((XDebugTarget)object.getDebugTarget());
1109                         fireChanged();
1110                 }
1111         }
1112
1113         /**
1114          * Change notification when there are no marker changes. If the marker
1115          * does not exist, do not fire a change notification (the marker may not
1116          * exist if the associated project was closed).
1117          */
1118         protected void fireChanged() {
1119         DebugPlugin plugin = DebugPlugin.getDefault();
1120                 if (plugin != null && markerExists()) {
1121             plugin.getBreakpointManager().fireBreakpointChanged(this);
1122                 }
1123         }
1124
1125         /* (non-Javadoc)
1126          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#getInstanceFilters()
1127          */
1128         public /*IJava*/Object[] getInstanceFilters() {
1129                 if (fInstanceFilters == null || fInstanceFilters.isEmpty()) {
1130                         return fgEmptyInstanceFilters;
1131                 }
1132                 return (/*IJava*/Object[])fInstanceFilters.toArray(new /*IJava*/Object[fInstanceFilters.size()]);
1133         }
1134
1135         /* (non-Javadoc)
1136          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#removeInstanceFilter(org.eclipse.jdt.debug.core.IJavaObject)
1137          */
1138         public void removeInstanceFilter(/*IJava*/Object object) throws CoreException {
1139                 if (fInstanceFilters == null) {
1140                         return;
1141                 }
1142                 if (fInstanceFilters.remove(object)) {
1143                         ///recreate((XDebugTarget)object.getDebugTarget());
1144                         fireChanged();
1145                 }
1146         }
1147
1148         /**
1149          * An attribute of this breakpoint has changed - recreate event requests in
1150          * all targets.
1151          */
1152         /*protected void recreate() throws CoreException {
1153                 DebugPlugin plugin = DebugPlugin.getDefault();
1154         if (plugin != null) {
1155             IDebugTarget[] targets = plugin.getLaunchManager().getDebugTargets();
1156             for (int i = 0; i < targets.length; i++) {
1157                 IDebugTarget target = targets[i];
1158                 MultiStatus multiStatus = new MultiStatus(XDebugCorePlugin.getUniqueIdentifier(), JDIDebugPlugin.ERROR, JDIDebugBreakpointMessages.JavaBreakpoint_Exception, null);
1159                 IJavaDebugTarget jdiTarget = (IJavaDebugTarget) target.getAdapter(IJavaDebugTarget.class);
1160                 if (jdiTarget instanceof JDIDebugTarget) {
1161                     try {
1162                         recreate((JDIDebugTarget) jdiTarget);
1163                     } catch (CoreException e) {
1164                         multiStatus.add(e.getStatus());
1165                     }
1166                 }
1167                 if (!multiStatus.isOK()) {
1168                     throw new CoreException(multiStatus);
1169                 }
1170             }
1171         }
1172     }*/
1173
1174         /**
1175          * Recreate this breakpoint in the given target, as long as the
1176          * target already contains this breakpoint.
1177          *
1178          * @param target the target in which to re-create the breakpoint
1179          */
1180         /*protected void recreate(XDebugTarget target) throws CoreException {
1181                 if (target.isAvailable() && target.getBreakpoints().contains(this)) {
1182                         removeRequests(target);
1183                         createRequests(target);
1184                 }
1185         }*/
1186
1187         /* (non-Javadoc)
1188          * @see org.eclipse.debug.core.model.Breakpoint#setEnabled(boolean)
1189          */
1190         public void setEnabled(boolean enabled) throws CoreException {
1191                 super.setEnabled(enabled);
1192                 //recreate();
1193         }
1194
1195         /* (non-Javadoc)
1196          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#supportsInstanceFilters()
1197          */
1198         public boolean supportsInstanceFilters() {
1199                 return true;
1200         }
1201         /* (non-Javadoc)
1202          * @see org.eclipse.jdt.debug.core.IJavaBreakpoint#supportsThreadFilters()
1203          */
1204         /*public boolean supportsThreadFilters() {
1205                 return true;
1206         }*/
1207 }