1 11 package org.eclipse.jdt.internal.debug.core.breakpoints; 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 org.eclipse.jdt.debug.core.IJavaBreakpoint; 33 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 34 import org.eclipse.jdt.debug.core.IJavaObject; 35 import org.eclipse.jdt.debug.core.IJavaThread; 36 import org.eclipse.jdt.debug.core.IJavaType; 37 import org.eclipse.jdt.debug.core.JDIDebugModel; 38 import org.eclipse.jdt.internal.debug.core.IJDIEventListener; 39 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 40 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 41 import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue; 42 import org.eclipse.jdt.internal.debug.core.model.JDIThread; 43 import org.eclipse.jdt.internal.debug.core.model.JDIType; 44 45 import com.ibm.icu.text.MessageFormat; 46 import com.sun.jdi.ObjectReference; 47 import com.sun.jdi.ReferenceType; 48 import com.sun.jdi.ThreadReference; 49 import com.sun.jdi.VMDisconnectedException; 50 import com.sun.jdi.event.ClassPrepareEvent; 51 import com.sun.jdi.event.Event; 52 import com.sun.jdi.event.LocatableEvent; 53 import com.sun.jdi.request.ClassPrepareRequest; 54 import com.sun.jdi.request.EventRequest; 55 import com.sun.jdi.request.EventRequestManager; 56 57 public abstract class JavaBreakpoint extends Breakpoint implements IJavaBreakpoint, IJDIEventListener, IDebugEventSetListener { 58 59 64 protected static final String EXPIRED = "org.eclipse.jdt.debug.core.expired"; 70 protected static final String HIT_COUNT = "org.eclipse.jdt.debug.core.hitCount"; 76 protected static final String INSTALL_COUNT = "org.eclipse.jdt.debug.core.installCount"; 78 83 protected static final String TYPE_NAME = "org.eclipse.jdt.debug.core.typeName"; 85 93 protected static final String SUSPEND_POLICY = "org.eclipse.jdt.debug.core.suspendPolicy"; 95 101 protected HashMap fRequestsByTarget; 102 103 109 protected Map fFilteredThreadsByTarget; 110 111 119 protected String fInstalledTypeName = null; 120 121 126 protected Set fInstalledTargets = null; 127 128 132 protected List fInstanceFilters = null; 133 134 137 protected static final IJavaObject[] fgEmptyInstanceFilters = new IJavaObject[0]; 138 139 142 public static final String JAVA_BREAKPOINT_PROPERTY = "org.eclipse.jdt.debug.breakpoint"; 144 147 protected static final String [] fgExpiredEnabledAttributes= new String []{EXPIRED, ENABLED}; 148 149 public JavaBreakpoint() { 150 fRequestsByTarget = new HashMap (1); 151 fFilteredThreadsByTarget= new HashMap (1); 152 } 153 154 157 public String getModelIdentifier() { 158 return JDIDebugModel.getPluginIdentifier(); 159 } 160 161 164 public void setMarker(IMarker marker) throws CoreException { 165 super.setMarker(marker); 166 configureAtStartup(); 167 } 168 169 173 protected void register(boolean register) throws CoreException { 174 DebugPlugin plugin = DebugPlugin.getDefault(); 175 if (plugin != null && register) { 176 plugin.getBreakpointManager().addBreakpoint(this); 177 } else { 178 setRegistered(false); 179 } 180 } 181 182 187 protected void registerRequest(EventRequest request, JDIDebugTarget target) throws CoreException { 188 if (request == null) { 189 return; 190 } 191 List reqs = getRequests(target); 192 if (reqs.isEmpty()) { 193 fRequestsByTarget.put(target, reqs); 194 } 195 reqs.add(request); 196 target.addJDIEventListener(this, request); 197 if (!(request instanceof ClassPrepareRequest)) { 199 incrementInstallCount(); 200 fireInstalled(target); 202 } 203 } 204 205 211 protected String getEnclosingReferenceTypeName() throws CoreException { 212 String name= getTypeName(); 213 int index = name.indexOf('$'); 214 if (index == -1) { 215 return name; 216 } 217 return name.substring(0, index); 218 } 219 220 224 protected ArrayList getRequests(JDIDebugTarget target) { 225 ArrayList list= (ArrayList )fRequestsByTarget.get(target); 226 if (list == null) { 227 list= new ArrayList (2); 228 } 229 return list; 230 } 231 232 237 protected void deregisterRequest(EventRequest request, JDIDebugTarget target) throws CoreException { 238 target.removeJDIEventListener(this, request); 239 if (!(request instanceof ClassPrepareRequest) && getMarker().exists()) { 244 decrementInstallCount(); 245 } 246 } 247 248 251 public boolean handleEvent(Event event, JDIDebugTarget target) { 252 if (event instanceof ClassPrepareEvent) { 253 return handleClassPrepareEvent((ClassPrepareEvent)event, target); 254 } 255 ThreadReference threadRef= ((LocatableEvent)event).thread(); 256 JDIThread thread= target.findThread(threadRef); 257 if (thread == null || thread.isIgnoringBreakpoints()) { 258 return true; 259 } 260 return handleBreakpointEvent(event, target, thread); 261 } 262 263 266 public void wonSuspendVote(Event event, JDIDebugTarget target) { 267 ThreadReference threadRef = null; 268 if (event instanceof ClassPrepareEvent) { 269 threadRef = ((ClassPrepareEvent)event).thread(); 270 } else if (event instanceof LocatableEvent) { 271 threadRef = ((LocatableEvent)event).thread(); 272 } 273 if (threadRef == null) { 274 return; 275 } 276 JDIThread thread= target.findThread(threadRef); 277 if (thread == null || thread.isIgnoringBreakpoints()) { 278 return; 279 } 280 thread.wonSuspendVote(this); 281 } 282 283 290 public boolean handleClassPrepareEvent(ClassPrepareEvent event, JDIDebugTarget target) { 291 try { 292 if (!installableReferenceType(event.referenceType(), target)) { 293 return true; 296 } 297 createRequest(target, event.referenceType()); 298 } catch (CoreException e) { 299 JDIDebugPlugin.log(e); 300 } 301 return true; 302 } 303 304 310 public boolean handleBreakpointEvent(Event event, JDIDebugTarget target, JDIThread thread) { 311 expireHitCount(event); 312 return !suspend(thread); } 314 315 323 protected boolean suspend(JDIThread thread) { 324 return thread.handleSuspendForBreakpoint(this, true); 325 } 326 327 332 protected boolean installableReferenceType(ReferenceType type, JDIDebugTarget target) throws CoreException { 333 String installableType= getTypeName(); 334 String queriedType= type.name(); 335 if (installableType == null || queriedType == null) { 336 return false; 337 } 338 int index= queriedType.indexOf('<'); 339 if (index != -1) { 340 queriedType= queriedType.substring(0, index); 341 } 342 if (installableType.equals(queriedType)) { 343 return queryInstallListeners(target, type); 344 } 345 index= queriedType.indexOf('$', 0); 346 if (index == -1) { 347 return false; 348 } 349 if (installableType.regionMatches(0, queriedType, 0, index)) { 350 return queryInstallListeners(target, type); 351 } 352 return false; 353 } 354 355 361 protected void expireHitCount(Event event) { 362 Integer requestCount= null; 363 EventRequest request= null; 364 if (event != null) { 365 request= event.request(); 366 requestCount= (Integer ) request.getProperty(HIT_COUNT); 367 } 368 if (requestCount != null) { 369 if (request != null) { 370 request.putProperty(EXPIRED, Boolean.TRUE); 371 } 372 try { 373 setAttributes(fgExpiredEnabledAttributes, new Object []{Boolean.TRUE, Boolean.FALSE}); 374 } catch (CoreException ce) { 376 JDIDebugPlugin.log(ce); 377 } 378 } 379 } 380 381 388 public boolean shouldSkipBreakpoint() throws CoreException { 389 DebugPlugin plugin = DebugPlugin.getDefault(); 390 return plugin != null && isRegistered() && !plugin.getBreakpointManager().isEnabled(); 391 } 392 393 399 protected boolean createRequest(JDIDebugTarget target, ReferenceType type) throws CoreException { 400 if (shouldSkipBreakpoint()) { 401 return false; 402 } 403 EventRequest[] requests= newRequests(target, type); 404 if (requests == null) { 405 return false; 406 } 407 fInstalledTypeName = type.name(); 408 for (int i = 0; i < requests.length; i++) { 409 EventRequest request = requests[i]; 410 registerRequest(request, target); 411 } 412 return true; 413 } 414 415 425 protected void configureRequest(EventRequest request, JDIDebugTarget target) throws CoreException { 426 request.setSuspendPolicy(getJDISuspendPolicy()); 427 request.putProperty(JAVA_BREAKPOINT_PROPERTY, this); 428 configureRequestThreadFilter(request, target); 429 configureRequestHitCount(request); 430 configureInstanceFilters(request, target); 431 updateEnabledState(request, target); 433 } 434 435 442 protected abstract void addInstanceFilter(EventRequest request, ObjectReference object); 443 444 447 protected void configureRequestThreadFilter(EventRequest request, JDIDebugTarget target) { 448 IJavaThread thread= (IJavaThread)fFilteredThreadsByTarget.get(target); 449 if (thread == null || (!(thread instanceof JDIThread))) { 450 return; 451 } 452 setRequestThreadFilter(request, ((JDIThread)thread).getUnderlyingThread()); 453 } 454 455 458 protected void configureRequestHitCount(EventRequest request) throws CoreException { 459 int hitCount= getHitCount(); 460 if (hitCount > 0) { 461 request.addCountFilter(hitCount); 462 request.putProperty(HIT_COUNT, new Integer (hitCount)); 463 } 464 } 465 466 protected void configureInstanceFilters(EventRequest request, JDIDebugTarget target) { 467 if (fInstanceFilters != null && !fInstanceFilters.isEmpty()) { 468 Iterator iter = fInstanceFilters.iterator(); 469 while (iter.hasNext()) { 470 IJavaObject object = (IJavaObject)iter.next(); 471 if (object.getDebugTarget().equals(target)) { 472 addInstanceFilter(request, ((JDIObjectValue)object).getUnderlyingObject()); 473 } 474 } 475 } 476 } 477 478 484 protected abstract EventRequest[] newRequests(JDIDebugTarget target, ReferenceType type) throws CoreException; 485 486 491 public void addToTarget(JDIDebugTarget target) throws CoreException { 492 fireAdding(target); 493 createRequests(target); 494 } 495 496 499 protected void createRequests(JDIDebugTarget target) throws CoreException { 500 if (target.isTerminated() || shouldSkipBreakpoint()) { 501 return; 502 } 503 String referenceTypeName= getTypeName(); 504 String enclosingTypeName= getEnclosingReferenceTypeName(); 505 if (referenceTypeName == null || enclosingTypeName == null) { 506 return; 507 } 508 if (referenceTypeName.indexOf('$') == -1) { 510 registerRequest(target.createClassPrepareRequest(enclosingTypeName), target); 511 registerRequest(target.createClassPrepareRequest(enclosingTypeName + "$*"), target); } else { 514 registerRequest(target.createClassPrepareRequest(referenceTypeName), target); 515 registerRequest(target.createClassPrepareRequest(enclosingTypeName + "$*", referenceTypeName), target); } 518 519 List classes= target.jdiClassesByName(referenceTypeName); 521 if (classes.isEmpty() && enclosingTypeName.equals(referenceTypeName)) { 522 return; 523 } 524 525 boolean success= false; 526 Iterator iter = classes.iterator(); 527 while (iter.hasNext()) { 528 ReferenceType type= (ReferenceType) iter.next(); 529 if (createRequest(target, type)) { 530 success= true; 531 } 532 } 533 534 if (!success) { 535 addToTargetForLocalType(target, enclosingTypeName); 536 } 537 } 538 539 552 protected void addToTargetForLocalType(JDIDebugTarget target, String enclosingTypeName) throws CoreException { 553 List classes= target.jdiClassesByName(enclosingTypeName); 554 if (!classes.isEmpty()) { 555 Iterator iter = classes.iterator(); 556 while (iter.hasNext()) { 557 ReferenceType type= (ReferenceType) iter.next(); 558 Iterator nestedTypes= type.nestedTypes().iterator(); 559 while (nestedTypes.hasNext()) { 560 ReferenceType nestedType= (ReferenceType) nestedTypes.next(); 561 if (createRequest(target, nestedType)) { 562 break; 563 } 564 } 565 } 566 } 567 } 568 569 578 protected int getJDISuspendPolicy() throws CoreException { 579 int breakpointPolicy = getSuspendPolicy(); 580 if (breakpointPolicy == IJavaBreakpoint.SUSPEND_THREAD) { 581 return EventRequest.SUSPEND_EVENT_THREAD; 582 } 583 return EventRequest.SUSPEND_ALL; 584 } 585 586 592 protected int getDefaultSuspendPolicy() { 593 Preferences store = JDIDebugModel.getPreferences(); 594 return store.getInt(JDIDebugPlugin.PREF_DEFAULT_BREAKPOINT_SUSPEND_POLICY); 595 } 596 597 598 602 protected boolean hasHitCountChanged(EventRequest request) throws CoreException { 603 int hitCount= getHitCount(); 604 Integer requestCount= (Integer ) request.getProperty(HIT_COUNT); 605 int oldCount = -1; 606 if (requestCount != null) { 607 oldCount = requestCount.intValue(); 608 } 609 return hitCount != oldCount; 610 } 611 612 615 public void removeFromTarget(final JDIDebugTarget target) throws CoreException { 616 removeRequests(target); 617 Object removed = fFilteredThreadsByTarget.remove(target); 618 boolean changed = removed != null; 619 boolean markerExists = markerExists(); 620 if (!markerExists || (markerExists && getInstallCount() == 0)) { 621 fInstalledTypeName = null; 622 } 623 624 if (fInstanceFilters != null && !fInstanceFilters.isEmpty()) { 626 for (int i = 0; i < fInstanceFilters.size(); i++) { 627 IJavaObject object = (IJavaObject)fInstanceFilters.get(i); 628 if (object.getDebugTarget().equals(target)) { 629 fInstanceFilters.remove(i); 630 changed = true; 631 } 632 } 633 } 634 635 if (changed) { 637 fireChanged(); 638 } 639 640 fireRemoved(target); 642 } 643 644 648 protected void removeRequests(final JDIDebugTarget target) throws CoreException { 649 ArrayList requests= (ArrayList )getRequests(target).clone(); 653 Iterator iter = requests.iterator(); 656 EventRequest req; 657 while (iter.hasNext()) { 658 req = (EventRequest)iter.next(); 659 try { 660 if (target.isAvailable() && !isExpired(req)) { EventRequestManager manager = target.getEventRequestManager(); 662 if (manager != null) { 663 manager.deleteEventRequest(req); } 665 } 666 } catch (VMDisconnectedException e) { 667 if (target.isAvailable()) { 668 JDIDebugPlugin.log(e); 669 } 670 } catch (RuntimeException e) { 671 target.internalError(e); 672 } finally { 673 deregisterRequest(req, target); 674 } 675 } 676 fRequestsByTarget.remove(target); 677 } 678 679 684 protected void updateEnabledState(EventRequest request, JDIDebugTarget target) throws CoreException { 685 internalUpdateEnabledState(request, isEnabled(), target); 686 } 687 688 692 protected void internalUpdateEnabledState(EventRequest request, boolean enabled, JDIDebugTarget target) { 693 if (request.isEnabled() != enabled) { 694 try { 696 if (!isExpired(request)) { 699 request.setEnabled(enabled); 700 } 701 } catch (VMDisconnectedException e) { 702 } catch (RuntimeException e) { 703 target.internalError(e); 704 } 705 } 706 } 707 708 711 public boolean isExpired() throws CoreException { 712 return ensureMarker().getAttribute(EXPIRED, false); 713 } 714 715 718 protected boolean isExpired(EventRequest request) { 719 Boolean requestExpired= (Boolean ) request.getProperty(EXPIRED); 720 if (requestExpired == null) { 721 return false; 722 } 723 return requestExpired.booleanValue(); 724 } 725 726 729 public boolean isInstalled() throws CoreException { 730 return ensureMarker().getAttribute(INSTALL_COUNT, 0) > 0; 731 } 732 733 736 protected void incrementInstallCount() throws CoreException { 737 int count = getInstallCount(); 738 setAttribute(INSTALL_COUNT, count + 1); 739 } 740 741 745 public int getInstallCount() throws CoreException { 746 return ensureMarker().getAttribute(INSTALL_COUNT, 0); 747 } 748 749 752 protected void decrementInstallCount() throws CoreException { 753 int count= getInstallCount(); 754 if (count > 0) { 755 setAttribute(INSTALL_COUNT, count - 1); 756 } 757 if (count == 1) { 758 if (isExpired()) { 759 setAttributes(fgExpiredEnabledAttributes, 761 new Object []{Boolean.FALSE, Boolean.TRUE}); 762 } 763 } 764 } 765 766 769 protected void setTypeName(String typeName) throws CoreException { 770 setAttribute(TYPE_NAME, typeName); 771 } 772 773 776 public String getTypeName() throws CoreException { 777 if (fInstalledTypeName == null) { 778 return ensureMarker().getAttribute(TYPE_NAME, null); 779 } 780 return fInstalledTypeName; 781 } 782 783 790 private void configureAtStartup() throws CoreException { 791 List attributes= null; 792 List values= null; 793 if (isInstalled()) { 794 attributes= new ArrayList (3); 795 values= new ArrayList (3); 796 attributes.add(INSTALL_COUNT); 797 values.add(new Integer (0)); 798 } 799 if (isExpired()) { 800 if (attributes == null) { 801 attributes= new ArrayList (3); 802 values= new ArrayList (3); 803 } 804 attributes.add(EXPIRED); 806 values.add(Boolean.FALSE); 807 attributes.add(ENABLED); 808 values.add(Boolean.TRUE); 809 } 810 if (attributes != null) { 811 String [] strAttributes= new String [attributes.size()]; 812 setAttributes((String [])attributes.toArray(strAttributes), values.toArray()); 813 } 814 } 815 816 819 public int getHitCount() throws CoreException { 820 return ensureMarker().getAttribute(HIT_COUNT, -1); 821 } 822 823 826 public void setHitCount(int count) throws CoreException { 827 if (getHitCount() != count) { 828 if (!isEnabled() && count > -1) { 829 setAttributes(new String []{ENABLED, HIT_COUNT, EXPIRED}, 830 new Object []{Boolean.TRUE, new Integer (count), Boolean.FALSE}); 831 } else { 832 setAttributes(new String []{HIT_COUNT, EXPIRED}, 833 new Object []{new Integer (count), Boolean.FALSE}); 834 } 835 recreate(); 836 } 837 } 838 839 protected String getMarkerMessage(int hitCount, int suspendPolicy) { 840 StringBuffer buff= new StringBuffer (); 841 if (hitCount > 0){ 842 buff.append(MessageFormat.format(JDIDebugBreakpointMessages.JavaBreakpoint___Hit_Count___0___1, new Object []{Integer.toString(hitCount)})); 843 buff.append(' '); 844 } 845 String suspendPolicyString; 846 if (suspendPolicy == IJavaBreakpoint.SUSPEND_THREAD) { 847 suspendPolicyString= JDIDebugBreakpointMessages.JavaBreakpoint__suspend_policy__thread__1; 848 } else { 849 suspendPolicyString= JDIDebugBreakpointMessages.JavaBreakpoint__suspend_policy__VM__2; 850 } 851 852 buff.append(suspendPolicyString); 853 return buff.toString(); 854 } 855 856 859 public void setExpired(boolean expired) throws CoreException { 860 setAttribute(EXPIRED, expired); 861 } 862 863 866 public int getSuspendPolicy() throws CoreException { 867 return ensureMarker().getAttribute(SUSPEND_POLICY, IJavaBreakpoint.SUSPEND_THREAD); 868 } 869 870 873 public void setSuspendPolicy(int suspendPolicy) throws CoreException { 874 if(getSuspendPolicy() != suspendPolicy) { 875 setAttribute(SUSPEND_POLICY, suspendPolicy); 876 recreate(); 877 } 878 } 879 880 886 protected void fireAdding(IJavaDebugTarget target) { 887 JDIDebugPlugin plugin = JDIDebugPlugin.getDefault(); 888 if (plugin != null) 889 plugin.fireBreakpointAdding(target, this); 890 } 891 892 898 protected void fireRemoved(IJavaDebugTarget target) { 899 JDIDebugPlugin plugin = JDIDebugPlugin.getDefault(); 900 if (plugin != null) { 901 plugin.fireBreakpointRemoved(target, this); 902 setInstalledIn(target, false); 903 } 904 } 905 906 912 protected void fireInstalled(IJavaDebugTarget target) { 913 JDIDebugPlugin plugin = JDIDebugPlugin.getDefault(); 914 if (plugin!= null && !isInstalledIn(target)) { 915 plugin.fireBreakpointInstalled(target, this); 916 setInstalledIn(target, true); 917 } 918 } 919 920 926 protected boolean isInstalledIn(IJavaDebugTarget target) { 927 return fInstalledTargets != null && fInstalledTargets.contains(target); 928 } 929 930 936 protected void setInstalledIn(IJavaDebugTarget target, boolean installed) { 937 if (installed) { 938 if (fInstalledTargets == null) { 939 fInstalledTargets = new HashSet (); 940 } 941 fInstalledTargets.add(target); 942 } else { 943 if (fInstalledTargets != null) { 944 fInstalledTargets.remove(target); 945 } 946 } 947 } 948 949 952 public void setThreadFilter(IJavaThread thread) throws CoreException { 953 if (!(thread.getDebugTarget() instanceof JDIDebugTarget) || !(thread instanceof JDIThread)) { 954 return; 955 } 956 JDIDebugTarget target= (JDIDebugTarget)thread.getDebugTarget(); 957 if (thread != fFilteredThreadsByTarget.put(target, thread) ) { 958 960 recreate(target); 968 fireChanged(); 969 } 970 } 971 972 975 public void handleDebugEvents(DebugEvent[] events) { 976 for (int i = 0; i < events.length; i++) { 977 DebugEvent event = events[i]; 978 if (event.getKind() == DebugEvent.TERMINATE) { 979 Object source= event.getSource(); 980 if (!(source instanceof JDIThread)) { 981 return; 982 } 983 try { 984 cleanupForThreadTermination((JDIThread)source); 985 } catch (VMDisconnectedException exception) { 986 } 991 } 992 } 993 } 994 995 1003 protected void cleanupForThreadTermination(JDIThread thread) { 1004 JDIDebugTarget target= (JDIDebugTarget)thread.getDebugTarget(); 1005 try { 1006 if (thread == getThreadFilter(target)) { 1007 removeThreadFilter(target); 1008 } 1009 } catch (CoreException exception) { 1010 JDIDebugPlugin.log(exception); 1011 } 1012 } 1013 1014 1021 protected abstract void setRequestThreadFilter(EventRequest request, ThreadReference thread); 1022 1023 1026 public IJavaThread getThreadFilter(IJavaDebugTarget target) { 1027 return (IJavaThread)fFilteredThreadsByTarget.get(target); 1028 } 1029 1030 1033 public IJavaThread[] getThreadFilters() { 1034 IJavaThread[] threads= null; 1035 Collection values= fFilteredThreadsByTarget.values(); 1036 threads= new IJavaThread[values.size()]; 1037 values.toArray(threads); 1038 return threads; 1039 } 1040 1041 1044 public void removeThreadFilter(IJavaDebugTarget javaTarget) throws CoreException { 1045 if (!(javaTarget instanceof JDIDebugTarget)) { 1046 return; 1047 } 1048 JDIDebugTarget target= (JDIDebugTarget)javaTarget; 1049 if (fFilteredThreadsByTarget.remove(target) != null) { 1050 recreate(target); 1051 fireChanged(); 1052 } 1053 } 1054 1055 1063 protected boolean queryInstallListeners(JDIDebugTarget target, ReferenceType type) { 1064 JDIDebugPlugin plugin = JDIDebugPlugin.getDefault(); 1065 if (plugin != null) { 1066 IJavaType jt = null; 1067 if (type != null) { 1068 jt = JDIType.createType(target, type); 1069 } 1070 return plugin.fireInstalling(target, this, jt); 1071 } 1072 return false; 1073 } 1074 1075 1078 public void addInstanceFilter(IJavaObject object) throws CoreException { 1079 if (fInstanceFilters == null) { 1080 fInstanceFilters= new ArrayList (); 1081 } 1082 if (!fInstanceFilters.contains(object)) { 1083 fInstanceFilters.add(object); 1084 recreate((JDIDebugTarget)object.getDebugTarget()); 1085 fireChanged(); 1086 } 1087 } 1088 1089 1094 protected void fireChanged() { 1095 DebugPlugin plugin = DebugPlugin.getDefault(); 1096 if (plugin != null && markerExists()) { 1097 plugin.getBreakpointManager().fireBreakpointChanged(this); 1098 } 1099 } 1100 1101 1104 public IJavaObject[] getInstanceFilters() { 1105 if (fInstanceFilters == null || fInstanceFilters.isEmpty()) { 1106 return fgEmptyInstanceFilters; 1107 } 1108 return (IJavaObject[])fInstanceFilters.toArray(new IJavaObject[fInstanceFilters.size()]); 1109 } 1110 1111 1114 public void removeInstanceFilter(IJavaObject object) throws CoreException { 1115 if (fInstanceFilters == null) { 1116 return; 1117 } 1118 if (fInstanceFilters.remove(object)) { 1119 recreate((JDIDebugTarget)object.getDebugTarget()); 1120 fireChanged(); 1121 } 1122 } 1123 1124 1128 protected void recreate() throws CoreException { 1129 DebugPlugin plugin = DebugPlugin.getDefault(); 1130 if (plugin != null) { 1131 IDebugTarget[] targets = plugin.getLaunchManager().getDebugTargets(); 1132 for (int i = 0; i < targets.length; i++) { 1133 IDebugTarget target = targets[i]; 1134 MultiStatus multiStatus = new MultiStatus(JDIDebugPlugin.getUniqueIdentifier(), JDIDebugPlugin.INTERNAL_ERROR, JDIDebugBreakpointMessages.JavaBreakpoint_Exception, null); 1135 IJavaDebugTarget jdiTarget = (IJavaDebugTarget) target.getAdapter(IJavaDebugTarget.class); 1136 if (jdiTarget instanceof JDIDebugTarget) { 1137 try { 1138 recreate((JDIDebugTarget) jdiTarget); 1139 } catch (CoreException e) { 1140 multiStatus.add(e.getStatus()); 1141 } 1142 } 1143 if (!multiStatus.isOK()) { 1144 throw new CoreException(multiStatus); 1145 } 1146 } 1147 } 1148 } 1149 1150 1156 protected void recreate(JDIDebugTarget target) throws CoreException { 1157 if (target.isAvailable() && target.getBreakpoints().contains(this)) { 1158 removeRequests(target); 1159 createRequests(target); 1160 } 1161 } 1162 1163 1166 public void setEnabled(boolean enabled) throws CoreException { 1167 super.setEnabled(enabled); 1168 recreate(); 1169 } 1170 1171 1174 public boolean supportsInstanceFilters() { 1175 return true; 1176 } 1177 1180 public boolean supportsThreadFilters() { 1181 return true; 1182 } 1183} 1184 | Popular Tags |