1 11 package org.eclipse.jdt.internal.debug.ui.breakpoints; 12 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.NullProgressMonitor; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.core.runtime.jobs.Job; 24 import org.eclipse.debug.core.DebugPlugin; 25 import org.eclipse.debug.core.model.IBreakpoint; 26 import org.eclipse.jdt.core.IType; 27 import org.eclipse.jdt.core.ITypeHierarchy; 28 import org.eclipse.jdt.core.JavaModelException; 29 import org.eclipse.jdt.core.search.TypeNameMatch; 30 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 31 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint; 32 import org.eclipse.jdt.debug.core.JDIDebugModel; 33 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils; 34 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 35 import org.eclipse.jface.action.IAction; 36 import org.eclipse.jface.dialogs.IDialogConstants; 37 import org.eclipse.jface.viewers.ISelection; 38 import org.eclipse.ui.IViewActionDelegate; 39 import org.eclipse.ui.IViewPart; 40 import org.eclipse.ui.IWorkbenchWindow; 41 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 42 43 46 public class AddExceptionAction implements IViewActionDelegate, IWorkbenchWindowActionDelegate { 47 48 51 public void run(IAction action) { 52 AddExceptionDialog dialog = new AddExceptionDialog(); 53 if(dialog.open() == IDialogConstants.OK_ID) { 54 boolean caught = dialog.shouldHandleCaughtExceptions(), 55 uncaught = dialog.shouldHandleUncaughtExceptions(); 56 Object [] results = dialog.getResult(); 57 if(results != null && results.length > 0) { 58 try { 59 createBreakpoint(caught, uncaught, ((TypeNameMatch)results[0]).getType()); 60 } 61 catch (CoreException e) {JDIDebugUIPlugin.statusDialog(e.getStatus());} 62 } 63 } 64 } 65 66 73 private void createBreakpoint(final boolean caught, final boolean uncaught, final IType type) throws CoreException { 74 final IResource resource = BreakpointUtils.getBreakpointResource(type); 75 final Map map = new HashMap (10); 76 BreakpointUtils.addJavaBreakpointAttributes(map, type); 77 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints( 78 JDIDebugModel.getPluginIdentifier()); 79 boolean exists = false; 80 for (int j = 0; j < breakpoints.length; j++) { 81 IJavaBreakpoint breakpoint = (IJavaBreakpoint) breakpoints[j]; 82 if (breakpoint instanceof IJavaExceptionBreakpoint) { 83 if (breakpoint.getTypeName().equals(type.getFullyQualifiedName())) { 84 exists = true; 85 break; 86 } 87 } 88 } 89 if (!exists) { 90 new Job(BreakpointMessages.AddExceptionAction_0) { 91 protected IStatus run(IProgressMonitor monitor) { 92 try { 93 JDIDebugModel.createExceptionBreakpoint(resource, 94 type.getFullyQualifiedName(), caught, 95 uncaught, isChecked(type), true, map); 96 return Status.OK_STATUS; 97 } catch (CoreException e) { 98 return e.getStatus(); 99 } 100 } 101 102 }.schedule(); 103 } 104 } 105 106 112 public static boolean isChecked(IType type) { 113 if(type != null) { 114 try { 115 ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); 116 IType curr = type; 117 while (curr != null) { 118 String name = curr.getFullyQualifiedName('.'); 119 if ("java.lang.RuntimeException".equals(name) || "java.lang.Error".equals(name)) { return false; 121 } 122 curr = hierarchy.getSuperclass(curr); 123 } 124 } 125 catch (JavaModelException e) {JDIDebugUIPlugin.log(e);} 126 } 127 return true; 128 } 129 130 133 public void init(IViewPart view) {} 134 135 138 public void selectionChanged(IAction action, ISelection selection) {} 139 140 143 public void dispose() {} 144 145 148 public void init(IWorkbenchWindow window) {} 149 } 150 | Popular Tags |