コード例 #1
0
  /**
   * @param preferenceStore the store from where we should get the preferences key.
   * @param preferenceKey this is a key where the value is a string with substrings separated by
   *     '|'.
   * @param shellMementoId the id for saving the memento settings for the dialog.
   */
  public SelectExistingOrCreateNewDialog(
      Shell parent, IPreferenceStore preferenceStore, String preferenceKey, String shellMementoId) {

    super(parent, new ToStringLabelProvider(), new StringFromListContentProvider());
    this.memento = new DialogMemento(parent, shellMementoId);
    this.preferenceStore = preferenceStore;

    final String initialValue = preferenceStore.getString(preferenceKey);

    this.preferenceKey = preferenceKey;

    this.setInput(StringUtils.split(initialValue, '|'));
    this.setAllowMultiple(false);
    this.setValidator(createValidator());
    this.setHelpAvailable(false);
    // as we have many special things about deleting, filtering in this class, it's important that
    // elements are up to date.
    this.updateInThread = false;
  }
コード例 #2
0
ファイル: Pep8Visitor.java プロジェクト: conbon/Pydev
  public List<IMessage> getMessages(
      SourceModule module,
      IDocument document,
      IProgressMonitor monitor,
      IAnalysisPreferences prefs) {
    try {

      if (prefs.getSeverityForType(IAnalysisPreferences.TYPE_PEP8) < IMarker.SEVERITY_WARNING) {
        return messages;
      }
      this.prefs = prefs;
      this.document = document;
      messageToIgnore = prefs.getRequiredMessageToIgnore(IAnalysisPreferences.TYPE_PEP8);
      File pep8Loc = JythonModules.getPep8Location();

      if (pep8Loc == null) {
        Log.log("Unable to get pep8 module.");
        return messages;
      }

      IAdaptable projectAdaptable = prefs.getProjectAdaptable();
      if (AnalysisPreferencesPage.useSystemInterpreter(projectAdaptable)) {
        String parameters = AnalysisPreferencesPage.getPep8CommandLineAsStr(projectAdaptable);
        String output =
            PyFormatStd.runWithPep8BaseScript(document.get(), parameters, "pep8.py", "");
        List<String> splitInLines = StringUtils.splitInLines(output, false);

        for (String line : splitInLines) {
          try {
            List<String> lst = StringUtils.split(line, ':', 4);
            int lineNumber = Integer.parseInt(lst.get(1));
            int offset = Integer.parseInt(lst.get(2)) - 1;
            String text = lst.get(3);
            this.reportError(lineNumber, offset, text, null);
          } catch (Exception e) {
            Log.log("Error parsing line: " + line, e);
          }
        }
        return messages;
      }

      String[] pep8CommandLine = AnalysisPreferencesPage.getPep8CommandLine(projectAdaptable);
      FastStringBuffer args = new FastStringBuffer(pep8CommandLine.length * 20);
      for (String string : pep8CommandLine) {
        args.append(',').append("r'").append(string).append('\'');
      }

      // It's important that the interpreter is created in the Thread and not outside the thread
      // (otherwise
      // it may be that the output ends up being shared, which is not what we want.)
      boolean useConsole = AnalysisPreferencesPage.useConsole(projectAdaptable);
      IPythonInterpreter interpreter = JythonPlugin.newPythonInterpreter(useConsole, false);
      String file = StringUtils.replaceAllSlashes(module.getFile().getAbsolutePath());
      interpreter.set("visitor", this);

      List<String> splitInLines = StringUtils.splitInLines(document.get());
      interpreter.set("lines", splitInLines);
      PyObject tempReportError = reportError;
      if (tempReportError != null) {
        interpreter.set("ReportError", tempReportError);
      } else {
        interpreter.set("ReportError", Py.None);
      }
      PyObject pep8Module = JythonModules.getPep8Module(interpreter);
      interpreter.set("pep8", pep8Module);

      String formatted = StringUtils.format(EXECUTE_PEP8, file, args.toString(), file);
      interpreter.exec(formatted);
      if (reportError == null) {
        synchronized (lock) {
          if (reportError == null) {
            reportError = interpreter.get("ReportError");
          }
        }
      }

    } catch (Exception e) {
      Log.log("Error analyzing: " + module, e);
    }

    return messages;
  }
コード例 #3
0
ファイル: ModulesManager.java プロジェクト: pczerkas/Pydev
  /**
   * @param systemModulesManager
   * @param workspaceMetadataFile
   * @throws IOException
   */
  public static void loadFromFile(ModulesManager modulesManager, File workspaceMetadataFile)
      throws IOException {
    if (workspaceMetadataFile.exists() && !workspaceMetadataFile.isDirectory()) {
      throw new IOException("Expecting: " + workspaceMetadataFile + " to be a directory.");
    }
    File modulesKeysFile = new File(workspaceMetadataFile, "modulesKeys");
    File pythonpatHelperFile = new File(workspaceMetadataFile, "pythonpath");
    if (!modulesKeysFile.isFile()) {
      throw new IOException("Expecting: " + modulesKeysFile + " to exist (and be a file).");
    }
    if (!pythonpatHelperFile.isFile()) {
      throw new IOException("Expecting: " + pythonpatHelperFile + " to exist (and be a file).");
    }

    String fileContents = FileUtils.getFileContents(modulesKeysFile);
    if (!fileContents.startsWith(MODULES_MANAGER_V2)) {
      throw new RuntimeException(
          "Could not load modules manager from " + modulesKeysFile + " (version changed).");
    }

    HashMap<Integer, String> intToString = new HashMap<Integer, String>();
    fileContents = fileContents.substring(MODULES_MANAGER_V2.length());
    if (fileContents.startsWith("--COMMON--\n")) {
      String header = fileContents.substring("--COMMON--\n".length());
      header = header.substring(0, header.indexOf("--END-COMMON--\n"));
      fileContents =
          fileContents.substring(
              fileContents.indexOf("--END-COMMON--\n") + "--END-COMMON--\n".length());

      for (String line : StringUtils.iterLines(header)) {
        line = line.trim();
        List<String> split = StringUtils.split(line, '=');
        if (split.size() == 2) {
          try {
            int i = Integer.parseInt(split.get(0));
            intToString.put(i, split.get(1));
          } catch (NumberFormatException e) {
            Log.log(e);
          }
        }
      }
      if (fileContents.startsWith(MODULES_MANAGER_V2)) {
        fileContents = fileContents.substring(MODULES_MANAGER_V2.length());
      }
    }

    handleFileContents(modulesManager, fileContents, intToString);

    if (modulesManager.pythonPathHelper == null) {
      throw new IOException(
          "Pythonpath helper not properly restored. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }
    modulesManager.pythonPathHelper.loadFromFile(pythonpatHelperFile);

    if (modulesManager.pythonPathHelper.getPythonpath() == null) {
      throw new IOException(
          "Pythonpath helper pythonpath not properly restored. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }

    if (modulesManager.pythonPathHelper.getPythonpath().size() == 0) {
      throw new IOException(
          "Pythonpath helper pythonpath restored with no contents. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }

    if (modulesManager.modulesKeys.size()
        < 2) { // if we have few modules, that may indicate a problem...
      // if the project is really small, modulesManager will be fast, otherwise, it'll fix the
      // problem.
      // Note: changed to a really low value because we now make a check after it's restored
      // anyways.
      throw new IOException(
          "Only "
              + modulesManager.modulesKeys.size()
              + " modules restored in I/O. "
              + modulesManager.getClass().getName()
              + " dir:"
              + workspaceMetadataFile);
    }
  }