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;
}
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);
}
}
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);
}
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;
}
}
}
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);
}
}
Aggregations