1 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 29 public class StepIntoSelectionUtils { 30 31 32 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 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 } 65 | Popular Tags |