/** * 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 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 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); }
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; } }
ITypedRegion typedRegion= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, textSelection.getOffset(), false); if (IJavaPartitions.JAVA_DOC.equals(typedRegion.getType())){ element= TextSelectionConverter.getElementAtOffset((JavaEditor) part, textSelection);
ITypedRegion typedRegion= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, textSelection.getOffset(), false); if (IJavaPartitions.JAVA_DOC.equals(typedRegion.getType())){ element= TextSelectionConverter.getElementAtOffset((JavaEditor) part, textSelection);