Ejemplo n.º 1
0
  private void reindexPackage(RPackage rPackage, RPackage indexPackage) {
    // replace package

    RHelperUtil.LOG.info("detecting methods in " + rPackage.getName());

    String allFunsConcat =
        RHelperUtil.runCommand("cat(getNamespaceExports('" + rPackage.getName() + "'))").trim();
    List<String> allFuns = Splitter.on(" ").trimResults().splitToList(allFunsConcat);

    List<Function> functions =
        Lists.transform(
            allFuns,
            new com.google.common.base.Function<String, Function>() {
              @Override
              public Function apply(String s) {
                return new Function(s, "NA");
              }
            });

    rPackage.setFunctions(functions);

    if (indexPackage != null) {
      allPackages.remove(indexPackage);
    }

    allPackages.add(rPackage);
  }
Ejemplo n.º 2
0
  @Nullable
  public RPackage getByName(String packageName) {
    for (RPackage aPackage : getInstance().getPackages()) {
      if (aPackage.getName().equals(packageName)) {
        return aPackage;
      }
    }

    return null;
  }
Ejemplo n.º 3
0
  @NotNull
  public List<RPackage> getContainingPackages(String functionName) {
    List<RPackage> funPackages = Lists.newArrayList();

    for (RPackage rPackage : getPackages()) {
      if (rPackage.hasFunction(functionName)) {
        funPackages.add(rPackage);
      }
    }

    return funPackages;
  }
Ejemplo n.º 4
0
  public List<Function> getFunctionByName(String funName) {
    List<Function> funList = new ArrayList<Function>();

    for (RPackage aPackage : getInstance().getPackages()) {
      Function function = aPackage.getFunction(funName);

      if (function != null) {
        funList.add(function);
      }
    }

    return funList;
  }
Ejemplo n.º 5
0
  @NotNull
  public Collection<RPackage> getDependencies(RPackage somePckge) {
    Collection<RPackage> deps = new HashSet<RPackage>();

    for (String dep : somePckge.getDependencyNames()) {
      RPackage depPckg = getByName(dep);
      if (depPckg == null) continue;

      deps.add(depPckg);
    }

    return deps;
  }
Ejemplo n.º 6
0
 public Set<RPackage> getImporting(@NotNull RPackage rPackage) {
   return allPackages
       .stream()
       .filter(p -> p.getImports().contains(rPackage.getName()))
       .collect(Collectors.toSet());
 }
Ejemplo n.º 7
0
  /**
   * @param packageNames Packages to be reindexd if version has changed or package has been
   *     installed since last indexing run.If non are provided all packages will be refreshed.
   */
  public boolean refreshIndex(String... packageNames) {
    RHelperUtil.runHelperWithArgs(RHelperUtil.R_HELPER_INSTALL_TIDYVERSE);

    Set<RPackage> installedPackages = LocalRUtil.getInstalledPackages();

    // remove packages from index that are no longer present
    if (packageNames.length == 0) {
      Sets.SetView<RPackage> noLongerInstalled = Sets.difference(allPackages, installedPackages);
      allPackages.removeAll(noLongerInstalled);
    }

    // cut down packges to be refreshed to speed up calculations
    //        if(packageNames.length>0){
    //            installedPackages = installedPackages.stream().
    //                    filter(p -> Arrays.asList(packageNames).contains(p.getName())).
    //                    collect(Collectors.toSet());
    //        }

    ExecutorService executorService = Executors.newFixedThreadPool(8);

    final boolean[] hasChanged = {false};

    for (final RPackage rPackage : installedPackages) {
      final RPackage indexPackage = getByName(rPackage.getName());

      if (indexPackage != null
          && ObjectUtils.equals(indexPackage.getVersion(), rPackage.getVersion())) {
        continue;
      }

      executorService.submit(
          new Runnable() {
            @Override
            public void run() {
              reindexPackage(rPackage, indexPackage);
              hasChanged[0] = true;
            }
          });
    }

    executorService.shutdown();
    try {
      executorService.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    //        allPackages.clear();
    //        allPackages.addAll(installedPackages);

    if (hasChanged[0]) {
      if (ApplicationManager.getApplication() != null) {
        Project[] projects = ProjectManager.getInstance().getOpenProjects();
        for (Project project : projects) {
          if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
            SpellCheckerManager spellCheckerManager = SpellCheckerManager.getInstance(project);
            EditableDictionary dictionary = spellCheckerManager.getUserDictionary();

            for (RPackage rPackage : RPackageService.getInstance().allPackages) {
              dictionary.addToDictionary(rPackage.getName());
              dictionary.addToDictionary(rPackage.getFunctionNames());
            }

            DaemonCodeAnalyzer.getInstance(project).restart();
          }
        }
      }
    }

    return hasChanged[0];
  }