Ejemplo n.º 1
0
 /** @return if the path passed belongs to a valid python source file (checks for the extension) */
 public static boolean isValidSourceFile(String path) {
   path = path.toLowerCase();
   for (String end : FileTypesPreferencesPage.getDottedValidSourceFiles()) {
     if (path.endsWith(end)) {
       return true;
     }
   }
   if (path.endsWith(".pypredef")) {
     return true;
   }
   return false;
 }
Ejemplo n.º 2
0
  public static void buildKeysForRegularEntries(
      IProgressMonitor monitor,
      ModulesFoundStructure modulesFound,
      PyPublicTreeMap<ModulesKey, ModulesKey> keys,
      boolean includeOnlySourceModules) {
    String[] dottedValidSourceFiles = FileTypesPreferencesPage.getDottedValidSourceFiles();

    int j = 0;
    FastStringBuffer buffer = new FastStringBuffer();
    // now, create in memory modules for all the loaded files (empty modules).
    for (Iterator<Map.Entry<File, String>> iterator =
            modulesFound.regularModules.entrySet().iterator();
        iterator.hasNext() && monitor.isCanceled() == false;
        j++) {
      Map.Entry<File, String> entry = iterator.next();
      String m = entry.getValue();

      if (m != null) {
        if (j % 20 == 0) {
          // no need to report all the time (that's pretty fast now)
          buffer.clear();
          monitor.setTaskName(buffer.append("Module resolved: ").append(m).toString());
          monitor.worked(1);
        }

        // we don't load them at this time.
        File f = entry.getKey();

        if (includeOnlySourceModules) {
          // check if we should include only source modules
          if (!PythonPathHelper.isValidSourceFile(f.getName())) {
            continue;
          }
        }
        ModulesKey modulesKey = new ModulesKey(m, f);

        // no conflict (easy)
        if (!keys.containsKey(modulesKey)) {
          keys.put(modulesKey, modulesKey);

        } else {
          // we have a conflict, so, let's resolve which one to keep (the old one or this one)
          if (PythonPathHelper.isValidSourceFile(f.getName(), dottedValidSourceFiles)) {
            // source files have priority over other modules (dlls) -- if both are source, there is
            // no real way to resolve
            // this priority, so, let's just add it over.
            keys.put(modulesKey, modulesKey);
          }
        }
      }
    }
  }