1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.internal.debug.ui.actions;
15 
16 
17 import java.util.Iterator;
18 
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.debug.core.model.IBreakpoint;
21 import org.eclipse.jdt.core.Signature;
22 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint;
23 import org.eclipse.jdt.debug.core.IJavaStackFrame;
24 import org.eclipse.jdt.debug.core.IJavaThread;
25 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
26 import org.eclipse.jface.action.IAction;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 import org.eclipse.ui.IActionDelegate;
29 
30 public class ExcludeExceptionLocationAction extends ObjectActionDelegate {
31 
32 	/**
33 	 * @see IActionDelegate#run(IAction)
34 	 */
35 	@Override
run(IAction action)36 	public void run(IAction action) {
37 		IStructuredSelection selection= getCurrentSelection();
38 		if (selection == null) {
39 			return;
40 		}
41 		Iterator<IJavaThread> itr= selection.iterator();
42 
43 		while (itr.hasNext()) {
44 			IJavaThread thread= itr.next();
45 			try {
46 				IBreakpoint[] breakpoints= thread.getBreakpoints();
47 				IJavaStackFrame frame= (IJavaStackFrame)thread.getTopStackFrame();
48 				String newFilter= frame.getDeclaringTypeName();
49 				int index = newFilter.indexOf(Signature.C_GENERIC_START);
50 				if (index > 0) {
51 					newFilter = newFilter.substring(0, index);
52 				}
53 				for (int i = 0; i < breakpoints.length; i++) {
54 					IBreakpoint breakpoint = breakpoints[i];
55 					if (breakpoint instanceof IJavaExceptionBreakpoint) {
56 						IJavaExceptionBreakpoint exBreakpoint= (IJavaExceptionBreakpoint)breakpoint;
57 						String[] current= exBreakpoint.getExclusionFilters();
58 						String[] newFilters= new String[current.length+1];
59 						System.arraycopy(current, 0, newFilters, 0, current.length);
60 						newFilters[current.length]= newFilter;
61 						exBreakpoint.setExclusionFilters(newFilters);
62 						action.setEnabled(false);
63 					}
64 				}
65 			} catch (CoreException de) {
66 				JDIDebugUIPlugin.log(de);
67 			}
68 		}
69 	}
70 }
71