Search in sources :

Example 41 with ModulesKey

use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.

the class ModulesManager method buildKeysFromModulesFound.

public static PyPublicTreeMap<ModulesKey, ModulesKey> buildKeysFromModulesFound(IProgressMonitor monitor, ModulesFoundStructure modulesFound) {
    // now, on to actually filling the module keys
    PyPublicTreeMap<ModulesKey, ModulesKey> keys = new PyPublicTreeMap<ModulesKey, ModulesKey>();
    buildKeysForRegularEntries(monitor, modulesFound, keys, false);
    for (ZipContents zipContents : modulesFound.zipContents) {
        if (monitor.isCanceled()) {
            break;
        }
        buildKeysForZipContents(keys, zipContents);
    }
    return keys;
}
Also used : ModulesKey(org.python.pydev.core.ModulesKey) ZipContents(org.python.pydev.ast.codecompletion.revisited.ModulesFoundStructure.ZipContents)

Example 42 with ModulesKey

use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.

the class ModulesManager method handleFileContents.

/**
 * This method was simply:
 *
 *  for(String line:StringUtils.iterLines(fileContents)){
 *      line = line.trim();
 *      List<String> split = StringUtils.split(line, '|');
 *      handleLineParts(modulesManager, intToString, split);
 *  }
 *
 *  and was changed to be faster (as this was one of the slow things in startup).
 */
/*default*/
@SuppressWarnings("rawtypes")
static void handleFileContents(ModulesManager modulesManager, String fileContents, HashMap<Integer, String> intToString) {
    String string = fileContents;
    int len = string.length();
    final ArrayList<ModulesKey> lst = new ArrayList<ModulesKey>();
    char c;
    int start = 0;
    int i = 0;
    String[] parts = new String[4];
    int partsFound = 0;
    for (; i < len; i++) {
        c = string.charAt(i);
        if (c == '\r') {
            String trimmed = string.substring(start, i).trim();
            if (trimmed.length() > 0) {
                parts[partsFound] = trimmed;
                partsFound++;
            }
            handleLineParts(modulesManager, intToString, parts, partsFound, lst);
            partsFound = 0;
            if (i < len - 1 && string.charAt(i + 1) == '\n') {
                i++;
            }
            start = i + 1;
        } else if (c == '\n') {
            String trimmed = string.substring(start, i).trim();
            if (trimmed.length() > 0) {
                parts[partsFound] = trimmed;
                partsFound++;
            }
            handleLineParts(modulesManager, intToString, parts, partsFound, lst);
            partsFound = 0;
            start = i + 1;
        } else if (c == '|') {
            String trimmed = string.substring(start, i).trim();
            if (trimmed.length() > 0) {
                parts[partsFound] = trimmed;
                partsFound++;
            }
            start = i + 1;
        }
    }
    if (start < len && start != i) {
        String trimmed = string.substring(start, i).trim();
        if (trimmed.length() > 0) {
            parts[partsFound] = trimmed;
            partsFound++;
        }
        handleLineParts(modulesManager, intToString, parts, partsFound, lst);
    }
    try {
        final int size = lst.size();
        // As we saved in sorted order, we can build in sorted order too (which is MUCH faster than adding items one
        // by one).
        modulesManager.modulesKeys.buildFromSorted(size, new Iterator() {

            private int i = 0;

            @Override
            public boolean hasNext() {
                return i < size;
            }

            @Override
            public Object next() {
                final ModulesKey next = lst.get(i);
                i++;
                return new Map.Entry() {

                    @Override
                    public Object getKey() {
                        return next;
                    }

                    @Override
                    public Object getValue() {
                        return next;
                    }

                    @Override
                    public Object setValue(Object value) {
                        throw new UnsupportedOperationException();
                    }
                };
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        }, null, null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Entry(org.python.pydev.ast.codecompletion.revisited.PyPublicTreeMap.Entry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) Iterator(java.util.Iterator) ModulesKey(org.python.pydev.core.ModulesKey) 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)

Example 43 with ModulesKey

use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.

the class ModulesManager method diffModules.

/**
 * @return a tuple with the new keys to be added to the modules manager (i.e.: found in keysFound but not in the
 * modules manager) and the keys to be removed from the modules manager (i.e.: found in the modules manager but
 * not in the keysFound)
 */
@Override
public Tuple<List<ModulesKey>, List<ModulesKey>> diffModules(AbstractMap<ModulesKey, ModulesKey> keysFound) {
    ArrayList<ModulesKey> newKeys = new ArrayList<ModulesKey>();
    ArrayList<ModulesKey> removedKeys = new ArrayList<ModulesKey>();
    Iterator<ModulesKey> it = keysFound.keySet().iterator();
    synchronized (modulesKeysLock) {
        while (it.hasNext()) {
            ModulesKey next = it.next();
            ModulesKey modulesKey = modulesKeys.get(next);
            if (modulesKey == null || modulesKey.getClass() != next.getClass()) {
                // Check the class because ModulesKey and ModulesKeyForZip are equal considering only the name.
                newKeys.add(next);
            }
        }
        it = modulesKeys.keySet().iterator();
        while (it.hasNext()) {
            ModulesKey next = it.next();
            ModulesKey modulesKey = keysFound.get(next);
            if (modulesKey == null || modulesKey.getClass() != next.getClass()) {
                removedKeys.add(next);
            }
        }
    }
    return new Tuple<List<ModulesKey>, List<ModulesKey>>(newKeys, removedKeys);
}
Also used : ArrayList(java.util.ArrayList) ModulesKey(org.python.pydev.core.ModulesKey) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 44 with ModulesKey

use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.

the class ModulesManagerCache method getObj.

/**
 * Overridden so that if we do not find the key, we have the chance to create it.
 */
public AbstractModule getObj(ModulesKey key, ModulesManager modulesManager) {
    synchronized (modulesManager.modulesKeysLock) {
        Tuple<ModulesKey, ModulesManager> keyTuple = new Tuple<ModulesKey, ModulesManager>(key, modulesManager);
        synchronized (lock) {
            AbstractModule obj = internalCache.getObj(keyTuple);
            if (obj == null && modulesManager.modulesKeys.containsKey(key)) {
                // get the 'real' key
                key = modulesManager.modulesKeys.get(key);
                obj = AbstractModule.createEmptyModule(key);
                internalCache.add(keyTuple, obj);
            }
            return obj;
        }
    }
}
Also used : ModulesKey(org.python.pydev.core.ModulesKey) Tuple(org.python.pydev.shared_core.structure.Tuple) AbstractModule(org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule)

Example 45 with ModulesKey

use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.

the class ModulesManagerWithBuild method removeModulesBelow.

/**
 * removes all the modules that have the module starting with the name of the module from
 * the specified file.
 */
private void removeModulesBelow(File file, IProject project, IProgressMonitor monitor) {
    if (file == null) {
        return;
    }
    String absolutePath = FileUtils.getFileAbsolutePath(file);
    List<ModulesKey> toRem = new ArrayList<ModulesKey>();
    synchronized (modulesKeysLock) {
        for (ModulesKey key : modulesKeys.keySet()) {
            if (key.file != null && FileUtils.getFileAbsolutePath(key.file).startsWith(absolutePath)) {
                toRem.add(key);
            }
        }
        removeThem(toRem);
    }
}
Also used : ArrayList(java.util.ArrayList) ModulesKey(org.python.pydev.core.ModulesKey)

Aggregations

ModulesKey (org.python.pydev.core.ModulesKey)58 File (java.io.File)23 ArrayList (java.util.ArrayList)13 HashSet (java.util.HashSet)11 MisconfigurationException (org.python.pydev.core.MisconfigurationException)11 ModulesKeyForZip (org.python.pydev.core.ModulesKeyForZip)10 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)10 IOException (java.io.IOException)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)9 Tuple (org.python.pydev.shared_core.structure.Tuple)9 IFile (org.eclipse.core.resources.IFile)8 IPythonNature (org.python.pydev.core.IPythonNature)8 HashMap (java.util.HashMap)7 ModulesKeyForFolder (org.python.pydev.core.ModulesKeyForFolder)7 IModule (org.python.pydev.core.IModule)6 List (java.util.List)5 IDocument (org.eclipse.jface.text.IDocument)5 AbstractModule (org.python.pydev.ast.codecompletion.revisited.modules.AbstractModule)5 AbstractAdditionalTokensInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)4