/** * 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); }
private IJavaElement getJavaElementFromEditor() throws JavaModelException { IJavaElement[] elements= SelectionConverter.codeResolve(fEditor); if (elements == null || elements.length != 1) return null; return elements[0]; }
private IJavaElement getJavaElementFromEditor() throws JavaModelException { IJavaElement[] elements= SelectionConverter.codeResolve(fEditor); if (elements == null || elements.length != 1) return null; return elements[0]; }
private IJavaElement getJavaElementFromEditor() throws JavaModelException { IJavaElement[] elements= SelectionConverter.codeResolve(fEditor); if (elements == null || elements.length != 1) return null; return elements[0]; }
/** * 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); }
public static IJavaElement[] codeResolve(JavaEditor editor) throws JavaModelException { return codeResolve(editor, true); }
/** * Resolves the <code>IJavaElement</code>s at the current offset. Returns * an empty array if the string under the offset doesn't resolve to a * <code>IJavaElement</code>. * * @return the resolved java elements at the current offset * @throws JavaModelException passed from the underlying code resolve API */ public IJavaElement[] resolveElementAtOffset() throws JavaModelException { if (fResolvedElements != null) return fResolvedElements; // long start= System.currentTimeMillis(); fResolvedElements= SelectionConverter.codeResolve(fElement, this); // System.out.println("Time resolving element: " + (System.currentTimeMillis() - start)); return fResolvedElements; }
/** * Resolves the <code>IJavaElement</code>s at the current offset. Returns * an empty array if the string under the offset doesn't resolve to a * <code>IJavaElement</code>. * * @return the resolved java elements at the current offset * @throws JavaModelException passed from the underlying code resolve API */ public IJavaElement[] resolveElementAtOffset() throws JavaModelException { if (fResolvedElements != null) return fResolvedElements; // long start= System.currentTimeMillis(); fResolvedElements= SelectionConverter.codeResolve(fElement, this); // System.out.println("Time resolving element: " + (System.currentTimeMillis() - start)); return fResolvedElements; }
/** * Resolves the <code>IJavaElement</code>s at the current offset. Returns * an empty array if the string under the offset doesn't resolve to a * <code>IJavaElement</code>. * * @return the resolved java elements at the current offset * @throws JavaModelException passed from the underlying code resolve API */ public IJavaElement[] resolveElementAtOffset() throws JavaModelException { if (fResolvedElements != null) return fResolvedElements; // long start= System.currentTimeMillis(); fResolvedElements= SelectionConverter.codeResolve(fElement, this); // System.out.println("Time resolving element: " + (System.currentTimeMillis() - start)); return fResolvedElements; }
/** * @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()); }
/** * Perform a code resolve at the current selection of an editor * * @param editor the editor * @param primaryOnly if <code>true</code> only primary working copies will be returned * @return the resolved elements * @throws JavaModelException thrown when the type root can not be accessed * @since 3.2 */ public static IJavaElement[] codeResolve(JavaEditor editor, boolean primaryOnly) throws JavaModelException { ITypeRoot input= getInput(editor, primaryOnly); if (input != null) return codeResolve(input, (ITextSelection) editor.getSelectionProvider().getSelection()); return EMPTY_RESULT; }
/** * Perform a code resolve at the current selection of an editor * * @param editor the editor * @param primaryOnly if <code>true</code> only primary working copies will be returned * @return the resolved elements * @throws JavaModelException thrown when the type root can not be accessed * @since 3.2 */ public static IJavaElement[] codeResolve(JavaEditor editor, boolean primaryOnly) throws JavaModelException { ITypeRoot input= getInput(editor, primaryOnly); if (input != null) return codeResolve(input, (ITextSelection) editor.getSelectionProvider().getSelection()); return EMPTY_RESULT; }
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; } } }
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; } } }
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]; IJavaElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); if (elementAt instanceof IMethod) return (IMethod)elementAt; return 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]; IJavaElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); if (elementAt instanceof IMethod) return (IMethod)elementAt; return 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]; IJavaElement elementAt= SelectionConverter.getInputAsCompilationUnit(fEditor).getElementAt(selection.getOffset()); if (elementAt instanceof IMethod) return (IMethod)elementAt; return 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; } } }
public void helpRequested(HelpEvent e) { try { Object[] selected= null; if (fViewer != null) { ISelection selection= fViewer.getSelection(); if (selection instanceof IStructuredSelection) { selected= ((IStructuredSelection)selection).toArray(); } } else if (fEditor != null) { IJavaElement input= SelectionConverter.getInput(fEditor); if (ActionUtil.isOnBuildPath(input)) { selected= SelectionConverter.codeResolve(fEditor); } } JavadocHelpContext.displayHelp(fContextId, selected); } catch (CoreException x) { } } }
public void run(ITextSelection selection) { try { IJavaElement[] elements= SelectionConverter.codeResolve(fEditor); if (elements.length != 1 || !(elements[0] instanceof IField)) { MessageDialog.openInformation(getShell(), ActionMessages.SelfEncapsulateFieldAction_dialog_title, ActionMessages.SelfEncapsulateFieldAction_dialog_unavailable); return; } IField field= (IField)elements[0]; if (!RefactoringAvailabilityTester.isSelfEncapsulateAvailable(field)) { MessageDialog.openInformation(getShell(), ActionMessages.SelfEncapsulateFieldAction_dialog_title, ActionMessages.SelfEncapsulateFieldAction_dialog_unavailable); return; } run(field); } catch (JavaModelException exception) { JavaPlugin.log(exception); return; } }