/**
   * Removes the markers from the given input
   *
   * @param input the input that has a related resource that should have markers removed
   */
  private void removeMarkersFromInput(IEditorInput input) {
    if (input != null && PyDevBuilderPrefPage.getAnalyzeOnlyActiveEditor()) {
      IFile relatedFile = (IFile) input.getAdapter(IFile.class);

      if (relatedFile != null && relatedFile.exists()) {
        // when disposing, remove all markers
        AnalysisRunner.deleteMarkers(relatedFile);
      }
    }
  }
Exemple #2
0
  /**
   * Utility routine to add PythonNature to the project
   *
   * @param projectPythonpath: @see {@link IPythonPathNature#setProjectSourcePath(String)}
   */
  public static synchronized IPythonNature addNature(
      IProject project,
      IProgressMonitor monitor,
      String version,
      String projectPythonpath,
      String externalProjectPythonpath,
      String projectInterpreter,
      Map<String, String> variableSubstitution)
      throws CoreException {

    if (project == null || !project.isOpen()) {
      return null;
    }
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    if (projectInterpreter == null) {
      projectInterpreter = IPythonNature.DEFAULT_INTERPRETER;
    }

    IProjectDescription desc = project.getDescription();

    // only add the nature if it still hasn't been added.
    if (project.hasNature(PYTHON_NATURE_ID) == false) {

      String[] natures = desc.getNatureIds();
      String[] newNatures = new String[natures.length + 1];
      System.arraycopy(natures, 0, newNatures, 0, natures.length);
      newNatures[natures.length] = PYTHON_NATURE_ID;
      desc.setNatureIds(newNatures);
      project.setDescription(desc, monitor);
    } else {
      // Return if it already has the nature configured.
      IProjectNature n = getPythonNature(project);
      if (n instanceof IPythonNature) {
        return (IPythonNature) n;
      }
    }

    // add the builder. It is used for pylint, pychecker, code completion, etc.
    ICommand[] commands = desc.getBuildSpec();

    // now, add the builder if it still hasn't been added.
    if (hasBuilder(commands) == false && PyDevBuilderPrefPage.usePydevBuilders()) {

      ICommand command = desc.newCommand();
      command.setBuilderName(BUILDER_ID);
      ICommand[] newCommands = new ICommand[commands.length + 1];

      System.arraycopy(commands, 0, newCommands, 1, commands.length);
      newCommands[0] = command;
      desc.setBuildSpec(newCommands);
      project.setDescription(desc, monitor);
    }

    IProjectNature n = getPythonNature(project);
    if (n instanceof PythonNature) {
      PythonNature nature = (PythonNature) n;
      // call initialize always - let it do the control.
      nature.init(
          version,
          projectPythonpath,
          externalProjectPythonpath,
          monitor,
          projectInterpreter,
          variableSubstitution);
      return nature;
    }
    return null;
  }