示例#1
0
  /**
   * Parses the LaTeX-document and adds error markers if there were any errors. Throws <code>
   * TexDocumentParseException</code> if there were fatal parse errors that prohibit building an
   * outline.
   *
   * @param monitor
   * @throws TexDocumentParseException
   */
  private ArrayList<OutlineNode> doParse(IProgressMonitor monitor)
      throws TexDocumentParseException {

    if (this.parser == null) {
      this.parser =
          new TexParser(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
    }
    if (projectOutline == null) {
      createProjectOutline();
    }

    try {
      parser.parseDocument(sectionCheckEnabled);
    } catch (IOException e) {
      TexlipsePlugin.log("Can't read file.", e);
      throw new TexDocumentParseException(e);
    }
    pollCancel(monitor);

    List<ParseErrorMessage> errors = parser.getErrors();
    List<ParseErrorMessage> tasks = parser.getTasks();
    MarkerHandler marker = MarkerHandler.getInstance();

    // somewhat inelegantly ensures that errors marked in createProjectDatastructs()
    // aren't removed immediately
    if (!firstRun) {
      marker.clearErrorMarkers(editor);
      marker.clearTaskMarkers(editor);
    } else {
      firstRun = false;
    }

    if (editor.getProject() != null && editor.getFullOutline() != null) {
      IResource res = (IResource) editor.getEditorInput().getAdapter(IResource.class);
      String fileName = res.getProjectRelativePath().toString();
      projectOutline.addOutline(parser.getOutlineTree(), fileName);

      List<OutlineNode> fo = projectOutline.getFullOutline();
      postParseJob.setFONodes(fo);
    } else {
      postParseJob.setFONodes(null);
    }
    pollCancel(monitor);

    processIncludes(parser.getInputs(), editor.getEditorInput());

    if (errors.size() > 0) {
      marker.createErrorMarkers(editor, errors);
    }
    if (tasks.size() > 0) {
      marker.createTaskMarkers(editor, tasks);
    }
    if (parser.isFatalErrors()) {
      throw new TexDocumentParseException("Fatal errors in file, parsing aborted.");
    }

    updateReferences(monitor);

    List<DocumentReference> cites = parser.getCites();
    List<DocumentReference> bibErrors = null;
    for (DocumentReference cite : cites) {
      if (!bibContainer.binTest(cite.getKey())) {
        if (bibErrors == null) bibErrors = new ArrayList<DocumentReference>();
        bibErrors.add(cite);
      }
    }
    if (bibErrors != null) {
      marker.createReferencingErrorMarkers(editor, bibErrors);
    }

    List<DocumentReference> refs = parser.getRefs();
    List<DocumentReference> refErrors = null;
    for (DocumentReference ref : refs) {
      if (!labelContainer.binTest(ref.getKey())) {
        if (refErrors == null) refErrors = new ArrayList<DocumentReference>();
        refErrors.add(ref);
      }
    }
    if (refErrors != null) {
      marker.createReferencingErrorMarkers(editor, refErrors);
    }

    return this.parser.getOutlineTree();
  }