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 112630
Collapse All | Expand All

(-)plugin.xml (-1 / +12 lines)
Lines 2914-2919 Link Here
2914
          id="org.eclipse.jdt.debug.ui.bpMarkerUpdater"
2914
          id="org.eclipse.jdt.debug.ui.bpMarkerUpdater"
2915
          markerType="org.eclipse.debug.core.breakpointMarker">
2915
          markerType="org.eclipse.debug.core.breakpointMarker">
2916
    </updater>
2916
    </updater>
2917
 </extension>	
2917
 </extension>
2918
 <extension
2919
       point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
2920
    <hyperlinkDetector
2921
          activate="true"
2922
          class="org.eclipse.jdt.internal.debug.ui.actions.StepIntoSelectionHyperlinkDetector"
2923
          description="%stepIntoSelectionHyperlinkDetector.description"
2924
          id="org.eclipse.jdt.debug.ui.hyperlinkdetector.stepIntoSelection"
2925
          name="%stepIntoSelectionHyperlinkDetector.label"
2926
          targetId="org.eclipse.jdt.ui.javaCode">
2927
    </hyperlinkDetector>
2928
 </extension>
2918
    
2929
    
2919
</plugin>
2930
</plugin>
(-)plugin.properties (+2 lines)
Lines 156-161 Link Here
156
showNullEntriesAction.tooltip=Show Null Array Entries
156
showNullEntriesAction.tooltip=Show Null Array Entries
157
157
158
stepIntoSelectionAction.label=Step &Into Selection
158
stepIntoSelectionAction.label=Step &Into Selection
159
stepIntoSelectionHyperlinkDetector.label=Step Into Selection
160
stepIntoSelectionHyperlinkDetector.description=Performs the step into selection command on demand via a hyperlink
159
161
160
suspendPolicy.label=&Suspend VM
162
suspendPolicy.label=&Suspend VM
161
suspendPolicy.tooltip=Changes the suspend policy of the selected breakpoint(s)
163
suspendPolicy.tooltip=Changes the suspend policy of the selected breakpoint(s)
(-)ui/org/eclipse/jdt/internal/debug/ui/actions/StepIntoSelectionActionDelegate.java (-75 / +40 lines)
Lines 21-43 Link Here
21
import org.eclipse.debug.core.model.IStackFrame;
21
import org.eclipse.debug.core.model.IStackFrame;
22
import org.eclipse.debug.core.model.IThread;
22
import org.eclipse.debug.core.model.IThread;
23
import org.eclipse.debug.ui.actions.IRunToLineTarget;
23
import org.eclipse.debug.ui.actions.IRunToLineTarget;
24
import org.eclipse.jdt.core.IClassFile;
25
import org.eclipse.jdt.core.ICodeAssist;
26
import org.eclipse.jdt.core.IJavaElement;
27
import org.eclipse.jdt.core.IMember;
24
import org.eclipse.jdt.core.IMember;
28
import org.eclipse.jdt.core.IMethod;
25
import org.eclipse.jdt.core.IMethod;
29
import org.eclipse.jdt.core.IType;
26
import org.eclipse.jdt.core.IType;
27
import org.eclipse.jdt.core.JavaModelException;
30
import org.eclipse.jdt.debug.core.IJavaStackFrame;
28
import org.eclipse.jdt.debug.core.IJavaStackFrame;
31
import org.eclipse.jdt.debug.core.IJavaThread;
29
import org.eclipse.jdt.debug.core.IJavaThread;
32
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
33
import org.eclipse.jdt.internal.debug.ui.EvaluationContextManager;
30
import org.eclipse.jdt.internal.debug.ui.EvaluationContextManager;
34
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
31
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
35
import org.eclipse.jdt.ui.JavaUI;
36
import org.eclipse.jface.action.IAction;
32
import org.eclipse.jface.action.IAction;
37
import org.eclipse.jface.text.ITextSelection;
33
import org.eclipse.jface.text.ITextSelection;
38
import org.eclipse.jface.viewers.ISelection;
34
import org.eclipse.jface.viewers.ISelection;
39
import org.eclipse.ui.IEditorActionDelegate;
35
import org.eclipse.ui.IEditorActionDelegate;
40
import org.eclipse.ui.IEditorInput;
41
import org.eclipse.ui.IEditorPart;
36
import org.eclipse.ui.IEditorPart;
42
import org.eclipse.ui.IWorkbenchWindow;
37
import org.eclipse.ui.IWorkbenchWindow;
43
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
38
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
Lines 55-66 Link Here
55
	 * The name of the type being "run to".
50
	 * The name of the type being "run to".
56
	 * @see StepIntoSelectionActionDelegate#runToLineBeforeStepIn(ITextSelection, IJavaStackFrame, IMethod)
51
	 * @see StepIntoSelectionActionDelegate#runToLineBeforeStepIn(ITextSelection, IJavaStackFrame, IMethod)
57
	 */
52
	 */
58
	private String runToLineType= null;
53
	private String fRunToLineType= null;
59
	/**
54
	/**
60
	 * The line number being "run to."
55
	 * The line number being "run to."
61
	 * @see StepIntoSelectionActionDelegate#runToLineBeforeStepIn(ITextSelection, IJavaStackFrame, IMethod)
56
	 * @see StepIntoSelectionActionDelegate#runToLineBeforeStepIn(ITextSelection, IJavaStackFrame, IMethod)
62
	 */
57
	 */
63
	private int runToLineLine= -1;
58
	private int fRunToLineLine= -1;
64
	/**
59
	/**
65
	 * The debug event list listener used to know when a run to line has finished.
60
	 * The debug event list listener used to know when a run to line has finished.
66
	 * @see StepIntoSelectionActionDelegate#runToLineBeforeStepIn(ITextSelection, IJavaStackFrame, IMethod)
61
	 * @see StepIntoSelectionActionDelegate#runToLineBeforeStepIn(ITextSelection, IJavaStackFrame, IMethod)
Lines 76-88 Link Here
76
			// no longer suspended - unexpected
71
			// no longer suspended - unexpected
77
			return;
72
			return;
78
		}
73
		}
79
		ITextSelection textSelection= getTextSelection();
74
		ITextSelection textSelection = getTextSelection();
80
		IMethod method= getMethod();
81
		IType callingType= getType();
82
		if (method == null || callingType == null) {
83
			return;
84
		}
85
		try {
75
		try {
76
			IMethod method = StepIntoSelectionUtils.getMethod(getTextSelection(),StepIntoSelectionUtils.getJavaElement(getActiveEditor().getEditorInput()));
77
			IType callingType = getType();
78
			if (method == null || callingType == null) {
79
				return;
80
			}
86
			int lineNumber = frame.getLineNumber();
81
			int lineNumber = frame.getLineNumber();
87
            String callingTypeName = stripInnerNames(callingType.getFullyQualifiedName());
82
            String callingTypeName = stripInnerNames(callingType.getFullyQualifiedName());
88
            String frameName = stripInnerNames(frame.getDeclaringTypeName());
83
            String frameName = stripInnerNames(frame.getDeclaringTypeName());
Lines 94-118 Link Here
94
				runToLineBeforeStepIn(textSelection, frame.getThread(), method);
89
				runToLineBeforeStepIn(textSelection, frame.getThread(), method);
95
				return;
90
				return;
96
			}
91
			}
97
		} catch (DebugException e) {
92
		} 
93
		catch (DebugException e) {
98
			showErrorMessage(e.getStatus().getMessage());
94
			showErrorMessage(e.getStatus().getMessage());
99
			return;
95
			return;
100
		}
96
		}
97
		catch(JavaModelException jme) {
98
			showErrorMessage(jme.getStatus().getMessage());
99
			return;
100
		}
101
	}
101
	}
102
103
    /**
104
     * Strips inner class names from the given type name.
105
     * 
106
     * @param fullyQualifiedName
107
     */
108
    private String stripInnerNames(String fullyQualifiedName) {
109
        // ignore inner class qualification, as the compiler generated names and java model names can be different
110
        int index = fullyQualifiedName.indexOf('$');
111
        if (index > 0) {
112
            return fullyQualifiedName.substring(0, index);
113
        }
114
        return fullyQualifiedName;
115
    }
116
	
102
	
117
	/**
103
	/**
118
	 * Steps into the given method in the given stack frame
104
	 * Steps into the given method in the given stack frame
Lines 140-151 Link Here
140
	 * the desired location, then perform a "step into selection."
126
	 * the desired location, then perform a "step into selection."
141
	 */
127
	 */
142
	private void runToLineBeforeStepIn(ITextSelection textSelection, final IThread thread, final IMethod method) {
128
	private void runToLineBeforeStepIn(ITextSelection textSelection, final IThread thread, final IMethod method) {
143
		runToLineType= getType().getFullyQualifiedName();
129
		fRunToLineType = getType().getFullyQualifiedName();
144
		runToLineLine= textSelection.getStartLine() + 1;
130
		fRunToLineLine = textSelection.getStartLine() + 1;
145
		if (runToLineType == null || runToLineLine == -1) {
131
		if (fRunToLineType == null || fRunToLineLine == -1) {
146
			return;
132
			return;
147
		}
133
		}
148
		// see bug 65489 - get the run-to-line adapater from the editor
134
		// see bug 65489 - get the run-to-line adapter from the editor
149
		IRunToLineTarget runToLineAction = null;
135
		IRunToLineTarget runToLineAction = null;
150
		IEditorPart ed = getActiveEditor();
136
		IEditorPart ed = getActiveEditor();
151
		if (ed != null) {
137
		if (ed != null) {
Lines 217-224 Link Here
217
			 */
203
			 */
218
			private boolean isExpectedFrame(IJavaStackFrame frame) throws DebugException {
204
			private boolean isExpectedFrame(IJavaStackFrame frame) throws DebugException {
219
				return frame != null &&
205
				return frame != null &&
220
					runToLineLine == frame.getLineNumber() &&
206
					fRunToLineLine == frame.getLineNumber() &&
221
					frame.getReceivingTypeName().equals(runToLineType);
207
					frame.getReceivingTypeName().equals(fRunToLineType);
222
			}
208
			}
223
			/**
209
			/**
224
			 * When the debug target we're listening for terminates, stop listening
210
			 * When the debug target we're listening for terminates, stop listening
Lines 242-247 Link Here
242
		}
228
		}
243
	}
229
	}
244
	
230
	
231
	/**
232
	 * Gets the current text selection from the currently active editor
233
	 * @return the current text selection
234
	 */
245
	private ITextSelection getTextSelection() {
235
	private ITextSelection getTextSelection() {
246
		IEditorPart part = getActiveEditor();
236
		IEditorPart part = getActiveEditor();
247
		if (part instanceof ITextEditor) { 
237
		if (part instanceof ITextEditor) { 
Lines 252-293 Link Here
252
		return null;
242
		return null;
253
	}
243
	}
254
	
244
	
255
	private IMethod getMethod() {
256
		ITextSelection textSelection= getTextSelection();
257
		IEditorInput input = getActiveEditor().getEditorInput();
258
		ICodeAssist codeAssist = null;
259
		Object element = JavaUI.getWorkingCopyManager().getWorkingCopy(input);
260
		if (element == null) {
261
			element = input.getAdapter(IClassFile.class);
262
		}
263
		if (element instanceof ICodeAssist) {
264
			codeAssist = ((ICodeAssist)element);
265
		} else {
266
			// editor does not support code assist
267
			showErrorMessage(ActionMessages.StepIntoSelectionActionDelegate_Step_into_selection_only_available_for_types_in_Java_projects__1); 
268
			return null;
269
		}
270
		
271
		IMethod method = null;
272
		try {
273
			IJavaElement[] resolve = codeAssist.codeSelect(textSelection.getOffset(), 0);
274
			for (int i = 0; i < resolve.length; i++) {
275
				IJavaElement javaElement = resolve[i];
276
				if (javaElement instanceof IMethod) {
277
					method = (IMethod)javaElement;
278
					break;
279
				}
280
			}
281
		} catch (CoreException e) {
282
			JDIDebugPlugin.log(e);
283
		}
284
		if (method == null) {
285
			// no resolved method
286
			showErrorMessage(ActionMessages.StepIntoSelectionActionDelegate_No_Method); 
287
		}
288
		return method;
289
	}
290
	
291
	/**
245
	/**
292
	 * Return the type containing the selected text, or <code>null</code> if the
246
	 * Return the type containing the selected text, or <code>null</code> if the
293
	 * selection is not in a type.
247
	 * selection is not in a type.
Lines 303-310 Link Here
303
		return type;
257
		return type;
304
	}	
258
	}	
305
	
259
	
306
307
308
	/**
260
	/**
309
	 * Displays an error message in the status area
261
	 * Displays an error message in the status area
310
	 * 
262
	 * 
Lines 343-348 Link Here
343
	}
295
	}
344
296
345
	/**
297
	/**
298
     * Strips inner class names from the given type name.
299
     * 
300
     * @param fullyQualifiedName
301
     */
302
    private String stripInnerNames(String fullyQualifiedName) {
303
        // ignore inner class qualification, as the compiler generated names and java model names can be different
304
        int index = fullyQualifiedName.indexOf('$');
305
        if (index > 0) {
306
            return fullyQualifiedName.substring(0, index);
307
        }
308
        return fullyQualifiedName;
309
    }
310
	
311
	/**
346
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
312
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
347
	 */
313
	 */
348
	public void selectionChanged(IAction action, ISelection selection) {
314
	public void selectionChanged(IAction action, ISelection selection) {
Lines 360-367 Link Here
360
	/**
326
	/**
361
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
327
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
362
	 */
328
	 */
363
	public void dispose() {
329
	public void dispose() {}
364
	}
365
330
366
	/**
331
	/**
367
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
332
	 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
(-)ui/org/eclipse/jdt/internal/debug/ui/actions/StepIntoSelectionHyperlinkDetector.java (+105 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.actions;
12
13
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IMethod;
15
import org.eclipse.jdt.core.JavaModelException;
16
import org.eclipse.jdt.internal.debug.ui.EvaluationContextManager;
17
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18
import org.eclipse.jdt.internal.debug.ui.JavaWordFinder;
19
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.jface.text.ITextViewer;
22
import org.eclipse.jface.text.TextSelection;
23
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
24
import org.eclipse.jface.text.hyperlink.IHyperlink;
25
import org.eclipse.ui.IEditorInput;
26
import org.eclipse.ui.texteditor.ITextEditor;
27
28
/**
29
 * This is a specialization of a hyperlink detector for the step into selection command
30
 * 
31
 * @since 3.3
32
 */
33
public class StepIntoSelectionHyperlinkDetector extends AbstractHyperlinkDetector {
34
	
35
	/**
36
	 * Specific implementation of a hyperlink for step into command
37
	 */
38
	class StepIntoSelectionHyperlink implements IHyperlink {
39
		
40
		private IRegion fRegion = null;
41
		
42
		/**
43
		 * Constructor
44
		 * @param region
45
		 */
46
		public StepIntoSelectionHyperlink(IRegion region) {
47
			fRegion = region;
48
		}
49
		/**
50
		 * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion()
51
		 */
52
		public IRegion getHyperlinkRegion() {
53
			return fRegion;
54
		}
55
		/**
56
		 * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText()
57
		 */
58
		public String getHyperlinkText() {
59
			return null;
60
		}
61
		/**
62
		 * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel()
63
		 */
64
		public String getTypeLabel() {
65
			return null;
66
		}
67
		/**
68
		 * @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
69
		 */
70
		public void open() {
71
			StepIntoSelectionActionDelegate delegate = new StepIntoSelectionActionDelegate();
72
			delegate.init(JDIDebugUIPlugin.getActiveWorkbenchWindow());
73
			delegate.run(null);
74
		}
75
		
76
	}
77
78
	/**
79
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
80
	 */
81
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
82
		ITextEditor editor = (ITextEditor) getAdapter(ITextEditor.class);
83
		if(editor != null && !canShowMultipleHyperlinks && EvaluationContextManager.getEvaluationContext(JDIDebugUIPlugin.getActiveWorkbenchWindow()) != null) {
84
			IEditorInput input = editor.getEditorInput();
85
			IJavaElement element = StepIntoSelectionUtils.getJavaElement(input);
86
			int offset = region.getOffset();
87
			if(element != null) {
88
				try {
89
					IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
90
					if(document != null) {
91
						IRegion wregion = JavaWordFinder.findWord(document, offset);
92
						if(wregion != null) {
93
							IMethod method = StepIntoSelectionUtils.getMethod(new TextSelection(document, wregion.getOffset(), wregion.getLength()), element);
94
							if (method != null) {
95
								return new IHyperlink[] {new StepIntoSelectionHyperlink(wregion)};
96
							}
97
						}
98
					}
99
				}
100
				catch(JavaModelException jme) {JDIDebugUIPlugin.log(jme);}
101
			}
102
		}
103
		return null;
104
	}
105
}
(-)ui/org/eclipse/jdt/internal/debug/ui/actions/StepIntoSelectionUtils.java (+64 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.actions;
12
13
import org.eclipse.jdt.core.ICodeAssist;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IMethod;
16
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.ui.JavaUI;
18
import org.eclipse.jface.text.ITextSelection;
19
import org.eclipse.ui.IEditorInput;
20
21
/**
22
 * Utility class for aiding step into selection actions and hyper-linking
23
 * 
24
 * @see StepIntoSelectionActionDelegate
25
 * @see StepIntoSelectionHyperlinkDetector
26
 * 
27
 * @since 3.3
28
 */
29
public class StepIntoSelectionUtils {
30
31
	
32
	/**
33
     * gets the <code>IJavaElement</code> from the editor input
34
     * @param input the current editor input
35
     * @return the corresponding <code>IJavaElement</code>
36
     */
37
    public static IJavaElement getJavaElement(IEditorInput input) {
38
    	IJavaElement je = JavaUI.getEditorInputJavaElement(input);
39
    	if(je != null) {
40
    		return je;
41
    	}
42
    	return JavaUI.getWorkingCopyManager().getWorkingCopy(input);
43
    }
44
    
45
    /**
46
     * Returns the <code>IMethod</code> from the given selection within the given <code>IJavaElement</code>, 
47
     * or <code>null</code> if the selection does not container or is not an <code>IMethod</code>
48
     * @param selection
49
     * @param element
50
     * @return the corresponding <code>IMethod</code> from the selection within the provided <code>IJavaElement</code>
51
     * @throws JavaModelException
52
     */
53
    public static IMethod getMethod(ITextSelection selection, IJavaElement element) throws JavaModelException {
54
    	if(element != null && element instanceof ICodeAssist) {
55
    		IJavaElement[] elements = ((ICodeAssist)element).codeSelect(selection.getOffset(), selection.getLength());
56
			for (int i = 0; i < elements.length; i++) {
57
				if (elements[i] instanceof IMethod) {
58
					return (IMethod)elements[i];
59
				}
60
			}
61
    	}
62
    	return null;
63
    }
64
}

Return to bug 112630