@Override public void doRun(ISelection selection, Event event, UIInstrumentationBuilder instrumentation) { instrumentation.metric("command", command); if (!(selection instanceof ITextSelection)) { instrumentation.metric("Problem", "Selection was not a TextSelection"); } IWorkbenchPage page = DartToolsPlugin.getActivePage(); if (page == null) { instrumentation.metric("Problem", "Page was null"); return; } IEditorPart part = page.getActiveEditor(); if (part == null) { instrumentation.metric("Problem", "Part was null"); return; } IEditorInput editorInput = part.getEditorInput(); IProject project = EditorUtility.getProject(editorInput); instrumentation.data("Project", project.getName()); savePubspecFile(project); runPubJob(project); }
@Override public void doRun( IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) { try { Object element = selection.getFirstElement(); if (element instanceof DartFunction) { DartFunction function = (DartFunction) element; instrumentation.data("function", function.getSource()); if (!RefactoringAvailabilityTester.isConvertGetterToMethodAvailable(function)) { instrumentation.metric("Problem", "RefactoringAvailabilityTester Returned false"); } boolean success = RefactoringExecutionStarter_OLD.startConvertGetterToMethodRefactoring( function, getShell()); if (success) { return; } instrumentation.metric( "Problem", "RefactoringExecutionStarter.startConvertGetterToMethodRefactoring returned False"); } } catch (DartModelException e) { ExceptionHandler.handle( e, getShell(), RefactoringMessages.ConvertGetterToMethodAction_dialog_title, RefactoringMessages.InlineMethodAction_unexpected_exception); } }
@Override public void doRun( IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) { instrumentation.metric("command", command); if (!selection.isEmpty() && selection.getFirstElement() instanceof IResource) { Object object = selection.getFirstElement(); if (object instanceof IFile) { object = ((IFile) object).getParent(); } while (object != null && ((IContainer) object).findMember(DartCore.PUBSPEC_FILE_NAME) == null) { object = ((IContainer) object).getParent(); } if (object instanceof IContainer) { IContainer container = (IContainer) object; instrumentation.data("name", container.getName()); savePubspecFile(container); runPubJob(container); return; } else { instrumentation.metric("Problem", "Object was null").log(); } } instrumentation.metric("Problem", "pubspec.yaml file not selected, showing dialog"); MessageDialog.openError( getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound); instrumentation.log(); }
/** * Executes the associated action for this element. * * @param text the current string in the search box */ public void execute(String text) { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder(this.getClass()); instrumentation.data("text", text); try { doExecute(text, instrumentation); } finally { instrumentation.log(); } }
@Override protected void doRun( ITextSelection selection, Event event, UIInstrumentationBuilder instrumentation) { CompilationUnit input = SelectionConverter.getInputAsCompilationUnit(editor); instrumentation.record(input); if (!ActionUtil.isProcessable(getShell(), input)) { instrumentation.metric("Problem", "input cu is not processable"); return; } try { DartElement[] elements = SelectionConverter.codeResolveOrInputForked(editor); if (elements == null) { instrumentation.metric("Problem", "elements was null"); return; } ActionInstrumentationUtilities.record(elements, "Selections", instrumentation); List<DartElement> candidates = new ArrayList<DartElement>(elements.length); for (int i = 0; i < elements.length; i++) { DartElement element = elements[i]; if (CallHierarchy.isPossibleInputElement(element)) { candidates.add(element); } } if (candidates.isEmpty()) { DartElement enclosingMethod = getEnclosingMethod(input, selection); if (enclosingMethod != null) { candidates.add(enclosingMethod); } } ActionInstrumentationUtilities.record(candidates, "Candidates", instrumentation); CallHierarchyUI.openSelectionDialog( candidates.toArray(new DartElement[candidates.size()]), getSite().getWorkbenchWindow()); } catch (InvocationTargetException e) { ExceptionHandler.handle( e, getShell(), CallHierarchyMessages.OpenCallHierarchyAction_dialog_title, ActionMessages.SelectionConverter_codeResolve_failed); } catch (InterruptedException e) { // cancelled instrumentation.metric("Problem", "User cancelled"); } }
private static IEditorPart openInEditor(IEditorInput input, String editorID, boolean activate) throws PartInitException { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder("EditorUtility.openInEditor-IEditorInput"); try { Assert.isNotNull(input); Assert.isNotNull(editorID); instrumentation.data("Name", input.getName()); instrumentation.data("EditorID", editorID); instrumentation.metric("activate", activate); IWorkbenchPage p = DartToolsPlugin.getActivePage(); if (p == null) { throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage); } IEditorPart editorPart = p.openEditor(input, editorID, activate); initializeHighlightRange(editorPart); return editorPart; } catch (RuntimeException e) { instrumentation.metric("Exception", e.getClass().toString()); instrumentation.data("Exception", e.toString()); throw e; } finally { instrumentation.log(); } }
@Override public void run(IAction action) { if (selection != null) { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder(getClass()); Object obj = SelectionUtil.getSingleElement(selection); try { instrumentation.record(selection); if (obj instanceof IVariable) { IVariable variable = (IVariable) obj; obj = variable.getValue(); } if (obj instanceof DartiumDebugValue) { DartiumDebugValue value = (DartiumDebugValue) obj; IValue classValue = value.getClassValue(); if (classValue != null) { ObjectInspectorView.inspect(classValue, true); } } else if (obj instanceof ServerDebugValue) { ServerDebugValue value = (ServerDebugValue) obj; IValue classValue = value.getClassValue(); if (classValue != null) { ObjectInspectorView.inspect(classValue, true); } } instrumentation.metric("Inspect", "Completed"); } catch (DebugException e) { DartDebugUIPlugin.logError(e); } finally { instrumentation.log(); } } }
@Override protected void doRun( IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) { List<?> elements = selection.toList(); instrumentation.metric("Elements-Length", elements.size()); if (!CallHierarchy.arePossibleInputElements(elements)) { elements = Collections.EMPTY_LIST; } TypeMember[] members = elements.toArray(new TypeMember[elements.size()]); ActionInstrumentationUtilities.record(members, "SelectedMembers", instrumentation); if (!ActionUtil.areProcessable(getShell(), members)) { instrumentation.metric("Problem", "areProcessable returned false"); return; } CallHierarchyUI.openView(members, getSite().getWorkbenchWindow()); }
@Override public void doRun( ITextSelection selection, Event event, UIInstrumentationBuilder instrumentation) { if (!ActionUtil.isEditable(fEditor)) { instrumentation.metric("Problem", "Editor not editable"); return; } CompilationUnit cu = SelectionConverter.getInputAsCompilationUnit(fEditor); instrumentation.record(cu); try { DartFunction function = DartModelUtil.findFunction(cu, selection.getOffset()); instrumentation.data("function", function.getSource()); boolean success = RefactoringExecutionStarter_OLD.startConvertGetterToMethodRefactoring( function, getShell()); if (success) { return; } instrumentation.metric( "Problem", "RefactoringExecutionStarter.startConvertGetterToMethodRefactoring False"); } catch (Throwable e) { instrumentation.record(e); } instrumentation.metric("Problem", "No valid selection, showing dialog"); MessageDialog.openInformation( getShell(), RefactoringMessages.ConvertGetterToMethodAction_dialog_title, RefactoringMessages.ConvertGetterToMethodAction_select); }
/** * Opens the given file in the registered editor for the file type, or in the default text editor * if no editor is registered. This differs from the openInEditor() method in that the system * editor will never be opened. * * @param file the file to open * @return an open editor * @throws PartInitException if the editor could not be opened or the input element is not valid */ public static IEditorPart openInTextEditor(IFile file, boolean activate) throws PartInitException { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder("EditorUtility.openInTextEditor"); try { if (file == null) { instrumentation.metric("Problem", "file is null"); throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null); } instrumentation.data("FileName", file.getName()); instrumentation.data("FilePath", file.getFullPath().toOSString()); IWorkbenchPage p = DartToolsPlugin.getActivePage(); if (p == null) { instrumentation.metric("Problem", "no active workbench page"); throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage); } IEditorDescriptor desc = IDE.getEditorDescriptor(file, true); if (desc.getId() == IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID) { IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry(); desc = editorReg.findEditor(EditorsUI.DEFAULT_TEXT_EDITOR_ID); } IEditorPart editorPart = IDE.openEditor(p, file, maybeSwapDefaultEditorDescriptor(desc.getId()), activate); initializeHighlightRange(editorPart); return editorPart; } catch (RuntimeException e) { instrumentation.metric("Exception", e.getClass().toString()); instrumentation.data("Exception", e.toString()); throw e; } finally { instrumentation.log(); } }
private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder("EditorUtility.openInEditor-IFile"); try { if (file == null) { throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null); } instrumentation.data("FileName", file.getName()); instrumentation.data("FilePath", file.getFullPath().toOSString()); instrumentation.metric("activate", activate); IWorkbenchPage p = DartToolsPlugin.getActivePage(); if (p == null) { throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage); } IEditorDescriptor desc = IDE.getEditorDescriptor(file, true); String editorId = desc.getId(); boolean isTooComplex = false; editorId = maybeSwapDefaultEditorDescriptor(editorId); if (DartUI.isTooComplexDartFile(file)) { isTooComplex = true; editorId = EditorsUI.DEFAULT_TEXT_EDITOR_ID; } IEditorPart editor = IDE.openEditor(p, file, editorId, activate); if (isTooComplex) { DartUI.showTooComplexDartFileWarning(editor); } initializeHighlightRange(editor); return editor; } catch (RuntimeException e) { instrumentation.metric("Exception", e.getClass().toString()); instrumentation.data("Exception", e.toString()); throw e; } finally { instrumentation.log(); } }
@SuppressWarnings("unused") private static IEditorPart openInEditor(URI file, boolean activate) throws PartInitException { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder("EditorUtility.openInEditor-URI"); try { if (file == null) { throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null); } instrumentation.data("File", file.getPath()); instrumentation.metric("activate", activate); IWorkbenchPage p = DartToolsPlugin.getActivePage(); if (p == null) { throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage); } IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getPath()); if (desc == null) { throwPartInitException(DartEditorMessages.EditorUtility_cantFindEditor + file.toString()); } IEditorPart editorPart = IDE.openEditor(p, file, maybeSwapDefaultEditorDescriptor(desc.getId()), activate); initializeHighlightRange(editorPart); return editorPart; } catch (RuntimeException e) { instrumentation.metric("Exception", e.getClass().toString()); instrumentation.data("Exception", e.toString()); throw e; } finally { instrumentation.log(); } }
@Override public boolean performOk() { IPreferenceStore editorPreferences = EditorsPlugin.getDefault().getPreferenceStore(); editorPreferences.setValue( AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER, lineNumbersCheck.getSelection()); DartFormatter.setMaxLineLengthEnabled(printMarginCheck.getSelection()); if (printMarginCheck.getSelection()) { DartFormatter.setMaxLineLength(printMarginText.getText()); } IPreferenceStore toolsPreferenceStore = PreferenceConstants.getPreferenceStore(); toolsPreferenceStore.setValue( PreferenceConstants.CODEASSIST_AUTOACTIVATION, enableAutoCompletion.getSelection()); if (!DartCoreDebug.ENABLE_ANALYSIS_SERVER) { toolsPreferenceStore.setValue( PreferenceConstants.EDITOR_FOLDING_ENABLED, enableFolding.getSelection()); } toolsPreferenceStore.setValue( PreferenceConstants.EDITOR_REMOVE_TRAILING_WS, removeTrailingWhitespaceCheck.getSelection()); toolsPreferenceStore.setValue( PreferenceConstants.EDITOR_FORMAT_ON_SAVES, formatCheck.getSelection()); handleSave(editorPreferences); handleSave(toolsPreferenceStore); IEclipsePreferences prefs = DartCore.getPlugin().getPrefs(); if (prefs != null) { prefs.putBoolean(DartCore.PUB_AUTO_RUN_PREFERENCE, runPubAutoCheck.getSelection()); try { DartCore.getPlugin().savePrefs(); } catch (CoreException e) { DartToolsPlugin.log(e); } // // If the user has changed the preference to true, // then run pub on all pubspecs in the workspace // if (runPubChanged) { UIInstrumentationBuilder instrumentation = UIInstrumentation.builder(this.getClass()); try { boolean autoRunPubEnabled = runPubAutoCheck.getSelection(); instrumentation.metric("autoRunPubEnabled", autoRunPubEnabled); if (autoRunPubEnabled) { PlatformUI.getWorkbench() .getDisplay() .asyncExec( new Runnable() { @Override public void run() { runPubNow(); } }); } } catch (RuntimeException e) { instrumentation.record(e); throw e; } finally { instrumentation.log(); } } } boolean serverChanged = setPrefBool(DartCoreDebug.ENABLE_ANALYSIS_SERVER_PREF, true, enableAnalysisServerButton); if (serverChanged) { MessageDialog.openInformation( getShell(), "Restart Required", "These changes will only take effect once the IDE has been restarted."); } return true; }