Example #1
0
  /**
   * Updates the references and project data based on the data in the parsed document.
   *
   * @param monitor Progress monitor
   */
  private void updateReferences(IProgressMonitor monitor) {
    this.updateLabels(parser.getLabels());
    this.updateCommands(parser.getCommands());
    IProject project = getCurrentProject();
    if (project == null) return;
    IFile cFile = ((FileEditorInput) editor.getEditorInput()).getFile();
    boolean isMainFile = cFile.equals(TexlipseProperties.getProjectSourceFile(project));

    pollCancel(monitor);

    // After here we just store those fun properties...
    if (parser.isLocalBib()) {
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, new Boolean(true));
    } else {
      TexlipseProperties.setSessionProperty(
          project, TexlipseProperties.SESSION_BIBLATEXLOCALBIB_PROPERTY, null);
    }

    // Only update Preamble, Bibstyle if main Document
    if (isMainFile) {
      boolean biblatexMode = parser.isBiblatexMode();
      updateBiblatex(project, biblatexMode, parser.getBiblatexBackend(), false);

      String[] bibs = parser.getBibs();
      this.updateBibs(bibs, biblatexMode, cFile);

      pollCancel(monitor);

      String preamble = parser.getPreamble();
      if (preamble != null) {
        TexlipseProperties.setSessionProperty(
            project, TexlipseProperties.PREAMBLE_PROPERTY, preamble);
      }
      if (!biblatexMode) {
        String bibstyle = parser.getBibstyle();
        if (bibstyle != null) {
          String oldStyle =
              (String)
                  TexlipseProperties.getSessionProperty(
                      project, TexlipseProperties.BIBSTYLE_PROPERTY);

          if (oldStyle == null || !bibstyle.equals(oldStyle)) {
            TexlipseProperties.setSessionProperty(
                project, TexlipseProperties.BIBSTYLE_PROPERTY, bibstyle);

            // schedule running bibtex on the next build
            TexlipseProperties.setSessionProperty(
                project, TexlipseProperties.BIBFILES_CHANGED, new Boolean(true));
          }
        }
      }
    }
  }
Example #2
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();
  }