1 11 package org.eclipse.jdt.internal.debug.core.breakpoints; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 import java.util.Map ; 19 20 import org.eclipse.core.resources.IResource; 21 import org.eclipse.core.resources.IWorkspaceRunnable; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.debug.core.DebugException; 25 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 26 import org.eclipse.jdt.debug.core.IJavaTargetPatternBreakpoint; 27 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 28 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 29 30 import com.sun.jdi.AbsentInformationException; 31 import com.sun.jdi.ReferenceType; 32 import com.sun.jdi.VMDisconnectedException; 33 import com.sun.jdi.VirtualMachine; 34 35 public class JavaTargetPatternBreakpoint extends JavaLineBreakpoint implements IJavaTargetPatternBreakpoint { 36 37 private static final String TARGET_PATTERN_BREAKPOINT = "org.eclipse.jdt.debug.javaTargetPatternBreakpointMarker"; 39 42 private HashMap fPatterns; 43 44 public JavaTargetPatternBreakpoint() { 45 } 46 47 50 public JavaTargetPatternBreakpoint(IResource resource, String sourceName, int lineNumber, int charStart, int charEnd, int hitCount, boolean add, Map attributes) throws DebugException { 51 this(resource, sourceName, lineNumber, charStart, charEnd, hitCount, add, attributes, TARGET_PATTERN_BREAKPOINT); 52 } 53 54 public JavaTargetPatternBreakpoint(final IResource resource, final String sourceName, final int lineNumber, final int charStart, final int charEnd, final int hitCount, final boolean add, final Map attributes, final String markerType) throws DebugException { 55 IWorkspaceRunnable wr= new IWorkspaceRunnable() { 56 public void run(IProgressMonitor monitor) throws CoreException { 57 58 setMarker(resource.createMarker(markerType)); 60 61 addLineBreakpointAttributes(attributes, getModelIdentifier(), true, lineNumber, charStart, charEnd); 63 addSourceNameAndHitCount(attributes, sourceName, hitCount); 64 attributes.put(SUSPEND_POLICY, new Integer (getDefaultSuspendPolicy())); 65 ensureMarker().setAttributes(attributes); 67 68 register(add); 69 } 70 }; 71 run(getMarkerRule(resource), wr); 72 } 73 74 80 public void addToTarget(JDIDebugTarget target) throws CoreException { 81 82 fireAdding(target); 84 85 String referenceTypeName= getPattern(target); 86 if (referenceTypeName == null) { 87 return; 88 } 89 90 String classPrepareTypeName= referenceTypeName; 91 if (!referenceTypeName.endsWith("*")) { classPrepareTypeName= classPrepareTypeName + '*'; 95 } 96 registerRequest(target.createClassPrepareRequest(classPrepareTypeName), target); 97 98 VirtualMachine vm = target.getVM(); 100 if (vm == null) { 101 target.requestFailed(JDIDebugBreakpointMessages.JavaTargetPatternBreakpoint_Unable_to_add_breakpoint___VM_disconnected__1, null); 102 } 103 List classes= vm.allClasses(); 104 if (classes != null) { 105 Iterator iter = classes.iterator(); 106 String typeName= null; 107 ReferenceType type= null; 108 while (iter.hasNext()) { 109 type= (ReferenceType) iter.next(); 110 typeName= type.name(); 111 if (typeName != null && typeName.startsWith(referenceTypeName)) { 112 createRequest(target, type); 113 } 114 } 115 } 116 } 117 118 121 protected String getReferenceTypeName() { 122 String name= "*"; try { 124 name= getSourceName(); 125 } catch (CoreException ce) { 126 JDIDebugPlugin.log(ce); 127 } 128 return name; 129 } 130 131 134 protected boolean installableReferenceType(ReferenceType type, JDIDebugTarget target) throws CoreException { 135 if (getSourceName() != null) { 138 String sourceName = null; 139 try { 140 sourceName = type.sourceName(); 141 } catch (AbsentInformationException e) { 142 } catch (VMDisconnectedException e) { 144 if (!target.isAvailable()) { 145 return false; 146 } 147 target.targetRequestFailed(MessageFormat.format(JDIDebugBreakpointMessages.JavaPatternBreakpoint_exception_source_name,new String [] {e.toString(), type.name()}) ,e); 148 return false; 151 } catch (RuntimeException e) { 152 target.targetRequestFailed(MessageFormat.format(JDIDebugBreakpointMessages.JavaPatternBreakpoint_exception_source_name,new String [] {e.toString(), type.name()}) ,e); 153 return false; 156 } 157 158 if (sourceName != null) { 160 if (!getSourceName().equalsIgnoreCase(sourceName)) { 161 return false; 162 } 163 } 164 } 165 166 String pattern= getPattern(target); 167 String queriedType= type.name(); 168 if (pattern == null || queriedType == null) { 169 return false; 170 } 171 if (queriedType.startsWith(pattern)) { 172 return queryInstallListeners(target, type); 175 } 176 return false; 177 } 178 179 182 protected void addSourceNameAndHitCount(Map attributes, String sourceName, int hitCount) { 183 if (sourceName != null) { 184 attributes.put(SOURCE_NAME, sourceName); 185 } 186 if (hitCount > 0) { 187 attributes.put(HIT_COUNT, new Integer (hitCount)); 188 attributes.put(EXPIRED, Boolean.FALSE); 189 } 190 } 191 192 195 public String getPattern(IJavaDebugTarget target) { 196 if (fPatterns != null) { 197 return (String )fPatterns.get(target); 198 } 199 return null; 200 } 201 202 205 public void setPattern(IJavaDebugTarget target, String pattern) throws CoreException { 206 if (fPatterns == null) { 207 fPatterns = new HashMap (2); 208 } 209 String oldPattern = getPattern(target); 211 fPatterns.put(target, pattern); 212 if (oldPattern != null && !oldPattern.equals(pattern)) { 213 recreate((JDIDebugTarget)target); 214 fireChanged(); 215 } 216 } 217 218 221 public String getSourceName() throws CoreException { 222 return (String ) ensureMarker().getAttribute(SOURCE_NAME); 223 } 224 225 228 public void removeFromTarget(JDIDebugTarget target) throws CoreException { 229 fPatterns.remove(target); 230 super.removeFromTarget(target); 231 } 232 } 233 234 | Popular Tags |