예제 #1
0
  /**
   * @return the module for the document (may return the ast from the pyedit if it is available).
   */
  public IModule getModule() {
    if (module == null) {
      if (pyEdit != null) {
        SimpleNode ast = pyEdit.getAST();
        if (ast != null) {
          IDocument doc = ps.getDoc();
          long astModificationTimeStamp = pyEdit.getAstModificationTimeStamp();
          if (astModificationTimeStamp != -1
              && astModificationTimeStamp == (((IDocumentExtension4) doc).getModificationStamp())) {
            // Matched time stamp -- so, we can use the ast without fear of being unsynched.
            module = AbstractModule.createModule(ast, file, resolveModule());
          } else {
            // Did not match time stamp!! We'll reparse the document later on to get a synched
            // version.
          }
        }
      }

      if (module == null) {
        try {
          module =
              AbstractModule.createModuleFromDoc(resolveModule(), file, ps.getDoc(), nature, false);
        } catch (MisconfigurationException e) {
          throw new RuntimeException(e);
        }
      }
    }
    return module;
  }
  public boolean beforePerformArrangeImports(PySelection ps, PyEdit edit, IFile f) {
    int oldSelection = ps.getRegion().getOffset();

    IDocumentExtension4 doc = (IDocumentExtension4) ps.getDoc();
    if (edit != null) {
      if (!ensureParsed(edit)) {
        return true;
      }
      // Check that the editor time is actually the same as the document time.
      long docTime = doc.getModificationStamp();

      if (docTime != edit.getAstModificationTimeStamp()) {
        return true;
      }
      ErrorDescription errorDescription = edit.getErrorDescription();
      if (errorDescription != null) {
        return true; // Don't remove unused imports if we have syntax errors.
      }
    }

    try {
      findAndDeleteUnusedImports(ps, edit, doc, f);
    } catch (Exception e) {
      Log.log(e);
    }
    ps.setSelection(oldSelection, oldSelection);
    return true;
  }