|
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) |