/** * Finds and returns the Java elements for the given editor selection. * * @param editor the Java editor * @param selection the text selection * @return the Java elements for the given editor selection * @throws JavaModelException if accessing the type root fails */ public static IJavaElement[] codeResolve(JavaEditor editor, ITextSelection selection) throws JavaModelException { return codeResolve(getInput(editor), selection); }
/** * Finds and returns the Java element that contains the text selection in the given editor. * * @param editor the Java editor * @param selection the text selection * @return the Java elements for the given editor selection * @throws JavaModelException if accessing the type root fails */ public static IJavaElement getElementAtOffset(JavaEditor editor, ITextSelection selection) throws JavaModelException { return getElementAtOffset(getInput(editor), selection); }
/** * Finds and returns the Java element selected in the given part. * * @param part the workbench part for which to find the selected Java element * @param selection the selection * @return the selected Java element */ protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) { Object element; try { if (part instanceof JavaEditor && selection instanceof ITextSelection) { IJavaElement[] elements= TextSelectionConverter.codeResolve((JavaEditor)part, (ITextSelection)selection); if (elements != null && elements.length > 0) return elements[0]; else return null; } else if (selection instanceof IStructuredSelection) { element= SelectionUtil.getSingleElement(selection); } else { return null; } } catch (JavaModelException e) { return null; } return findJavaElement(element); }
protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) { IJavaElement element; try { element= super.findSelectedJavaElement(part, selection); if (element == null && part instanceof JavaEditor && selection instanceof ITextSelection) { JavaEditor editor= (JavaEditor)part; ITextSelection textSelection= (ITextSelection)selection; IDocumentProvider documentProvider= editor.getDocumentProvider(); if (documentProvider == null) return null; IDocument document= documentProvider.getDocument(editor.getEditorInput()); if (document == null) return null; ITypedRegion typedRegion= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, textSelection.getOffset(), false); if (IJavaPartitions.JAVA_DOC.equals(typedRegion.getType())) return TextSelectionConverter.getElementAtOffset((JavaEditor)part, textSelection); else return null; } else return element; } catch (JavaModelException e) { return null; } catch (BadLocationException e) { return null; } }
if (part instanceof JavaEditor && selection instanceof ITextSelection) { JavaEditor editor = (JavaEditor)part; IJavaElement[] elements= TextSelectionConverter.codeResolve(editor, (ITextSelection)selection); if (elements != null && elements.length > 0) { return elements[0];
ITypedRegion typedRegion= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, textSelection.getOffset(), false); if (IJavaPartitions.JAVA_DOC.equals(typedRegion.getType())){ element= TextSelectionConverter.getElementAtOffset((JavaEditor) part, textSelection);
/** * Finds and returns the Java element that contains the * text selection in the given editor. * * @param editor the Java editor * @param selection the text selection * @return the Java elements for the given editor selection * @throws JavaModelException */ public static IJavaElement getElementAtOffset(JavaEditor editor, ITextSelection selection) throws JavaModelException { return getElementAtOffset(getInput(editor), selection); }
/** * Finds and returns the Java elements for the given editor selection. * * @param editor the Java editor * @param selection the text selection * @return the Java elements for the given editor selection * @throws JavaModelException */ public static IJavaElement[] codeResolve(JavaEditor editor, ITextSelection selection) throws JavaModelException { return codeResolve(getInput(editor), selection); }
if (part instanceof JavaEditor && selection instanceof ITextSelection) { JavaEditor editor = (JavaEditor)part; IJavaElement[] elements= TextSelectionConverter.codeResolve(editor, (ITextSelection)selection); if (elements != null && elements.length > 0) { return elements[0];
ITypedRegion typedRegion= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, textSelection.getOffset(), false); if (IJavaPartitions.JAVA_DOC.equals(typedRegion.getType())){ element= TextSelectionConverter.getElementAtOffset((JavaEditor) part, textSelection);
/** * Finds and returns the Java element that contains the text selection in the given editor. * * @param editor the Java editor * @param selection the text selection * @return the Java elements for the given editor selection * @throws JavaModelException if accessing the type root fails */ public static IJavaElement getElementAtOffset(JavaEditor editor, ITextSelection selection) throws JavaModelException { return getElementAtOffset(getInput(editor), selection); }
/** * Finds and returns the Java elements for the given editor selection. * * @param editor the Java editor * @param selection the text selection * @return the Java elements for the given editor selection * @throws JavaModelException if accessing the type root fails */ public static IJavaElement[] codeResolve(JavaEditor editor, ITextSelection selection) throws JavaModelException { return codeResolve(getInput(editor), selection); }