@Override protected void addHyperlinks(List<IHyperlink> hyperlinksCollector, IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) { if (canOpenImplementation(element) && SelectionConverter.canOperateOn(editor)) { hyperlinksCollector.add(new JavaElementImplementationHyperlink(wordRegion, openAction, element, qualify, editor)); } }
/** * @param primaryOnly if <code>true</code> only primary working copies will be returned * @since 3.2 */ public static IJavaElement[] codeResolve(JavaEditor editor, boolean primaryOnly) throws JavaModelException { return codeResolve(getInput(editor, primaryOnly), (ITextSelection)editor.getSelectionProvider().getSelection()); }
private IJavaElement elementAtOffset() { try { return SelectionConverter.getElementAtOffset(fEditor); } catch(JavaModelException e) { } return null; }
public static IJavaElement[] codeResolveOrInputForked(JavaEditor editor) throws InvocationTargetException, InterruptedException { ITypeRoot input= getInput(editor); if (input == null) return EMPTY_RESULT; ITextSelection selection= (ITextSelection)editor.getSelectionProvider().getSelection(); IJavaElement[] result= performForkedCodeResolve(input, selection); if (result.length == 0) { result= new IJavaElement[] {input}; } return result; }
public static IType getTypeAtOffset(JavaEditor editor) throws JavaModelException { IJavaElement element= SelectionConverter.getElementAtOffset(editor); IType type= (IType)element.getAncestor(IJavaElement.TYPE); if (type == null) { ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(editor); if (unit != null) type= unit.findPrimaryType(); } return type; }
@Override public void run(ITextSelection selection) { IJavaElement element= SelectionConverter.getInput(fEditor); if (!ActionUtil.isProcessable(getShell(), element)) return; try { IJavaElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); if (elements == null || elements.length == 0) return; IJavaElement candidate= elements[0]; if (elements.length > 1) { candidate= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.OpenAttachedJavadocAction_select_element); } if (candidate != null) { run(candidate); } } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.OpenAttachedJavadocAction_code_resolve_failed); } catch (InterruptedException e) { // cancelled } }
public void run(ITextSelection selection) { try { if (!ActionUtil.isProcessable(fEditor)) return; IJavaElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); if (elements.length == 1 && (elements[0] instanceof IField)) { IField field= (IField) elements[0]; run(field.getDeclaringType(), new IField[] { field}, true); return; } IJavaElement element= SelectionConverter.getElementAtOffset(fEditor); if (element != null) { IType type= (IType) element.getAncestor(IJavaElement.TYPE); if (type != null) { if (type.getFields().length > 0) { run(type, new IField[0], true); return; } } } MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); } catch (InterruptedException e) { // cancelled } }
public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(fEditor)) return; try { String title= SearchMessages.SearchElementSelectionDialog_title; String message= SearchMessages.SearchElementSelectionDialog_message; IJavaElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); if (elements.length > 0 && canOperateOn(elements[0])) { IJavaElement element= elements[0]; if (elements.length > 1) element= SelectionConverter.selectJavaElement(elements, getShell(), title, message); if (element != null) run(element); } else showOperationUnavailableDialog(); } catch (InvocationTargetException ex) { String title= SearchMessages.Search_Error_search_title; String message= SearchMessages.Search_Error_codeResolve; ExceptionHandler.handle(ex, getShell(), title, message); } catch (InterruptedException e) { // ignore } }
@Override public void run(ITextSelection selection) { IJavaElement input= SelectionConverter.getInput(fEditor); if (!ActionUtil.isProcessable(getShell(), input)) return; try { IJavaElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); if (elements == null) return; List<IJavaElement> candidates= new ArrayList<>(elements.length); for (int i= 0; i < elements.length; i++) { IJavaElement[] resolvedElements= OpenTypeHierarchyUtil.getCandidates(elements[i]); if (resolvedElements != null) candidates.addAll(Arrays.asList(resolvedElements)); } run(candidates.toArray(new IJavaElement[candidates.size()])); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.SelectionConverter_codeResolve_failed); } catch (InterruptedException e) { // cancelled } }
public Object getInformation2(ITextViewer textViewer, IRegion subject) { if (fEditor == null) return null; try { if (fUseCodeResolve) { IStructuredSelection sel= SelectionConverter.getStructuredSelection(fEditor); if (!sel.isEmpty()) return sel.getFirstElement(); } IJavaElement element= SelectionConverter.getElementAtOffset(fEditor); if (element != null) return element; return EditorUtility.getEditorInputJavaElement(fEditor, false); } catch (JavaModelException e) { return null; } } }
@Override public void run(ITextSelection selection) { try { IJavaElement element= SelectionConverter.getElementAtOffset(fEditor); if (!ActionUtil.isEditable(fEditor, getShell(), element)) return; int type= element != null ? element.getElementType() : -1; if (type != IJavaElement.METHOD && type != IJavaElement.TYPE && type != IJavaElement.FIELD) { element= SelectionConverter.getTypeAtOffset(fEditor); if (element == null) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_not_applicable); return; } } IMember[] members= new IMember[] { (IMember)element }; if (ElementValidator.checkValidateEdit(members, getShell(), getDialogTitle())) run(members); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed); } }
public static boolean canOperateOn(JavaEditor editor) { if (editor == null) return false; return getInput(editor) != null; }
/** * Note: This constructor is for internal use only. Clients should not call this constructor. * @param editor the java editor */ public IntroduceFactoryAction(JavaEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); }
private IMethod getSingleSelectedMethod(ITextSelection selection) throws JavaModelException { // - when caret/selection on method name (call or declaration) -> that method // - otherwise: caret position's enclosing method declaration // - when caret inside argument list of method declaration -> enclosing method declaration // - when caret inside argument list of method call -> enclosing method declaration (and NOT method call) IJavaElement[] elements= SelectionConverter.codeResolve(fEditor); if (elements.length > 1) return null; if (elements.length == 1 && elements[0] instanceof IMethod) { return (IMethod) elements[0]; } else { IJavaElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); if (!(elementAt instanceof IMethod)) return null; return (IMethod) elementAt; } } }
/** * Perform a code resolve at the current selection of an editor * * @param editor the editor * @return the resolved elements (only from primary working copies) * @throws JavaModelException when the type root can not be accessed */ public static IJavaElement[] codeResolve(JavaEditor editor) throws JavaModelException { return codeResolve(editor, true); }
/** * Creates and returns a help context provider for the given part. * * @param part the part for which to create the help context provider * @param contextId the optional context ID used to retrieve static help * @return the help context provider */ public static IContextProvider getHelpContextProvider(IWorkbenchPart part, String contextId) { IStructuredSelection selection; try { selection= SelectionConverter.getStructuredSelection(part); } catch (JavaModelException ex) { selection= StructuredSelection.EMPTY; } Object[] elements= selection.toArray(); return new AspectJUIHelpContextProvider(contextId, elements); }
public void run(ITextSelection selection) { try { checkAndRun(SelectionConverter.getTypeAtOffset(fEditor)); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), ActionMessages.GenerateHashCodeEqualsAction_error_caption, ActionMessages.GenerateHashCodeEqualsAction_error_cannot_create); } }
public static CallHierarchyViewPart open(IJavaElement[] candidates, IWorkbenchWindow window) { Assert.isTrue(candidates != null && candidates.length != 0); IJavaElement input= null; if (candidates.length > 1) { String title= CallHierarchyMessages.CallHierarchyUI_selectionDialog_title; String message= CallHierarchyMessages.CallHierarchyUI_selectionDialog_message; input= SelectionConverter.selectJavaElement(candidates, window.getShell(), title, message); } else { input= candidates[0]; } if (input == null) return null; return openInViewPart(window, input); }
@Override public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(fEditor)) return; IJavaElement element= null; try { IJavaElement[] elements= SelectionConverter.codeResolveForked(fEditor, true); if (elements.length == 1) element= elements[0]; } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.OpenAction_error_message); return; } catch (InterruptedException e) { return; } if (element == null || !(element instanceof IMethod)) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.OpenImplementationAction_not_applicable); return; } if (!ActionUtil.isProcessable(getShell(), element)) return; SelectionDispatchAction openAction= (SelectionDispatchAction)fEditor.getAction("OpenEditor"); //$NON-NLS-1$ if (openAction == null) return; IRegion region= new Region(selection.getOffset(), 0); JavaElementImplementationHyperlink.openImplementations(fEditor, region, (IMethod)element, openAction); }
public void run(ITextSelection selection) { IJavaElement input= SelectionConverter.getInput(fEditor); if (!ActionUtil.isProcessable(getShell(), input)) return; try { IJavaElement[] elements= SelectionConverter.codeResolveOrInputForked(fEditor); if (elements == null || elements.length == 0) return; IJavaElement candidate= elements[0]; if (elements.length > 1) { candidate= SelectionConverter.selectJavaElement(elements, getShell(), getDialogTitle(), ActionMessages.ShowInNavigatorView_dialog_message); } if (candidate != null) { run(getResource(candidate)); } } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getDialogTitle(), ActionMessages.SelectionConverter_codeResolve_failed); } catch (InterruptedException e) { // cancelled } }