Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 150652 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/debug/core/model/JDIThread.java (-7 / +8 lines)
Lines 2669-2680 Link Here
2669
			return;
2669
			return;
2670
		}
2670
		}
2671
		try {
2671
		try {
2672
			setRunning(true);
2672
//			setRunning(true);
2673
			setSuspendedQuiet(false);
2673
//			setSuspendedQuiet(false);
2674
			fireResumeEvent(DebugEvent.CLIENT_REQUEST);
2674
//			fireResumeEvent(DebugEvent.CLIENT_REQUEST);
2675
			preserveStackFrames();
2675
//			preserveStackFrames();
2676
			fThread.forceEarlyReturn(((JDIValue)value).getUnderlyingValue());
2676
			fThread.forceEarlyReturn(((JDIValue)value).getUnderlyingValue());
2677
			fThread.resume();
2677
//			fThread.resume();
2678
			stepReturn();
2678
		} catch (VMDisconnectedException e) {
2679
		} catch (VMDisconnectedException e) {
2679
			disconnected();
2680
			disconnected();
2680
		} catch (InvalidTypeException e) {
2681
		} catch (InvalidTypeException e) {
Lines 2696-2703 Link Here
2696
	 * @throws DebugException wrapping the given exception
2697
	 * @throws DebugException wrapping the given exception
2697
	 */
2698
	 */
2698
	private void returnFailed(Exception e) throws DebugException {
2699
	private void returnFailed(Exception e) throws DebugException {
2699
		setRunning(false);
2700
//		setRunning(false);
2700
		fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
2701
//		fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
2701
		targetRequestFailed(JDIDebugModelMessages.JDIThread_48, e);
2702
		targetRequestFailed(JDIDebugModelMessages.JDIThread_48, e);
2702
	}
2703
	}
2703
	
2704
	
(-)plugin.xml (-64 / +71 lines)
Lines 164-183 Link Here
164
            label="%BreakpointActionSet.label"
164
            label="%BreakpointActionSet.label"
165
            visible="false"
165
            visible="false"
166
            id="org.eclipse.debug.ui.breakpointActionSet">
166
            id="org.eclipse.debug.ui.breakpointActionSet">
167
         <menu
168
               label="%RunMenu.label"
169
               path="additions"
170
               id="org.eclipse.ui.run">
171
            <separator
172
                  name="breakpointGroup">
173
            </separator>
174
            <groupMarker
175
                  name="lineBreakpointGroup">
176
            </groupMarker>
177
            <groupMarker
178
                  name="emptyBreakpointGroup">
179
            </groupMarker>
180
         </menu>
181
         <action
167
         <action
182
               disabledIcon="$nl$/icons/full/dlcl16/rem_all_co.gif"
168
               disabledIcon="$nl$/icons/full/dlcl16/rem_all_co.gif"
183
               label="%RemoveAllBreakpointsAction.label"
169
               label="%RemoveAllBreakpointsAction.label"
Lines 242-267 Link Here
242
            label="%DebugActionSet.label"
228
            label="%DebugActionSet.label"
243
            visible="false"
229
            visible="false"
244
            id="org.eclipse.debug.ui.debugActionSet">
230
            id="org.eclipse.debug.ui.debugActionSet">
245
         <menu
246
               label="%RunMenu.label"
247
               path="additions"
248
               id="org.eclipse.ui.run">
249
            <separator
250
                  name="stepGroup">
251
            </separator>
252
            <groupMarker
253
                  name="stepIntoGroup">
254
            </groupMarker>
255
            <groupMarker
256
                  name="stepOverGroup">
257
            </groupMarker>
258
            <groupMarker
259
                  name="stepReturnGroup">
260
            </groupMarker>
261
            <groupMarker
262
                  name="emptyStepGroup">
263
            </groupMarker>
264
         </menu>
265
         <action
231
         <action
266
               id="org.eclipse.debug.ui.actions.ToggleStepFilters"
232
               id="org.eclipse.debug.ui.actions.ToggleStepFilters"
267
               hoverIcon="$nl$/icons/full/elcl16/stepbystep_co.gif"
233
               hoverIcon="$nl$/icons/full/elcl16/stepbystep_co.gif"
Lines 356-378 Link Here
356
            label="%LaunchActionSet.label"
322
            label="%LaunchActionSet.label"
357
            visible="false"
323
            visible="false"
358
            id="org.eclipse.debug.ui.launchActionSet">
324
            id="org.eclipse.debug.ui.launchActionSet">
359
         <menu
360
               label="%RunMenu.label"
361
               path="additions"
362
               id="org.eclipse.ui.run">
363
            <separator
364
                  name="relaunchGroup">
365
            </separator>
366
            <separator
367
                  name="runGroup">
368
            </separator>
369
            <separator
370
                  name="debugGroup">
371
            </separator>
372
            <separator
373
                  name="emptyLaunchGroup">
374
            </separator>
375
         </menu>
376
         <action
325
         <action
377
               class="org.eclipse.debug.internal.ui.actions.OpenRunConfigurations"
326
               class="org.eclipse.debug.internal.ui.actions.OpenRunConfigurations"
378
               definitionId="org.eclipse.debug.ui.commands.OpenRunConfigurations"
327
               definitionId="org.eclipse.debug.ui.commands.OpenRunConfigurations"
Lines 476-492 Link Here
476
            label="%ProfileActionSet.label"
425
            label="%ProfileActionSet.label"
477
            visible="false"
426
            visible="false"
478
            id="org.eclipse.debug.ui.profileActionSet">
427
            id="org.eclipse.debug.ui.profileActionSet">
479
         <menu
480
               label="%RunMenu.label"
481
               path="additions"
482
               id="org.eclipse.ui.run">
483
            <separator
484
                  name="relaunchGroup">
485
            </separator>
486
            <separator
487
                  name="profileGroup">
488
            </separator>
489
         </menu>
490
         <action
428
         <action
491
               id="org.eclipse.debug.internal.ui.actions.ProfileDropDownAction"
429
               id="org.eclipse.debug.internal.ui.actions.ProfileDropDownAction"
492
               toolbarPath="org.eclipse.debug.ui.launchActionSet/debug"
430
               toolbarPath="org.eclipse.debug.ui.launchActionSet/debug"
Lines 1490-1499 Link Here
1490
            id="org.eclipse.debug.ui.commands.OpenDebugConfigurations">
1428
            id="org.eclipse.debug.ui.commands.OpenDebugConfigurations">
1491
      </command>
1429
      </command>
1492
      <command
1430
      <command
1493
            name="%ActionDefinition.debugLast.name"
1494
            categoryId="org.eclipse.debug.ui.category.run"
1431
            categoryId="org.eclipse.debug.ui.category.run"
1495
            description="%ActionDefinition.debugLast.description"
1432
            description="%ActionDefinition.debugLast.description"
1496
            id="org.eclipse.debug.ui.commands.DebugLast">
1433
            helpContextId="debug_last_action_context"
1434
            id="org.eclipse.debug.ui.commands.DebugLast"
1435
            name="%ActionDefinition.debugLast.name">
1497
      </command>
1436
      </command>
1498
      <command
1437
      <command
1499
            name="%ActionDefinition.runLast.name"
1438
            name="%ActionDefinition.runLast.name"
Lines 2297-2302 Link Here
2297
       </wizard>
2236
       </wizard>
2298
    </extension>
2237
    </extension>
2299
    <extension
2238
    <extension
2239
          point="org.eclipse.ui.menus">
2240
       <menuContribution
2241
             locationURI="menu:org.eclipse.ui.main.menu">
2242
          <menu
2243
                id="org.eclipse.ui.run"
2244
                label="%RunMenu.label"
2245
                mnemonic="R"
2246
                tooltip="The main run menu">
2247
             <separator
2248
                   name="stepGroup"
2249
                   visible="true">
2250
             </separator>
2251
             <separator
2252
                   name="stepIntoGroup"
2253
                   visible="false">
2254
             </separator>
2255
             <separator
2256
                   name="stepOverGroup"
2257
                   visible="false">
2258
             </separator>
2259
             <separator
2260
                   name="stepReturnGroup"
2261
                   visible="false">
2262
             </separator>
2263
             <separator
2264
                   name="emptyStepGroup"
2265
                   visible="true">
2266
             </separator>
2267
             <separator
2268
                   name="relaunchGroup"
2269
                   visible="true">
2270
             </separator>
2271
             <separator
2272
                   name="debugGroup"
2273
                   visible="true">
2274
             </separator>
2275
             <separator
2276
                   name="runGroup"
2277
                   visible="true">
2278
             </separator>
2279
             <separator
2280
                   name="profileGroup"
2281
                   visible="true">
2282
             </separator>
2283
             <separator
2284
                   name="emptyLaunchGroup"
2285
                   visible="true">
2286
             </separator>
2287
             <separator
2288
                   name="breakpointGroup"
2289
                   visible="true">
2290
             </separator>
2291
             <separator
2292
                   name="lineBreakpointGroup"
2293
                   visible="true">
2294
             </separator>
2295
             <separator
2296
                   name="emptyBreakpointGroup"
2297
                   visible="true">
2298
             </separator>
2299
             <separator
2300
                   name="additions">
2301
             </separator>
2302
             
2303
          </menu>
2304
       </menuContribution>
2305
    </extension>
2306
    <extension
2300
          point="org.eclipse.ui.exportWizards">
2307
          point="org.eclipse.ui.exportWizards">
2301
       <wizard
2308
       <wizard
2302
             category="org.eclipse.ui.Basic"
2309
             category="org.eclipse.ui.Basic"
(-)ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPlugin.java (+6 lines)
Lines 114-119 Link Here
114
	public static final String COMMAND_INSPECT = "org.eclipse.jdt.debug.ui.commands.Inspect"; //$NON-NLS-1$
114
	public static final String COMMAND_INSPECT = "org.eclipse.jdt.debug.ui.commands.Inspect"; //$NON-NLS-1$
115
	
115
	
116
	/**
116
	/**
117
	 * Whether this plug-in is in debug mode.
118
	 */
119
	public static boolean DEBUG = false;
120
	
121
	/**
117
	 * Java Debug UI plug-in instance
122
	 * Java Debug UI plug-in instance
118
	 */
123
	 */
119
	private static JDIDebugUIPlugin fgPlugin;
124
	private static JDIDebugUIPlugin fgPlugin;
Lines 333-338 Link Here
333
	 */
338
	 */
334
	public void start(BundleContext context) throws Exception {
339
	public void start(BundleContext context) throws Exception {
335
		super.start(context);
340
		super.start(context);
341
		DEBUG = "true".equals(Platform.getDebugOption("org.eclipse.jdt.debug.ui/debug"));  //$NON-NLS-1$//$NON-NLS-2$
336
		JavaDebugOptionsManager.getDefault().startup();
342
		JavaDebugOptionsManager.getDefault().startup();
337
		ResourcesPlugin.getWorkspace().addSaveParticipant(this, new ISaveParticipant() {
343
		ResourcesPlugin.getWorkspace().addSaveParticipant(this, new ISaveParticipant() {
338
			public void doneSaving(ISaveContext context) {}
344
			public void doneSaving(ISaveContext context) {}
(-)ui/org/eclipse/jdt/internal/debug/ui/JavaDebugOptionsManager.java (+2 lines)
Lines 60-65 Link Here
60
import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaLogicalStructures;
60
import org.eclipse.jdt.internal.debug.core.logicalstructures.JavaLogicalStructures;
61
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
61
import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
62
import org.eclipse.jdt.internal.debug.ui.actions.JavaBreakpointPropertiesAction;
62
import org.eclipse.jdt.internal.debug.ui.actions.JavaBreakpointPropertiesAction;
63
import org.eclipse.jdt.internal.debug.ui.evaluation.EvaluationContextManager2;
63
import org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookLauncher;
64
import org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookLauncher;
64
import org.eclipse.jface.preference.IPreferenceStore;
65
import org.eclipse.jface.preference.IPreferenceStore;
65
import org.eclipse.jface.util.IPropertyChangeListener;
66
import org.eclipse.jface.util.IPropertyChangeListener;
Lines 199-204 Link Here
199
		debugPlugin.getLaunchManager().addLaunchListener(this);
200
		debugPlugin.getLaunchManager().addLaunchListener(this);
200
		debugPlugin.getBreakpointManager().addBreakpointListener(this);
201
		debugPlugin.getBreakpointManager().addBreakpointListener(this);
201
		EvaluationContextManager.startup();
202
		EvaluationContextManager.startup();
203
		EvaluationContextManager2.startup();
202
	}
204
	}
203
	
205
	
204
	/**
206
	/**
(-)plugin.xml (-26 / +95 lines)
Lines 113-144 Link Here
113
            label="%JDTDebugActionSet.label"
113
            label="%JDTDebugActionSet.label"
114
            visible="false"
114
            visible="false"
115
            id="org.eclipse.jdt.debug.ui.JDTDebugActionSet">
115
            id="org.eclipse.jdt.debug.ui.JDTDebugActionSet">
116
         <menu
117
               label="%RunMenu.label"
118
               path="additions"
119
               id="org.eclipse.ui.run">
120
            <separator
121
                  name="jdtGroup">
122
            </separator>
123
         </menu>
124
         <action
125
	           definitionId="org.eclipse.jdt.debug.ui.commands.AddClassPrepareBreakpoint"
126
               label="%classPrepareAction.label"
127
               icon="$nl$/icons/full/obj16/class_obj.gif"
128
               helpContextId="add_class_prepare_action_context"
129
               class="org.eclipse.jdt.internal.debug.ui.breakpoints.AddClassPrepareBreakpointAction"
130
               menubarPath="org.eclipse.ui.run/breakpointGroup"
131
               id="org.eclipse.jdt.debug.ui.actions.AddClassPrepareBreakpoint">
132
         </action>         
133
         <action
134
               definitionId="org.eclipse.jdt.debug.ui.commands.AddExceptionBreakpoint"
135
               label="%exceptionAction.accel.label"
136
               icon="$nl$/icons/full/elcl16/exc_catch.gif"
137
               helpContextId="add_exception_action_context"
138
               class="org.eclipse.jdt.internal.debug.ui.breakpoints.AddExceptionAction"
139
               menubarPath="org.eclipse.ui.run/breakpointGroup"
140
               id="org.eclipse.jdt.debug.ui.actions.AddExceptionBreakpoint">
141
         </action>
142
         <action
116
         <action
143
               definitionId="org.eclipse.jdt.debug.ui.commands.StepIntoSelection"
117
               definitionId="org.eclipse.jdt.debug.ui.commands.StepIntoSelection"
144
               label="%stepIntoSelectionAction.label"
118
               label="%stepIntoSelectionAction.label"
Lines 158-163 Link Here
158
                  </objectClass>
132
                  </objectClass>
159
               </and>
133
               </and>
160
            </enablement>
134
            </enablement>
135
         </action>            
136
         <action
137
	           definitionId="org.eclipse.jdt.debug.ui.commands.AddClassPrepareBreakpoint"
138
               label="%classPrepareAction.label"
139
               icon="$nl$/icons/full/obj16/class_obj.gif"
140
               helpContextId="add_class_prepare_action_context"
141
               class="org.eclipse.jdt.internal.debug.ui.breakpoints.AddClassPrepareBreakpointAction"
142
               menubarPath="org.eclipse.ui.run/breakpointGroup"
143
               id="org.eclipse.jdt.debug.ui.actions.AddClassPrepareBreakpoint">
144
         </action>         
145
         <action
146
               definitionId="org.eclipse.jdt.debug.ui.commands.AddExceptionBreakpoint"
147
               label="%exceptionAction.accel.label"
148
               icon="$nl$/icons/full/elcl16/exc_catch.gif"
149
               helpContextId="add_exception_action_context"
150
               class="org.eclipse.jdt.internal.debug.ui.breakpoints.AddExceptionAction"
151
               menubarPath="org.eclipse.ui.run/breakpointGroup"
152
               id="org.eclipse.jdt.debug.ui.actions.AddExceptionBreakpoint">
161
         </action>
153
         </action>
162
         <action
154
         <action
163
               id="org.eclipse.jdt.debug.ui.actions.Execute"
155
               id="org.eclipse.jdt.debug.ui.actions.Execute"
Lines 2288-2293 Link Here
2288
            description="%ActionDefinition.breakpointproperties.description"
2280
            description="%ActionDefinition.breakpointproperties.description"
2289
            id="org.eclipse.jdt.debug.ui.breakpoint.properties"
2281
            id="org.eclipse.jdt.debug.ui.breakpoint.properties"
2290
            name="%CommandDefinition.breakpointproperties.name">
2282
            name="%CommandDefinition.breakpointproperties.name">
2283
      </command>
2284
      <command
2285
            categoryId="org.eclipse.debug.ui.category.run"
2286
            description="%Command.description.ForceReturn"
2287
            id="org.eclipse.jdt.debug.ui.commands.ForceReturn"
2288
            name="%Command.name.ForceReturn">
2291
      </command> 
2289
      </command> 
2292
   </extension>
2290
   </extension>
2293
   <extension point="org.eclipse.ui.bindings">
2291
   <extension point="org.eclipse.ui.bindings">
Lines 2653-2658 Link Here
2653
            name="%ActionContext.breakpointsview.name"
2651
            name="%ActionContext.breakpointsview.name"
2654
            parentId="org.eclipse.ui.contexts.window">
2652
            parentId="org.eclipse.ui.contexts.window">
2655
      </context>
2653
      </context>
2654
      <context
2655
            id="org.eclipse.jdt.debug.ui.evaluation"
2656
            name="Java Debug Expression Evaluation"
2657
            >
2658
      </context>
2656
   </extension>
2659
   </extension>
2657
   <extension
2660
   <extension
2658
         point="org.eclipse.debug.ui.debugModelContextBindings">
2661
         point="org.eclipse.debug.ui.debugModelContextBindings">
Lines 2982-2987 Link Here
2982
    </updater>
2985
    </updater>
2983
 </extension>
2986
 </extension>
2984
 <extension
2987
 <extension
2988
       point="org.eclipse.ui.menus">
2989
    <menuContribution
2990
          locationURI="menu:org.eclipse.ui.run?after=profileGroup">
2991
       <separator
2992
             name="jdtGroup"
2993
             visible="true">
2994
       </separator>
2995
    </menuContribution>
2996
    <menuContribution
2997
          locationURI="menu:org.eclipse.debug.ui.DebugView?after=basic">
2998
       <separator
2999
             name="javaActions"
3000
             visible="true">
3001
       </separator>
3002
    </menuContribution>
3003
    <menuContribution
3004
          locationURI="menu:org.eclipse.ui.run?after=jdtGroup">
3005
       <command
3006
             commandId="org.eclipse.jdt.debug.ui.commands.ForceReturn"
3007
             style="push">
3008
       </command>
3009
    </menuContribution>
3010
 </extension>	
3011
 <extension
2985
       point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
3012
       point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
2986
    <hyperlinkDetector
3013
    <hyperlinkDetector
2987
          activate="true"
3014
          activate="true"
Lines 2993-2997 Link Here
2993
          targetId="org.eclipse.jdt.ui.javaCode">
3020
          targetId="org.eclipse.jdt.ui.javaCode">
2994
    </hyperlinkDetector>
3021
    </hyperlinkDetector>
2995
 </extension>
3022
 </extension>
3023
 <extension
3024
       point="org.eclipse.ui.handlers">
3025
    <handler
3026
          class="org.eclipse.jdt.internal.debug.ui.evaluation.ForceReturnHandler"
3027
          commandId="org.eclipse.jdt.debug.ui.commands.ForceReturn">
3028
       <activeWhen>
3029
 		  <with
3030
                variable="activePartId">
3031
                <not>
3032
                <equals
3033
                      value="org.eclipse.jdt.debug.ui.SnippetEditor">
3034
                </equals>
3035
                </not>
3036
          </with>
3037
       </activeWhen>
3038
       <enabledWhen>
3039
          <and>
3040
			<with variable="activeContexts">
3041
				<test
3042
					property="org.eclipse.jdt.debug.ui.contains"
3043
					value="org.eclipse.jdt.debug.ui.evaluation">
3044
				</test>
3045
			</with>
3046
			<with variable="selection">
3047
      <instanceof
3048
            value="org.eclipse.jface.text.ITextSelection">
3049
      </instanceof>
3050
			</with>
3051
          </and>       
3052
       </enabledWhen>
3053
    </handler>
3054
 </extension>
3055
 <extension
3056
       point="org.eclipse.core.expressions.propertyTesters">
3057
    <propertyTester
3058
          class="org.eclipse.jdt.internal.debug.ui.evaluation.EvaluationPropertyTester"
3059
          id="org.eclipse.jdt.debug.ui.evaluationPropertyTester"
3060
          namespace="org.eclipse.jdt.debug.ui"
3061
          properties="contains"
3062
          type="java.lang.Object">
3063
    </propertyTester>
3064
 </extension>
2996
    
3065
    
2997
</plugin>
3066
</plugin>
(-)plugin.properties (+3 lines)
Lines 29-34 Link Here
29
Display.label=Displa&y
29
Display.label=Displa&y
30
Display.tooltip=Display Result of Evaluating Selected Text
30
Display.tooltip=Display Result of Evaluating Selected Text
31
31
32
Command.name.ForceReturn=&Force Return
33
Command.description.ForceReturn=Returns the value of the selected expression from the current method
34
32
editStepFiltersAction.label=Edit Ste&p Filters...
35
editStepFiltersAction.label=Edit Ste&p Filters...
33
editStepFiltersAction.tooltip=Manage the set of defined step filters
36
editStepFiltersAction.tooltip=Manage the set of defined step filters
34
37
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 17-22 Link Here
17
 org.eclipse.jdt.internal.debug.ui.console;x-internal:=true,
17
 org.eclipse.jdt.internal.debug.ui.console;x-internal:=true,
18
 org.eclipse.jdt.internal.debug.ui.contentassist;x-internal:=true,
18
 org.eclipse.jdt.internal.debug.ui.contentassist;x-internal:=true,
19
 org.eclipse.jdt.internal.debug.ui.display;x-internal:=true,
19
 org.eclipse.jdt.internal.debug.ui.display;x-internal:=true,
20
 org.eclipse.jdt.internal.debug.ui.evaluation;x-internal:=true,
20
 org.eclipse.jdt.internal.debug.ui.heapwalking;x-internal:=true,
21
 org.eclipse.jdt.internal.debug.ui.heapwalking;x-internal:=true,
21
 org.eclipse.jdt.internal.debug.ui.jres;x-internal:=true,
22
 org.eclipse.jdt.internal.debug.ui.jres;x-internal:=true,
22
 org.eclipse.jdt.internal.debug.ui.launcher;x-internal:=true,
23
 org.eclipse.jdt.internal.debug.ui.launcher;x-internal:=true,
(-).options (+2 lines)
Added Link Here
1
org.eclipse.jdt.debug.ui/debug=false
2
org.eclipse.jdt.debug.ui/debug/evaluation/contextManager=false
(-)ui/org/eclipse/jdt/internal/debug/ui/evaluation/EvaluationContextManager2.java (+232 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.evaluation;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.jobs.Job;
22
import org.eclipse.debug.ui.DebugUITools;
23
import org.eclipse.debug.ui.contexts.DebugContextEvent;
24
import org.eclipse.debug.ui.contexts.IDebugContextListener;
25
import org.eclipse.debug.ui.contexts.IDebugContextProvider;
26
import org.eclipse.jdt.debug.core.IJavaStackFrame;
27
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
28
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPartSite;
32
import org.eclipse.ui.IWorkbenchWindow;
33
import org.eclipse.ui.contexts.IContextActivation;
34
import org.eclipse.ui.contexts.IContextService;
35
import org.eclipse.ui.progress.UIJob;
36
37
/**
38
 * @since 3.3
39
 */
40
public class EvaluationContextManager2 implements IDebugContextListener {
41
	
42
	/**
43
	 * Context that is enabled when there is a valid context for performing
44
	 * an expression evaluation.
45
	 */
46
	private static final String EVALUATION_CONTEXT_ID = "org.eclipse.jdt.debug.ui.evaluation"; //$NON-NLS-1$
47
	
48
	/**
49
	 * Debug flag for tracing information
50
	 */
51
	private static boolean DEBUG_EVALUATION_CONTEXT_MANAGER = false;
52
	
53
	static {
54
		DEBUG_EVALUATION_CONTEXT_MANAGER = JDIDebugUIPlugin.DEBUG && "true".equals( //$NON-NLS-1$
55
		 Platform.getDebugOption("org.eclipse.jdt.debug.ui/debug/evaluation/contextManager")); //$NON-NLS-1$
56
	}
57
58
	class UpdateJobFamily {
59
		public UpdateJobFamily(IWorkbenchWindow window) {
60
			fWindow = window;
61
		}
62
		public IWorkbenchWindow fWindow;
63
	}
64
	
65
	class UpdateContextJob extends Job {
66
67
		private DebugContextEvent fEvent;
68
		private IWorkbenchWindow fWindow;
69
		
70
		/**
71
		 * @param name
72
		 */
73
		public UpdateContextJob(DebugContextEvent event, IWorkbenchWindow window) {
74
			super("Update expression evaluation context"); //$NON-NLS-1$
75
			fEvent = event;
76
			fWindow = window;
77
			setSystem(true);
78
		}
79
		
80
		/* (non-Javadoc)
81
		 * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
82
		 */
83
		public boolean belongsTo(Object family) {
84
			if (family instanceof UpdateJobFamily) {
85
				UpdateJobFamily ujf = (UpdateJobFamily) family;
86
				return ujf.fWindow.equals(fWindow);
87
			}
88
			return false;
89
		}
90
91
		/* (non-Javadoc)
92
		 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
93
		 */
94
		protected IStatus run(IProgressMonitor monitor) {
95
			if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
96
				System.out.println("[Evaluation] Updating enablement"); //$NON-NLS-1$
97
			}
98
			boolean activate = false;
99
			if (!monitor.isCanceled()) {
100
				ISelection context = fEvent.getContext();
101
				if (context instanceof IStructuredSelection) {
102
					IStructuredSelection ss = (IStructuredSelection) context;
103
					Object firstElement = ss.getFirstElement();
104
					if (firstElement instanceof IAdaptable) {
105
						IAdaptable adaptable = (IAdaptable) firstElement;
106
						Object adapter = adaptable.getAdapter(IJavaStackFrame.class);
107
						if (adapter != null) {
108
							// TODO: scrap book
109
							activate = true;
110
						}
111
					}
112
				}
113
			}
114
			IContextService service = (IContextService) fWindow.getService(IContextService.class);
115
			if (service != null) {
116
				if (activate) {
117
					if (!service.getActiveContextIds().contains(EVALUATION_CONTEXT_ID)) {
118
						if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
119
							System.out.println("[Evaluation]\tSchedule activation"); //$NON-NLS-1$
120
						}
121
						Job job = new PerformActivation(service);
122
						job.schedule();
123
					} else {
124
						if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
125
							System.out.println("[Evaluation]\tStill enabled"); //$NON-NLS-1$
126
						}
127
					}
128
				} else {
129
					IContextActivation activation = (IContextActivation) fActivations.remove(service);
130
					if (activation != null) {
131
						if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
132
							System.out.println("[Evaluation]\tSchedule deactivation"); //$NON-NLS-1$
133
						}
134
						Job job = new PerformDeactivation(activation);
135
						job.schedule();
136
					} else {
137
						if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
138
							System.out.println("[Evaluation]\tStill deactivated"); //$NON-NLS-1$
139
						}
140
					}
141
				}
142
			}
143
			return Status.OK_STATUS;
144
		}
145
		
146
	}
147
	
148
	/**
149
	 * Map of context activations per service
150
	 */
151
	private Map fActivations = new HashMap();
152
	
153
	class PerformActivation extends UIJob {
154
155
		private IContextService fService;
156
		
157
		/**
158
		 * @param name
159
		 */
160
		public PerformActivation(IContextService service) {
161
			super("Activate evaluation context"); //$NON-NLS-1$
162
			fService = service;
163
			setSystem(true);
164
		}
165
166
		/* (non-Javadoc)
167
		 * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
168
		 */
169
		public IStatus runInUIThread(IProgressMonitor monitor) {
170
			if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
171
				System.out.println("[Evaluation] Activate " + EVALUATION_CONTEXT_ID); //$NON-NLS-1$
172
			}
173
			IContextActivation activation = fService.activateContext(EVALUATION_CONTEXT_ID);
174
			fActivations.put(fService, activation);
175
			return Status.OK_STATUS;
176
		}
177
		
178
	}
179
	
180
	class PerformDeactivation extends UIJob {
181
182
		private IContextActivation fActivation;
183
		
184
		/**
185
		 * @param name
186
		 */
187
		public PerformDeactivation(IContextActivation activation) {
188
			super("Deactivate evaluation context"); //$NON-NLS-1$
189
			fActivation = activation;
190
			setSystem(true);
191
		}
192
193
		/* (non-Javadoc)
194
		 * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
195
		 */
196
		public IStatus runInUIThread(IProgressMonitor monitor) {
197
			if (DEBUG_EVALUATION_CONTEXT_MANAGER) {
198
				System.out.println("Evaluation] Deactivate " + EVALUATION_CONTEXT_ID); //$NON-NLS-1$
199
			}
200
			fActivation.getContextService().deactivateContext(fActivation);
201
			return Status.OK_STATUS;
202
		}
203
		
204
	}	
205
	
206
	/* (non-Javadoc)
207
	 * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
208
	 */
209
	public void debugContextChanged(DebugContextEvent event) {
210
		if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
211
			IDebugContextProvider provider = (IDebugContextProvider) event.getSource();
212
			IWorkbenchPart part = provider.getPart();
213
			if (part != null) {
214
				IWorkbenchPartSite site = part.getSite();
215
				if (site != null) {
216
					IWorkbenchWindow window = site.getWorkbenchWindow();
217
					if (window != null) {
218
						Job.getJobManager().cancel(new UpdateJobFamily(window));
219
						Job job = new UpdateContextJob(event, window);
220
						job.schedule(100);
221
					}
222
				}
223
			}
224
		}
225
	}
226
	
227
	public static void startup() {
228
		EvaluationContextManager2 manager = new EvaluationContextManager2();
229
		DebugUITools.getDebugContextManager().addDebugContextListener(manager);
230
	}
231
232
}
(-)ui/org/eclipse/jdt/internal/debug/ui/evaluation/ForceReturnHandler.java (+252 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.evaluation;
12
13
import java.lang.reflect.InvocationTargetException;
14
15
import org.eclipse.core.commands.AbstractHandler;
16
import org.eclipse.core.commands.ExecutionEvent;
17
import org.eclipse.core.commands.ExecutionException;
18
import org.eclipse.core.expressions.EvaluationContext;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.Status;
25
import org.eclipse.debug.core.DebugEvent;
26
import org.eclipse.debug.core.DebugException;
27
import org.eclipse.debug.core.ILaunch;
28
import org.eclipse.debug.core.model.ISourceLocator;
29
import org.eclipse.debug.core.model.IStackFrame;
30
import org.eclipse.debug.ui.DebugUITools;
31
import org.eclipse.debug.ui.contexts.IDebugContextService;
32
import org.eclipse.jdt.core.IJavaElement;
33
import org.eclipse.jdt.core.IJavaProject;
34
import org.eclipse.jdt.core.JavaCore;
35
import org.eclipse.jdt.core.Signature;
36
import org.eclipse.jdt.debug.core.IJavaDebugTarget;
37
import org.eclipse.jdt.debug.core.IJavaStackFrame;
38
import org.eclipse.jdt.debug.core.IJavaThread;
39
import org.eclipse.jdt.debug.core.JDIDebugModel;
40
import org.eclipse.jdt.debug.eval.IEvaluationEngine;
41
import org.eclipse.jdt.debug.eval.IEvaluationListener;
42
import org.eclipse.jdt.debug.eval.IEvaluationResult;
43
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
44
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
45
import org.eclipse.jdt.internal.debug.ui.actions.ActionMessages;
46
import org.eclipse.jdt.internal.debug.ui.actions.EvaluateAction;
47
import org.eclipse.jface.operation.IRunnableWithProgress;
48
import org.eclipse.jface.text.ITextSelection;
49
import org.eclipse.jface.viewers.ISelection;
50
import org.eclipse.jface.viewers.IStructuredSelection;
51
import org.eclipse.swt.widgets.Display;
52
import org.eclipse.ui.ISources;
53
import org.eclipse.ui.IWorkbench;
54
import org.eclipse.ui.IWorkbenchWindow;
55
import org.eclipse.ui.PlatformUI;
56
57
/**
58
 * @since 3.3
59
 */
60
public class ForceReturnHandler extends AbstractHandler implements IEvaluationListener {
61
62
	public ForceReturnHandler() {
63
		System.out.println("CREATED");
64
		System.out.println(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
65
	}
66
	
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
69
	 */
70
	public Object execute(ExecutionEvent event) throws ExecutionException {
71
		ISelection selection = getSelection(event);
72
		if (selection instanceof ITextSelection) {
73
			ITextSelection textSelection = (ITextSelection) selection;
74
			Object debugContext = getDebugContext(event);
75
			if (debugContext instanceof IAdaptable) {
76
				IJavaStackFrame frame = (IJavaStackFrame) ((IAdaptable)debugContext).getAdapter(IJavaStackFrame.class);
77
				if (frame != null) {
78
					IJavaThread thread = (IJavaThread) frame.getThread();
79
					IJavaDebugTarget target = (IJavaDebugTarget) frame.getDebugTarget();
80
					try {
81
						String signature = frame.getSignature();
82
						String returnType = Signature.getReturnType(signature);
83
						if (Signature.SIG_VOID.equals(returnType)) {
84
							thread.forceReturn(target.voidValue());
85
						} else {
86
							evaluate(textSelection.getText(), frame, this);
87
						}
88
					} catch (DebugException e) {
89
						// TODO Auto-generated catch block
90
						e.printStackTrace();
91
					}
92
				}
93
			}
94
		}
95
		return null;
96
	}
97
98
	public void dispose() {
99
		System.out.println("DISPOSED");
100
		super.dispose();
101
	}
102
	
103
	/**
104
	 * Returns the active debug context for the given execution event.
105
	 * 
106
	 * @param event execution event
107
	 * @return active debug context or <code>null</code>
108
	 */
109
	protected Object getDebugContext(ExecutionEvent event) {
110
		Object context = event.getApplicationContext();
111
		if (context instanceof EvaluationContext) {
112
			EvaluationContext ec = (EvaluationContext) context;
113
			Object variable = ec.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);
114
			if (variable instanceof IWorkbenchWindow) {
115
				IWorkbenchWindow window = (IWorkbenchWindow) variable;
116
				IDebugContextService contextService = DebugUITools.getDebugContextManager().getContextService(window);
117
				ISelection debugContext = contextService.getActiveContext();
118
				if (debugContext instanceof IStructuredSelection) {
119
					IStructuredSelection ss = (IStructuredSelection) debugContext;
120
					return ss.getFirstElement();
121
				}
122
			}
123
		}
124
		return null;
125
	}
126
	
127
	/**
128
	 * Returns the current selection for the given execution event or <code>null</code>.
129
	 * 
130
	 * @param event execution event
131
	 * @return current selection or <code>null</code>
132
	 */
133
	protected ISelection getSelection(ExecutionEvent event) {
134
		Object context = event.getApplicationContext();
135
		if (context instanceof EvaluationContext) {
136
			EvaluationContext ec = (EvaluationContext) context;
137
			Object variable = ec.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
138
			if (variable instanceof ISelection) {
139
				return (ISelection)variable;
140
			}
141
		}
142
		return null;
143
	}	
144
	
145
	protected void reportError(String message) {
146
		Status status= new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, message, null);
147
		JDIDebugUIPlugin.statusDialog(status); 
148
	}
149
	
150
	protected void evaluate(final String expression, final IJavaStackFrame frame, final IEvaluationListener listener) {
151
		if (frame == null) {
152
			reportError(ActionMessages.Evaluate_error_message_stack_frame_context); 
153
			return;
154
		}
155
		
156
		// check for nested evaluation
157
		IJavaThread thread = (IJavaThread)frame.getThread();
158
		if (thread.isPerformingEvaluation()) {
159
			reportError(ActionMessages.EvaluateAction_Cannot_perform_nested_evaluations__1); 
160
			return;
161
		}
162
        
163
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
164
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
165
                if (frame.isSuspended()) {
166
                    IJavaElement javaElement= getJavaElement(frame);
167
                    if (javaElement != null) {
168
                        IJavaProject project = javaElement.getJavaProject();
169
                        IEvaluationEngine engine = null;
170
                        try {                            
171
                            engine = JDIDebugPlugin.getDefault().getEvaluationEngine(project, (IJavaDebugTarget)frame.getDebugTarget());
172
                            boolean hitBreakpoints= JDIDebugModel.getPreferences().getBoolean(JDIDebugModel.PREF_SUSPEND_FOR_BREAKPOINTS_DURING_EVALUATION);
173
                            engine.evaluate(expression, frame, listener, DebugEvent.EVALUATION, hitBreakpoints);
174
                            return;
175
                        } catch (CoreException e) {
176
                            throw new InvocationTargetException(e, EvaluateAction.getExceptionMessage(e));
177
                        }
178
                    }
179
                    throw new InvocationTargetException(null, ActionMessages.Evaluate_error_message_src_context); 
180
                }
181
                // thread not suspended
182
                throw new InvocationTargetException(null, ActionMessages.EvaluateAction_Thread_not_suspended___unable_to_perform_evaluation__1); 
183
            }
184
        };
185
        
186
        IWorkbench workbench = JDIDebugUIPlugin.getDefault().getWorkbench();
187
        try {
188
            workbench.getProgressService().busyCursorWhile(runnable);
189
        } catch (InvocationTargetException e) {
190
        	String message = e.getMessage();
191
        	if (message == null) {
192
        		message = e.getClass().getName();
193
        		if (e.getCause() != null) {
194
        			message = e.getCause().getClass().getName();
195
        			if (e.getCause().getMessage() != null) {
196
        				message = e.getCause().getMessage();
197
        			}
198
        		}
199
        	}
200
            reportError(message);
201
        } catch (InterruptedException e) {
202
        }		
203
	}
204
205
	protected IJavaElement getJavaElement(IStackFrame stackFrame) {
206
		
207
		// Get the corresponding element.
208
		ILaunch launch = stackFrame.getLaunch();
209
		if (launch == null) {
210
			return null;
211
		}
212
		ISourceLocator locator= launch.getSourceLocator();
213
		if (locator == null)
214
			return null;
215
		
216
		Object sourceElement = locator.getSourceElement(stackFrame);
217
		if (sourceElement instanceof IJavaElement) {
218
			return (IJavaElement) sourceElement;
219
		} else if (sourceElement instanceof IResource) {
220
			IJavaProject project = JavaCore.create(((IResource)sourceElement).getProject());
221
			if (project.exists()) {
222
				return project;
223
			}
224
		}			
225
		return null;
226
	}
227
228
	/* (non-Javadoc)
229
	 * @see org.eclipse.jdt.debug.eval.IEvaluationListener#evaluationComplete(org.eclipse.jdt.debug.eval.IEvaluationResult)
230
	 */
231
	public void evaluationComplete(IEvaluationResult result) {
232
		// if plug-in has shutdown, ignore - see bug# 8693
233
		if (JDIDebugUIPlugin.getDefault() == null) {
234
			return;
235
		}
236
		final Display display= JDIDebugUIPlugin.getStandardDisplay();
237
		if (display.isDisposed()) {
238
			return;
239
		}
240
		
241
		if (result.hasErrors()) {
242
			
243
		} else {
244
			try {
245
				result.getThread().forceReturn(result.getValue());
246
			} catch (DebugException e) {
247
				// TODO Auto-generated catch block
248
				e.printStackTrace();
249
			}
250
		}
251
	}
252
}
(-)ui/org/eclipse/jdt/internal/debug/ui/evaluation/EvaluationPropertyTester.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.jdt.internal.debug.ui.evaluation;
12
13
import java.util.Collection;
14
15
import org.eclipse.core.expressions.PropertyTester;
16
17
/**
18
 * @since 3.3
19
 */
20
public class EvaluationPropertyTester extends PropertyTester {
21
	
22
	/**
23
	 * Tests for containment in a collection
24
	 */
25
	public static final String PROP_CONTAINS = "contains"; //$NON-NLS-1$
26
27
	public EvaluationPropertyTester() {
28
	}
29
30
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
31
		if (PROP_CONTAINS.equals(property)) {
32
			if (receiver instanceof Collection) {
33
				Collection collection = (Collection) receiver;
34
				return collection.contains(expectedValue);
35
			}
36
		}
37
		return false;
38
	}
39
40
}

Return to bug 150652