Exemple #1
0
  /**
   * Called when document changes. Marks the document dirty and schedules the parsing job.
   *
   * <p>When we return from here this.isDirty must remain true until new parseJob has finished.
   *
   * <p>If the previous parseJob is not cancelled immediately (parseJob.cancel() returns false) a
   * smarter way to calculate the next scheduling delay could be used. However we should not spend
   * much time in documentChanged()
   */
  public void documentChanged(DocumentEvent event) {

    // set isDirty true and prevent possibly running parseJob from
    // changing it back to false
    // order of acquire, cancel and setDirty matters!
    try {
      lock.acquire();
      parseJob.cancel();
      this.setDirty(true);
    } finally {
      lock.release();
    }
    // if parseJob was running, now it is either cancelled or it will
    // be before it tries setDirty(false)

    // inform outline that model is dirty
    TexOutlinePage outline = editor.getOutlinePage();
    if (outline != null) {
      editor.getOutlinePage().modelGotDirty();
    }

    TexOutlineTreeView fullOutline = editor.getFullOutline();
    if (fullOutline != null) {
      fullOutline.modelGotDirty();
    }

    // reschedule parsing with delay
    if (autoParseEnabled) {
      parseJob.schedule(parseDelay);
    }
  }
  private void parse(boolean force) {
    if (!force) {
      if (_parseJob.isScheduled() || _parseJob.isRunning()) {
        if (LOGGER.isDebugEnabled()) LOGGER.debug("Parse scheduled or active, skipping");
        return;
      }
    } else {
      if (LOGGER.isDebugEnabled()) LOGGER.debug("Canceling..");

      if (_compileJob != null) _compileJob.cancel();
      if (_parseJob != null) _parseJob.cancel();
    }

    if (LOGGER.isDebugEnabled()) LOGGER.debug("Scheduling parse");
    _parseJob.schedule(200);
  }
Exemple #3
0
  /**
   * Constructs a new document model.
   *
   * @param editor The editor this model is associated to.
   */
  public TexDocumentModel(TexEditor editor) {
    this.editor = editor;
    this.isDirty = true;

    // initialize jobs
    parseJob = new ParseJob("Parsing");
    postParseJob = new PostParseJob("Updating");
    parseJob.setPriority(Job.DECORATE);
    postParseJob.setPriority(Job.DECORATE);
    // get preferences
    this.parseDelay =
        TexlipsePlugin.getDefault()
            .getPreferenceStore()
            .getInt(TexlipseProperties.AUTO_PARSING_DELAY);
    this.autoParseEnabled =
        TexlipsePlugin.getDefault()
            .getPreferenceStore()
            .getBoolean(TexlipseProperties.AUTO_PARSING);
    this.sectionCheckEnabled =
        TexlipsePlugin.getDefault()
            .getPreferenceStore()
            .getBoolean(TexlipseProperties.SECTION_CHECK);

    // add preference change listener
    TexlipsePlugin.getDefault()
        .getPreferenceStore()
        .addPropertyChangeListener(
            new IPropertyChangeListener() {

              public void propertyChange(PropertyChangeEvent event) {
                String property = event.getProperty();
                if (TexlipseProperties.AUTO_PARSING.equals(property)) {
                  autoParseEnabled =
                      TexlipsePlugin.getDefault()
                          .getPreferenceStore()
                          .getBoolean(TexlipseProperties.AUTO_PARSING);
                } else if (TexlipseProperties.AUTO_PARSING_DELAY.equals(property)) {
                  parseDelay =
                      TexlipsePlugin.getDefault()
                          .getPreferenceStore()
                          .getInt(TexlipseProperties.AUTO_PARSING_DELAY);
                } else if (TexlipseProperties.SECTION_CHECK.equals(property)) {
                  sectionCheckEnabled =
                      TexlipsePlugin.getDefault()
                          .getPreferenceStore()
                          .getBoolean(TexlipseProperties.SECTION_CHECK);
                }
              }
            });
  }
  public void setDocument(IDocument document) {
    URI uri = getURI();
    if (uri == null) {
      clear();
      return;
    }

    AbstractModelParser modelParser = null;
    IResource resource = getResource();
    String name = uri.getPath();
    if (resource != null) {
      modelParser = (AbstractModelParser) IDEParserFactory.getParser(resource);
      name = resource.getName();
    } else modelParser = (AbstractModelParser) IDEParserFactory.getParser(uri);

    ANTLRDocumentStream documentStream = new ANTLRDocumentStream(document, name);

    /*
     * set the base url so that relative imports will work
     */
    try {
      modelParser.setBaseURL(uri.toURL());
    } catch (MalformedURLException e) {
      LOGGER.error("NewReconciler.setDocument threw MalformedURLException : ", e);
    }

    modelParser.setInput(documentStream);
    installPositionMarkers(modelParser, document);

    _compilationUnit = _editor.getCompilationUnit();

    if (_compilationUnit instanceof IProjectCompilationUnit)
      _markJob =
          new CompilationUnitJob(
              "Marking", new MarkRunnable((IProjectCompilationUnit) _compilationUnit));

    _parseJob =
        new ParseJob(
            new ParseRunnable((IMutableCompilationUnit) _compilationUnit, modelParser),
            documentStream);
    _parseJob.addJobChangeListener(_jobListener);

    _compileJob =
        new CompilationUnitJob(
            "Compiling",
            new CompileRunnable((IMutableCompilationUnit) _compilationUnit, new IDECompiler()));
    _compileJob.addJobChangeListener(_jobListener);
  }
Exemple #5
0
 /**
  * Cancels possibly running parseJob and schedules it to run again immediately.
  *
  * <p>Called when new outline is created, so it is quite likely that there is no parseJob running.
  *
  * <p>If parseJob were running we could maybe use isDirty to figure out if it would be smarter to
  * wait for the running parseJob.
  */
 public void updateNow() {
   parseJob.cancel();
   parseJob.schedule();
 }
 public void dependencyParse(ParseJob job, DatabaseService db) {
   for (NLPSentence sentence : job.getSentences()) {
     db.addSentence(parseSentence(sentence));
   }
 }