/**
   * 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();
  }
  @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;
  }
Beispiel #3
0
  public IDocument getDocument(IEditorPart currentEditor) {
    AbstractTextEditor castEditor = (AbstractTextEditor) currentEditor;
    IDocumentProvider provider = castEditor.getDocumentProvider();

    return provider.getDocument(castEditor.getEditorInput());
  }