Beispiel #1
0
  /**
   * Returns the text of the first line in the loaded document which has an error.
   *
   * @ensure result is the text of the first line with an error
   * @throws NoDocumentException, if a document has not been loaded
   * @throws NoSuchLineException, if there are no lines with errors
   */
  public String getLine() {
    if (document == null) {
      throw new NoDocumentException();
    }

    /*
     * line holds the first line in the loaded document which contains an
     * error.
     */
    Line line = getFirstLineWithError();
    if (line == null) {
      throw new NoSuchLineException();
    }
    return line.getText();
  }
Beispiel #2
0
  /**
   * Returns the text of the first line with an error in the loaded document with the first
   * misspelled word replaced by correction. The error is removed from the loaded document.
   *
   * @require correction is not null
   * @ensure result is the text of the first line with an error with its first misspelled word
   *     replaced by correction, and the first error is removed from the loaded document
   * @throws NoDocumentException, if a document has not been loaded
   * @throws NoSuchErrorException, if there are no errors in the loaded document
   */
  public String correctError(String correction) {
    if (document == null) {
      throw new NoDocumentException();
    }

    /*
     * line holds the first line in the loaded document which contains an
     * error.
     */
    Line lineWithError = getFirstLineWithError();
    if (lineWithError == null) {
      throw new NoSuchErrorException();
    }

    /*
     * lineCorrected holds the corrected version of lineWithError.
     */
    Line lineCorrected = lineWithError.correctError(0, correction);
    document.correctError(getLineIndex(lineWithError), 0, correction);
    return lineCorrected.getText();
  }