1 11 package org.eclipse.jdt.internal.debug.core.breakpoints; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 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.DebugException; 24 import org.eclipse.jdt.debug.core.IJavaPatternBreakpoint; 25 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 26 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget; 27 28 import com.sun.jdi.AbsentInformationException; 29 import com.sun.jdi.ReferenceType; 30 import com.sun.jdi.VMDisconnectedException; 31 import com.sun.jdi.VirtualMachine; 32 33 public class JavaPatternBreakpoint extends JavaLineBreakpoint implements IJavaPatternBreakpoint { 34 35 private static final String PATTERN_BREAKPOINT = "org.eclipse.jdt.debug.javaPatternBreakpointMarker"; 37 42 protected static final String PATTERN = "org.eclipse.jdt.debug.core.pattern"; 44 public JavaPatternBreakpoint() { 45 } 46 47 50 public JavaPatternBreakpoint(IResource resource, String sourceName, String pattern, int lineNumber, int charStart, int charEnd, int hitCount, boolean add, Map attributes) throws DebugException { 51 this(resource, sourceName, pattern, lineNumber, charStart, charEnd, hitCount, add, attributes, PATTERN_BREAKPOINT); 52 } 53 54 public JavaPatternBreakpoint(final IResource resource, final String sourceName, final String pattern, 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 addPatternAndHitCount(attributes, sourceName, pattern, hitCount); 64 attributes.put(SUSPEND_POLICY, new Integer (getDefaultSuspendPolicy())); 66 ensureMarker().setAttributes(attributes); 67 68 register(add); 69 } 70 }; 71 run(getMarkerRule(resource), wr); 72 } 73 74 77 protected String getReferenceTypeName() { 78 String name= ""; try { 80 name= getPattern(); 81 } catch (CoreException ce) { 82 JDIDebugPlugin.log(ce); 83 } 84 return name; 85 } 86 87 90 protected boolean installableReferenceType(ReferenceType type, JDIDebugTarget target) throws CoreException { 91 if (getSourceName() != null) { 94 String sourceName = null; 95 try { 96 sourceName = type.sourceName(); 97 } catch (AbsentInformationException e) { 98 } catch (VMDisconnectedException e) { 100 if (!target.isAvailable()) { 101 return false; 102 } 103 target.targetRequestFailed(MessageFormat.format(JDIDebugBreakpointMessages.JavaPatternBreakpoint_exception_source_name,new String [] {e.toString(), type.name()}) ,e); 104 return false; 107 } catch (RuntimeException e) { 108 target.targetRequestFailed(MessageFormat.format(JDIDebugBreakpointMessages.JavaPatternBreakpoint_exception_source_name,new String [] {e.toString(), type.name()}) ,e); 109 return false; 112 } 113 114 if (sourceName != null) { 116 if (!getSourceName().equalsIgnoreCase(sourceName)) { 117 return false; 118 } 119 } 120 } 121 122 String pattern= getPattern(); 123 String queriedType= type.name(); 124 if (pattern == null || queriedType == null) { 125 return false; 126 } 127 if (queriedType.startsWith(pattern)) { 128 return queryInstallListeners(target, type); 131 } 132 return false; 133 } 134 135 138 protected void addPatternAndHitCount(Map attributes, String sourceName, String pattern, int hitCount) { 139 attributes.put(PATTERN, pattern); 140 if (sourceName != null) { 141 attributes.put(SOURCE_NAME, sourceName); 142 } 143 if (hitCount > 0) { 144 attributes.put(HIT_COUNT, new Integer (hitCount)); 145 attributes.put(EXPIRED, Boolean.FALSE); 146 } 147 } 148 149 152 public String getPattern() throws CoreException { 153 return (String ) ensureMarker().getAttribute(PATTERN); 154 } 155 156 159 public String getSourceName() throws CoreException { 160 return (String ) ensureMarker().getAttribute(SOURCE_NAME); 161 } 162 163 protected void createRequests(JDIDebugTarget target) throws CoreException { 164 if (target.isTerminated() || shouldSkipBreakpoint()) { 165 return; 166 } 167 String referenceTypeName= getReferenceTypeName(); 168 if (referenceTypeName == null) { 169 return; 170 } 171 172 String classPrepareTypeName= referenceTypeName; 173 if (!referenceTypeName.endsWith("*")) { classPrepareTypeName= classPrepareTypeName + '*'; 177 } 178 registerRequest(target.createClassPrepareRequest(classPrepareTypeName), target); 179 180 VirtualMachine vm = target.getVM(); 182 if (vm == null) { 183 target.requestFailed(JDIDebugBreakpointMessages.JavaPatternBreakpoint_Unable_to_add_breakpoint___VM_disconnected__1, null); 184 } 185 List classes = null; 186 try { 187 classes= vm.allClasses(); 188 } catch (RuntimeException e) { 189 target.targetRequestFailed(JDIDebugBreakpointMessages.JavaPatternBreakpoint_0, e); 190 } 191 if (classes != null) { 192 Iterator iter = classes.iterator(); 193 String typeName= null; 194 ReferenceType type= null; 195 while (iter.hasNext()) { 196 type= (ReferenceType) iter.next(); 197 typeName= type.name(); 198 if (typeName != null && typeName.startsWith(referenceTypeName)) { 199 createRequest(target, type); 200 } 201 } 202 } 203 } 204 } 205 206 | Popular Tags |