/** * Converts the given selection to a structured selection * containing Java elements. * * @param selection the selection * @return a structured selection with Java elements */ private IStructuredSelection convertToJavaElementSelection(ISelection selection) { if (!(selection instanceof ITextSelection && fCurrentViewInput instanceof ISourceReference)) return StructuredSelection.EMPTY; ITextSelection textSelection= (ITextSelection)selection; Object codeAssist= fCurrentViewInput.getAncestor(IJavaElement.COMPILATION_UNIT); if (codeAssist == null) codeAssist= fCurrentViewInput.getAncestor(IJavaElement.CLASS_FILE); if (codeAssist instanceof ICodeAssist) { IJavaElement[] elements= null; try { ISourceRange range= ((ISourceReference)fCurrentViewInput).getSourceRange(); elements= ((ICodeAssist)codeAssist).codeSelect(range.getOffset() + getOffsetInUnclippedDocument(textSelection), textSelection.getLength()); } catch (JavaModelException e) { return StructuredSelection.EMPTY; } if (elements != null && elements.length > 0) { return new StructuredSelection(elements[0]); } else return StructuredSelection.EMPTY; } return StructuredSelection.EMPTY; }
/** * Converts the given selection to a structured selection * containing Java elements. * * @param selection the selection * @return a structured selection with Java elements */ private IStructuredSelection convertToJavaElementSelection(ISelection selection) { if (!(selection instanceof ITextSelection && fCurrentViewInput instanceof ISourceReference)) return StructuredSelection.EMPTY; ITextSelection textSelection= (ITextSelection)selection; Object codeAssist= fCurrentViewInput.getAncestor(IJavaElement.COMPILATION_UNIT); if (codeAssist == null) codeAssist= fCurrentViewInput.getAncestor(IJavaElement.CLASS_FILE); if (codeAssist instanceof ICodeAssist) { IJavaElement[] elements= null; try { ISourceRange range= ((ISourceReference)fCurrentViewInput).getSourceRange(); elements= ((ICodeAssist)codeAssist).codeSelect(range.getOffset() + getOffsetInUnclippedDocument(textSelection), textSelection.getLength()); } catch (JavaModelException e) { return StructuredSelection.EMPTY; } if (elements != null && elements.length > 0) { return new StructuredSelection(elements[0]); } else return StructuredSelection.EMPTY; } return StructuredSelection.EMPTY; }
/** * Converts the given selection to a structured selection * containing Java elements. * * @param selection the selection * @return a structured selection with Java elements */ private IStructuredSelection convertToJavaElementSelection(ISelection selection) { if (!(selection instanceof ITextSelection && fCurrentViewInput instanceof ISourceReference)) return StructuredSelection.EMPTY; ITextSelection textSelection= (ITextSelection)selection; Object codeAssist= fCurrentViewInput.getAncestor(IJavaElement.COMPILATION_UNIT); if (codeAssist == null) codeAssist= fCurrentViewInput.getAncestor(IJavaElement.CLASS_FILE); if (codeAssist instanceof ICodeAssist) { IJavaElement[] elements= null; try { ISourceRange range= ((ISourceReference)fCurrentViewInput).getSourceRange(); elements= ((ICodeAssist)codeAssist).codeSelect(range.getOffset() + getOffsetInUnclippedDocument(textSelection), textSelection.getLength()); } catch (JavaModelException e) { return StructuredSelection.EMPTY; } if (elements != null && elements.length > 0) { return new StructuredSelection(elements[0]); } else return StructuredSelection.EMPTY; } return StructuredSelection.EMPTY; }