@Override public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { AbstractTextEditor editor = getEditor(part); if (editor != null) { IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine() + 1; IBreakpoint[] breakpoints = DebugPlugin.getDefault() .getBreakpointManager() .getBreakpoints(DartDebugCorePlugin.DEBUG_MODEL_ID); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber) { breakpoint.delete(); return; } } } DartBreakpoint breakpoint = new DartBreakpoint(resource, lineNumber); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(breakpoint); } }
protected void measureUndo(IFile file) throws PartInitException { AbstractTextEditor editor = (AbstractTextEditor) EditorTestHelper.openInEditor(file, true); editor.showChangeInformation( false); // TODO: remove when undo does no longer trigger timing issue IAction selectAll = editor.getAction(ITextEditorActionConstants.SELECT_ALL); IAction shiftRight = editor.getAction(ITextEditorActionConstants.SHIFT_RIGHT); IAction undo = editor.getAction(ITextEditorActionConstants.UNDO); int warmUpRuns = getWarmUpRuns(); int measuredRuns = getMeasuredRuns(); for (int i = 0; i < warmUpRuns + measuredRuns; i++) { runAction(selectAll); runAction(shiftRight); sleep(5000); EditorTestHelper.runEventQueue(); if (i >= warmUpRuns) fPerformanceMeter.start(); runAction(undo); if (i >= warmUpRuns) fPerformanceMeter.stop(); sleep( 5000); // NOTE: runnables posted from other threads, while the main thread waits here, are // not measured at all } fPerformanceMeter.commit(); assertPerformance(fPerformanceMeter); }
/** * Edits the file given by the fileName. The number of characters indicated by length are replaced * by the given text beginning at the character located at the given line number and the line * character offset. * * @param fileName * @param lineNum * @param lineRelativeCharOffset * @param length * @param text * @throws Exception */ public void editFile( String fileName, int lineNum, int lineRelativeCharOffset, int length, String text) throws Exception { IFile file = this.getFile(fileName); AbstractTextEditor editor = this.getEditor(file); IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); int offset = doc.getLineOffset(lineNum) + lineRelativeCharOffset; doc.replace(offset, length, text); waitForIndexManager(); }
/** Selects a Dart Element in an editor part. */ public static void revealInEditor(IEditorPart part, Element element) { if (part instanceof DartEditor) { ((DartEditor) part).selectEndReveal(element); return; } if (part instanceof AbstractTextEditor) { AbstractTextEditor textEditor = (AbstractTextEditor) part; textEditor.selectAndReveal(element.getNameOffset(), element.getName().length()); return; } }
@Nullable private DiagnosticAnnotation getAnnotationByOffset(int offset) { AbstractTextEditor editor = getActiveEditor(); if (editor == null) { return null; } IDocumentProvider documentProvider = editor.getDocumentProvider(); IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editor.getEditorInput()); for (Iterator<?> i = annotationModel.getAnnotationIterator(); i.hasNext(); ) { Annotation annotation = (Annotation) i.next(); if (annotation instanceof DiagnosticAnnotation) { DiagnosticAnnotation diagnosticAnnotation = (DiagnosticAnnotation) annotation; TextRange range = diagnosticAnnotation.getRange(); if (range.getStartOffset() <= offset && range.getEndOffset() >= offset) { return diagnosticAnnotation; } } } return null; }
public IDocument getDocument(IEditorPart currentEditor) { AbstractTextEditor castEditor = (AbstractTextEditor) currentEditor; IDocumentProvider provider = castEditor.getDocumentProvider(); return provider.getDocument(castEditor.getEditorInput()); }