Search in sources :

Example 1 with Entry

use of org.python.pydev.ast.codecompletion.revisited.PyPublicTreeMap.Entry in project Pydev by fabioz.

the class ModulesManager method buildKeysForRegularEntries.

public static void buildKeysForRegularEntries(IProgressMonitor monitor, ModulesFoundStructure modulesFound, PyPublicTreeMap<ModulesKey, ModulesKey> keys, boolean includeOnlySourceModules) {
    String[] dottedValidSourceFiles = FileTypesPreferences.getDottedValidSourceFiles();
    int j = 0;
    FastStringBuffer buffer = new FastStringBuffer();
    Map<String, File> packages = new HashMap<String, File>();
    String packageM;
    File packageF;
    // 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;
                }
            }
            packageM = FullRepIterable.getParentModule(m);
            packageF = f.getParentFile();
            while (!packageM.isEmpty()) {
                packages.put(packageM, packageF);
                packageM = FullRepIterable.getParentModule(packageM);
                packageF = packageF.getParentFile();
            }
            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);
                }
            }
        }
    }
    for (Map.Entry<String, File> packageEntry : packages.entrySet()) {
        buffer.clear();
        File f = packageEntry.getValue();
        ModulesKey modulesKeyForFolder = new ModulesKeyForFolder(buffer.append(packageEntry.getKey()).append(".__init__").toString(), f);
        if (!keys.containsKey(modulesKeyForFolder)) {
            keys.put(modulesKeyForFolder, modulesKeyForFolder);
        }
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) HashMap(java.util.HashMap) ModulesKeyForFolder(org.python.pydev.core.ModulesKeyForFolder) Entry(org.python.pydev.ast.codecompletion.revisited.PyPublicTreeMap.Entry) ModulesKey(org.python.pydev.core.ModulesKey) File(java.io.File) LRUMap(org.python.pydev.shared_core.cache.LRUMap) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap)

Aggregations

File (java.io.File)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Entry (org.python.pydev.ast.codecompletion.revisited.PyPublicTreeMap.Entry)1 ModulesKey (org.python.pydev.core.ModulesKey)1 ModulesKeyForFolder (org.python.pydev.core.ModulesKeyForFolder)1 LRUMap (org.python.pydev.shared_core.cache.LRUMap)1 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)1