Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 304383 - Support suspending on JavaScript exceptions

  • Loading branch information...
commit 0645100b73daceb16f7703f0e91bbc4860b7d290 1 parent ad76568
authored May 11, 2010
8  bundles/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/Constants.java
@@ -78,5 +78,11 @@
78 78
 	/**
79 79
 	 * Preference to suspend execution when any script loads, i.e. for every script load event
80 80
 	 */
81  
-	public static final String SUSPEND_ON_ALL_SCRIPT_LOADS = JavaScriptDebugPlugin.PLUGIN_ID + ".suspend_on_all_script_loads"; //$NON-NLS-1$	
  81
+	public static final String SUSPEND_ON_ALL_SCRIPT_LOADS = JavaScriptDebugPlugin.PLUGIN_ID + ".suspend_on_all_script_loads"; //$NON-NLS-1$
  82
+	
  83
+	/**
  84
+	 * Preference to suspend execution when a thrown exception is encountered
  85
+	 * @since 1.1
  86
+	 */
  87
+	public static final String SUSPEN_ON_THROWN_EXCEPTION = JavaScriptDebugPlugin.PLUGIN_ID + ".suspend_on_thrown_exceptions"; //$NON-NLS-1$
82 88
 }
73  ...lipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/JavaScriptPreferencesManager.java
@@ -25,6 +25,7 @@
25 25
 import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptBreakpoint;
26 26
 import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLoadBreakpoint;
27 27
 import org.eclipse.wst.jsdt.debug.core.model.JavaScriptDebugModel;
  28
+import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptExceptionBreakpoint;
28 29
 import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptLoadBreakpoint;
29 30
 import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget;
30 31
 
@@ -46,6 +47,12 @@
46 47
 	private static IJavaScriptLoadBreakpoint allLoadsBreakpoint = null;
47 48
 	
48 49
 	/**
  50
+	 * The invisible "suspend on exception" breakpoint
  51
+	 * @since 1.1
  52
+	 */
  53
+	private static JavaScriptExceptionBreakpoint allExceptions = null;
  54
+	
  55
+	/**
49 56
 	 * Starts the manager
50 57
 	 */
51 58
 	public void start() {
@@ -54,6 +61,9 @@ public void start() {
54 61
 		if(node.getBoolean(Constants.SUSPEND_ON_ALL_SCRIPT_LOADS, false)) {
55 62
 			allLoadsBreakpoint = createSuspendOnAllLoads();
56 63
 		}
  64
+		if(node.getBoolean(Constants.SUSPEN_ON_THROWN_EXCEPTION, false)) {
  65
+			allExceptions = createSuspendOnException();
  66
+		}
57 67
 	}
58 68
 	
59 69
 	/**
@@ -68,6 +78,9 @@ public void stop() {
68 78
 			if(allLoadsBreakpoint != null) {
69 79
 				allLoadsBreakpoint.delete();
70 80
 			}
  81
+			if(allExceptions != null) {
  82
+				allExceptions.delete();
  83
+			}
71 84
 		} catch (CoreException e) {
72 85
 			JavaScriptDebugPlugin.log(e);
73 86
 		}
@@ -86,6 +99,63 @@ public void preferenceChange(PreferenceChangeEvent event) {
86 99
 				deleteSuspendOnAllLoads();
87 100
 			}
88 101
 		}
  102
+		if(event.getKey().equals(Constants.SUSPEN_ON_THROWN_EXCEPTION)) {
  103
+			if(event.getNewValue().equals(Boolean.TRUE.toString())) {
  104
+				//create it
  105
+				allExceptions = createSuspendOnException();
  106
+			}
  107
+			else {
  108
+				deleteSuspendOnException();
  109
+			}
  110
+		}
  111
+	}
  112
+	
  113
+	/**
  114
+	 * Creates the singleton exception breakpoint
  115
+	 * 
  116
+	 * @return the new {@link JavaScriptExceptionBreakpoint}
  117
+	 * @since 1.1
  118
+	 */
  119
+	private JavaScriptExceptionBreakpoint createSuspendOnException() {
  120
+		try {
  121
+			JavaScriptExceptionBreakpoint breakpoint = new JavaScriptExceptionBreakpoint(new HashMap());
  122
+			IDebugTarget[] targets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
  123
+			for (int i = 0; i < targets.length; i++) {
  124
+				if(targets[i] instanceof JavaScriptDebugTarget) {
  125
+					((JavaScriptDebugTarget)targets[i]).breakpointAdded(breakpoint);
  126
+				}
  127
+			}
  128
+			return breakpoint;
  129
+		}
  130
+		catch(DebugException de) {
  131
+			JavaScriptDebugPlugin.log(de);
  132
+		}
  133
+		return null;
  134
+	}
  135
+	
  136
+	/**
  137
+	 * Deletes any set exception breakpoints
  138
+	 * 
  139
+	 * @since 1.1
  140
+	 */
  141
+	private void deleteSuspendOnException() {
  142
+		if(allExceptions != null) {
  143
+			//notify all the targets
  144
+			IDebugTarget[] targets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
  145
+			for (int i = 0; i < targets.length; i++) {
  146
+				if(targets[i] instanceof JavaScriptDebugTarget) {
  147
+					((JavaScriptDebugTarget)targets[i]).breakpointRemoved(allExceptions, null);
  148
+				}
  149
+			}
  150
+			try {
  151
+				allExceptions.delete();
  152
+			} catch (CoreException e) {
  153
+				JavaScriptDebugPlugin.log(e);
  154
+			}
  155
+			finally {
  156
+				allExceptions = null;
  157
+			}
  158
+		}
89 159
 	}
90 160
 	
91 161
 	/**
@@ -166,6 +236,9 @@ public static void setGlobalSuspendOn(String scriptpath) {
166 236
 		if(allLoadsBreakpoint != null) {
167 237
 			breakpoints.add(allLoadsBreakpoint);
168 238
 		}
  239
+		if(allExceptions != null) {
  240
+			breakpoints.add(allExceptions);
  241
+		}
169 242
 		return (IJavaScriptBreakpoint[]) breakpoints.toArray(new IJavaScriptBreakpoint[breakpoints.size()]);
170 243
 	}
171 244
 	
100  ...t.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptExceptionBreakpoint.java
@@ -10,12 +10,26 @@
10 10
  *******************************************************************************/
11 11
 package org.eclipse.wst.jsdt.debug.internal.core.breakpoints;
12 12
 
  13
+import java.util.Map;
  14
+
  15
+import org.eclipse.core.resources.IMarker;
  16
+import org.eclipse.core.resources.IWorkspaceRunnable;
  17
+import org.eclipse.core.resources.ResourcesPlugin;
13 18
 import org.eclipse.core.runtime.CoreException;
  19
+import org.eclipse.core.runtime.IProgressMonitor;
  20
+import org.eclipse.debug.core.DebugException;
  21
+import org.eclipse.debug.core.model.IBreakpoint;
  22
+import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptLoadBreakpoint;
14 23
 import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
15 24
 import org.eclipse.wst.jsdt.debug.core.jsdi.event.Event;
16 25
 import org.eclipse.wst.jsdt.debug.core.jsdi.event.EventSet;
  26
+import org.eclipse.wst.jsdt.debug.core.jsdi.event.ExceptionEvent;
  27
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequest;
  28
+import org.eclipse.wst.jsdt.debug.core.jsdi.request.ExceptionRequest;
17 29
 import org.eclipse.wst.jsdt.debug.core.model.JavaScriptDebugModel;
  30
+import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
18 31
 import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget;
  32
+import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptThread;
19 33
 
20 34
 
21 35
 /**
@@ -24,13 +38,46 @@
24 38
  * @since 1.0
25 39
  */
26 40
 public class JavaScriptExceptionBreakpoint extends JavaScriptBreakpoint {
27  
-
  41
+	
  42
+	public static final String MESSAGE = JavaScriptDebugPlugin.PLUGIN_ID + ".exception_message"; //$NON-NLS-1$
  43
+	
  44
+	private ExceptionRequest request = null;
  45
+	
28 46
 	/**
29 47
 	 * Constructor
30 48
 	 * 
31 49
 	 * Required for persistence / restore
32 50
 	 */
33 51
 	public JavaScriptExceptionBreakpoint() {}
  52
+	
  53
+	/**
  54
+	 * Constructor
  55
+	 * 
  56
+	 * @param attributes
  57
+	 * @throws DebugException
  58
+	 */
  59
+	public JavaScriptExceptionBreakpoint(final Map attributes) throws DebugException {
  60
+		IWorkspaceRunnable wr = new IWorkspaceRunnable() {
  61
+			public void run(IProgressMonitor monitor) throws CoreException {
  62
+				IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IJavaScriptLoadBreakpoint.MARKER_ID);
  63
+				// create the marker
  64
+				setMarker(marker);
  65
+
  66
+				// add attributes
  67
+				attributes.put(IBreakpoint.ID, getModelIdentifier());
  68
+				attributes.put(IBreakpoint.ENABLED, Boolean.valueOf(true));
  69
+				Integer nochar = new Integer(-1);
  70
+				attributes.put(IMarker.CHAR_START, nochar);
  71
+				attributes.put(IMarker.CHAR_END, nochar);
  72
+
  73
+				ensureMarker().setAttributes(attributes);
  74
+
  75
+				// add to breakpoint manager if requested
  76
+				register(false);
  77
+			}
  78
+		};
  79
+		run(getMarkerRule(ResourcesPlugin.getWorkspace().getRoot()), wr);
  80
+	}
34 81
 
35 82
 	/* (non-Javadoc)
36 83
 	 * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier()
@@ -40,16 +87,63 @@ public String getModelIdentifier() {
40 87
 	}
41 88
 
42 89
 	/* (non-Javadoc)
  90
+	 * @see org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptBreakpoint#addToTarget(org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget)
  91
+	 */
  92
+	public void addToTarget(JavaScriptDebugTarget target) throws CoreException {
  93
+		if (target.isTerminated() || shouldSkipBreakpoint()) {
  94
+			return;
  95
+		}
  96
+		if(request == null) {
  97
+			request = target.getVM().eventRequestManager().createExceptionRequest();
  98
+			request.setEnabled(true);
  99
+			addRequestForTarget(target, request);
  100
+		}
  101
+	}
  102
+	/* (non-Javadoc)
  103
+	 * @see org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptBreakpoint#deregisterRequest(org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget, org.eclipse.wst.jsdt.debug.core.jsdi.request.EventRequest)
  104
+	 */
  105
+	protected void deregisterRequest(JavaScriptDebugTarget target, EventRequest request) {
  106
+		target.removeJSDIEventListener(this, request);
  107
+		this.request = null;
  108
+	}
  109
+	
  110
+	/* (non-Javadoc)
43 111
 	 * @see org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptBreakpoint#createRequest(org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget, org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference)
44 112
 	 */
45 113
 	protected boolean createRequest(JavaScriptDebugTarget target, ScriptReference script) throws CoreException {
46  
-		return false;
  114
+		return true;
47 115
 	}
48 116
 	
49 117
 	/* (non-Javadoc)
50 118
 	 * @see org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptBreakpoint#handleEvent(org.eclipse.wst.jsdt.debug.core.jsdi.event.Event, org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget, boolean, org.eclipse.wst.jsdt.debug.core.jsdi.event.EventSet)
51 119
 	 */
52 120
 	public boolean handleEvent(Event event, JavaScriptDebugTarget target, boolean suspendVote, EventSet eventSet) {
53  
-		return false;
  121
+		if(event instanceof ExceptionEvent) {
  122
+			try {
  123
+				ExceptionEvent eevent = (ExceptionEvent) event;
  124
+				setAttribute(MESSAGE, eevent.message());
  125
+				JavaScriptThread thread = target.findThread(eevent.thread());
  126
+				if (thread != null) {
  127
+					thread.addBreakpoint(this);
  128
+					return false;
  129
+				}
  130
+			}
  131
+			catch(CoreException ce) {
  132
+				JavaScriptDebugPlugin.log(ce);
  133
+			}
  134
+		}
  135
+		return true;
  136
+	}
  137
+	
  138
+	/* (non-Javadoc)
  139
+	 * @see org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptBreakpoint#eventSetComplete(org.eclipse.wst.jsdt.debug.core.jsdi.event.Event, org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget, boolean, org.eclipse.wst.jsdt.debug.core.jsdi.event.EventSet)
  140
+	 */
  141
+	public void eventSetComplete(Event event, JavaScriptDebugTarget target, boolean suspend, EventSet eventSet) {
  142
+		if(event instanceof ExceptionEvent) {
  143
+			JavaScriptThread thread = target.findThread(((ExceptionEvent) event).thread());
  144
+			if (thread != null) {
  145
+				thread.suspendForException(this);
  146
+			}
  147
+		}
54 148
 	}
55 149
 }
82  ...org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/model/JavaScriptThread.java
@@ -44,6 +44,7 @@
44 44
 import org.eclipse.wst.jsdt.debug.internal.core.Constants;
45 45
 import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
46 46
 import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptBreakpoint;
  47
+import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptExceptionBreakpoint;
47 48
 import org.eclipse.wst.jsdt.debug.internal.core.breakpoints.JavaScriptLoadBreakpoint;
48 49
 
49 50
 /**
@@ -247,44 +248,47 @@ public JavaScriptThread(JavaScriptDebugTarget target, ThreadReference thread) {
247 248
 	 */
248 249
 	private synchronized String statusText() {
249 250
 		switch (state) {
250  
-		case SUSPENDED: {
251  
-			if (this.breakpoints.size() > 0) {
252  
-				try {
253  
-					JavaScriptBreakpoint breakpoint = (JavaScriptBreakpoint) breakpoints.get(0);
254  
-					if (breakpoint instanceof JavaScriptLoadBreakpoint) {
255  
-						String name = breakpoint.getScriptPath();
256  
-						if (Constants.EMPTY_STRING.equals(name)) {
257  
-							name = getSourceName();
  251
+			case SUSPENDED: {
  252
+				if (this.breakpoints.size() > 0) {
  253
+					try {
  254
+						JavaScriptBreakpoint breakpoint = (JavaScriptBreakpoint) breakpoints.get(0);
  255
+						if (breakpoint instanceof JavaScriptLoadBreakpoint) {
  256
+							String name = breakpoint.getScriptPath();
  257
+							if (Constants.EMPTY_STRING.equals(name)) {
  258
+								name = getSourceName();
  259
+							}
  260
+							return NLS.bind(ModelMessages.JSDIThread_suspended_loading_script, name);
258 261
 						}
259  
-						return NLS.bind(ModelMessages.JSDIThread_suspended_loading_script, name);
260  
-					}
261  
-					// TODO support function breakpoints here
262  
-					if (breakpoint instanceof IJavaScriptLineBreakpoint) {
263  
-						IJavaScriptLineBreakpoint bp = (IJavaScriptLineBreakpoint) breakpoint;
264  
-						return NLS.bind(ModelMessages.breakpoint_at_line_location, new String[] { Integer.toString(bp.getLineNumber()), getSourceName() });
  262
+						if(breakpoint instanceof JavaScriptExceptionBreakpoint) {
  263
+							return NLS.bind(ModelMessages.JavaScriptThread_suspended_on_exception, breakpoint.getMarker().getAttribute(JavaScriptExceptionBreakpoint.MESSAGE));
  264
+						}
  265
+						// TODO support function breakpoints here
  266
+						if (breakpoint instanceof IJavaScriptLineBreakpoint) {
  267
+							IJavaScriptLineBreakpoint bp = (IJavaScriptLineBreakpoint) breakpoint;
  268
+							return NLS.bind(ModelMessages.breakpoint_at_line_location, new String[] { Integer.toString(bp.getLineNumber()), getSourceName() });
  269
+						}
  270
+						// TODO also need to report stopped at debugger; statement
  271
+					} catch (CoreException ce) {
  272
+						JavaScriptDebugPlugin.log(ce);
265 273
 					}
266  
-					// TODO also need to report stopped at debugger; statement
267  
-				} catch (CoreException ce) {
268  
-					JavaScriptDebugPlugin.log(ce);
269 274
 				}
  275
+				return ModelMessages.thread_suspended;
270 276
 			}
271  
-			return ModelMessages.thread_suspended;
272  
-		}
273  
-		case RUNNING: {
274  
-			if (pendingstep != null) {
275  
-				return ModelMessages.thread_stepping;
  277
+			case RUNNING: {
  278
+				if (pendingstep != null) {
  279
+					return ModelMessages.thread_stepping;
  280
+				}
  281
+				return ModelMessages.thread_running;
  282
+			}
  283
+			case TERMINATED: {
  284
+				return ModelMessages.thread_terminated;
  285
+			}
  286
+			case ThreadReference.THREAD_STATUS_ZOMBIE: {
  287
+				return ModelMessages.thread_zombie;
  288
+			}
  289
+			default: {
  290
+				return ModelMessages.thread_state_unknown;
276 291
 			}
277  
-			return ModelMessages.thread_running;
278  
-		}
279  
-		case TERMINATED: {
280  
-			return ModelMessages.thread_terminated;
281  
-		}
282  
-		case ThreadReference.THREAD_STATUS_ZOMBIE: {
283  
-			return ModelMessages.thread_zombie;
284  
-		}
285  
-		default: {
286  
-			return ModelMessages.thread_state_unknown;
287  
-		}
288 292
 		}
289 293
 	}
290 294
 
@@ -530,6 +534,18 @@ public void run() {
530 534
 	}
531 535
 
532 536
 	/**
  537
+	 * Suspend the thread because an exception has been caught
  538
+	 * 
  539
+	 * @param breakpoint
  540
+	 * @since 1.1
  541
+	 */
  542
+	public void suspendForException(JavaScriptExceptionBreakpoint breakpoint) {
  543
+		addBreakpoint(breakpoint);
  544
+		markSuspended();
  545
+		fireSuspendEvent(DebugEvent.BREAKPOINT);
  546
+	}
  547
+	
  548
+	/**
533 549
 	 * Call-back from a breakpoint that has been hit
534 550
 	 * 
535 551
 	 * @param breakpoint
1  ...es/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/model/ModelMessages.java
@@ -21,6 +21,7 @@
21 21
 	private static final String BUNDLE_NAME = "org.eclipse.wst.jsdt.debug.internal.core.model.modelmessages"; //$NON-NLS-1$
22 22
 	public static String breakpoint_at_line_location;
23 23
 	public static String JavaScriptThread_evaluated_script;
  24
+	public static String JavaScriptThread_suspended_on_exception;
24 25
 	public static String JavaScriptValue_object_value_label;
25 26
 	public static String JSDIDebugTarget_jsdi_debug_target;
26 27
 	public static String JSDIDebugTarget_not_support_disconnect;
1  ....eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/model/modelmessages.properties
@@ -10,6 +10,7 @@
10 10
 ###############################################################################
11 11
 breakpoint_at_line_location=suspended at breakpoint on line {0} in {1}
12 12
 JavaScriptThread_evaluated_script=<evaluated script>
  13
+JavaScriptThread_suspended_on_exception=suspended on exception: {0}
13 14
 JavaScriptValue_object_value_label={0} (id={1})
14 15
 JSDIDebugTarget_jsdi_debug_target=JavaScript Debug Target
15 16
 JSDIDebugTarget_not_support_disconnect=JavaScript debug target {0} does not support being disconnected
2  bundles/org.eclipse.wst.jsdt.debug.ui/OSGI-INF/l10n/bundle.properties
@@ -31,6 +31,8 @@ toggleFunctionBreakpointAction.name = Toggle Function Breakpoint
31 31
 toggleFunctionBreakpointAction.tooltip = Toggle a breakpoint on the selected function
32 32
 showAllScripts.name = Show All Scripts
33 33
 showAllScripts.tooltip = Shows or hides all scripts loaded in the visible targets
  34
+suspendOnExceptions.name = Suspend On JavaScript Exceptions
  35
+suspendOnExceptions.tooltip = Suspend on all JavaScript exceptions
34 36
 suspendForAllScriptLoadsAction.name = Suspend For All Script Loads
35 37
 suspendForAllScriptLoadsAction.tooltip = Suspends when any script is loaded
36 38
 javascriptMenu.name = JavaScript
9  bundles/org.eclipse.wst.jsdt.debug.ui/plugin.xml
@@ -310,6 +310,15 @@
310 310
                style="toggle"
311 311
                tooltip="%suspendForAllScriptLoadsAction.tooltip">
312 312
          </action>
  313
+         <action
  314
+               class="org.eclipse.wst.jsdt.debug.internal.ui.actions.SuspendOnExceptionsAction"
  315
+               helpContextId="suspend_on_javascript_exceptions"
  316
+               id="org.eclipse.wst.jsdt.debug.ui.suspend.on.exceptions"
  317
+               label="%suspendOnExceptions.name"
  318
+               menubarPath="javascriptActions"
  319
+               style="toggle"
  320
+               tooltip="%suspendOnExceptions.tooltip">
  321
+         </action>
313 322
       </viewContribution>
314 323
       <viewContribution
315 324
             id="debugViewActions"
68  ...ipse.wst.jsdt.debug.ui/src/org/eclipse/wst/jsdt/debug/internal/ui/actions/SuspendOnExceptionsAction.java
... ...
@@ -0,0 +1,68 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2010 IBM Corporation and others.
  3
+ * All rights reserved. This program and the accompanying materials
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ *
  8
+ * Contributors:
  9
+ *     IBM Corporation - initial API and implementation
  10
+ *******************************************************************************/
  11
+package org.eclipse.wst.jsdt.debug.internal.ui.actions;
  12
+
  13
+import org.eclipse.core.runtime.Platform;
  14
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
  15
+import org.eclipse.core.runtime.preferences.InstanceScope;
  16
+import org.eclipse.jface.action.IAction;
  17
+import org.eclipse.jface.viewers.ISelection;
  18
+import org.eclipse.ui.IViewActionDelegate;
  19
+import org.eclipse.ui.IViewPart;
  20
+import org.eclipse.wst.jsdt.debug.internal.core.Constants;
  21
+import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
  22
+import org.eclipse.wst.jsdt.debug.internal.ui.JavaScriptDebugUIPlugin;
  23
+import org.osgi.service.prefs.BackingStoreException;
  24
+
  25
+/**
  26
+ * Handles suspending the debugger when an exception is thrown
  27
+ * 
  28
+ * @since 1.1
  29
+ */
  30
+public class SuspendOnExceptionsAction implements IViewActionDelegate {
  31
+	
  32
+	boolean initialized = false;
  33
+	
  34
+	/* (non-Javadoc)
  35
+	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
  36
+	 */
  37
+	public void run(IAction action) {
  38
+		IEclipsePreferences prefs = new InstanceScope().getNode(JavaScriptDebugPlugin.PLUGIN_ID);
  39
+		if(prefs != null) {
  40
+			prefs.putBoolean(Constants.SUSPEN_ON_THROWN_EXCEPTION, action.isChecked());
  41
+			try {
  42
+				prefs.flush();
  43
+			} catch (BackingStoreException e) {
  44
+				JavaScriptDebugUIPlugin.log(e);
  45
+			}
  46
+		}
  47
+	}
  48
+
  49
+	/* (non-Javadoc)
  50
+	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
  51
+	 */
  52
+	public void selectionChanged(IAction action, ISelection selection) {
  53
+		if(!initialized) {
  54
+			boolean checked = Platform.getPreferencesService().getBoolean(
  55
+								JavaScriptDebugPlugin.PLUGIN_ID,
  56
+								Constants.SUSPEN_ON_THROWN_EXCEPTION, 
  57
+								false, 
  58
+								null);
  59
+			action.setChecked(checked);
  60
+			initialized = true;
  61
+		}
  62
+	}
  63
+
  64
+	/* (non-Javadoc)
  65
+	 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
  66
+	 */
  67
+	public void init(IViewPart view) {}
  68
+}

0 notes on commit 0645100

Please sign in to comment.
Something went wrong with that request. Please try again.