use of org.python.pydev.ast.codecompletion.revisited.modules.IAbstractJavaClassModule in project Pydev by fabioz.
the class AbstractAdditionalDependencyInfo method updateKeysIfNeededAndSave.
/**
* If info == null we're dealing with project info (otherwise we're dealing with interpreter info).
*
* The main difference is that we don't index builtin modules for projects (but maybe we should?). Still,
* to index builtin modules we have to be a bit more careful, especially on changes (i.e.: when a builtin
* becomes a source module and vice-versa).
*/
public void updateKeysIfNeededAndSave(PyPublicTreeMap<ModulesKey, ModulesKey> keysFound, InterpreterInfo info, IProgressMonitor monitor) {
Map<CompleteIndexKey, CompleteIndexKey> keys = this.completeIndex.keys();
ArrayList<ModulesKey> newKeys = new ArrayList<ModulesKey>();
ArrayList<ModulesKey> removedKeys = new ArrayList<ModulesKey>();
// temporary
CompleteIndexKey tempKey = new CompleteIndexKey((ModulesKey) null);
boolean isJython = info != null ? info.getInterpreterType() == IInterpreterManager.INTERPRETER_TYPE_JYTHON : true;
Iterator<ModulesKey> it = keysFound.values().iterator();
while (it.hasNext()) {
ModulesKey next = it.next();
if (next.file != null) {
// Can be a .pyd or a .py
long lastModified = FileUtils.lastModified(next.file);
if (lastModified != 0) {
tempKey.key = next;
CompleteIndexKey completeIndexKey = keys.get(tempKey);
if (completeIndexKey == null) {
newKeys.add(next);
} else {
if (completeIndexKey.lastModified != lastModified) {
// Just re-add it if the time changed!
newKeys.add(next);
}
}
}
} else {
// at this point, it's always a compiled module (forced builtin), so, we can't check if it was modified (just re-add it).
tempKey.key = next;
CompleteIndexKey completeIndexKey = keys.get(tempKey);
if (completeIndexKey == null) {
// Only add if it's not there already.
newKeys.add(next);
}
}
}
Iterator<CompleteIndexKey> it2 = keys.values().iterator();
while (it2.hasNext()) {
CompleteIndexKey next = it2.next();
if (!keysFound.containsKey(next.key)) {
removedKeys.add(next.key);
}
}
boolean hasNew = newKeys.size() != 0;
boolean hasRemoved = removedKeys.size() != 0;
modulesAddedAndRemoved.call(new Tuple(newKeys, removedKeys));
Set<File> ignoreFiles = new HashSet<File>();
// Remove first!
if (hasRemoved) {
for (ModulesKey removedKey : removedKeys) {
// Don't generate deltas (we'll save it in the end).
this.removeInfoFromModule(removedKey.name, false);
}
}
// Add last (a module could be removed/added).
if (hasNew) {
FastStringBuffer buffer = new FastStringBuffer();
int currI = 0;
int total = newKeys.size();
IModuleRequestState moduleRequest = new BaseModuleRequest(true);
for (ModulesKey newKey : newKeys) {
currI += 1;
if (monitor.isCanceled()) {
return;
}
if (PythonPathHelper.canAddAstInfoForSourceModule(newKey)) {
buffer.clear().append("Indexing ").append(currI).append(" of ").append(total).append(" (source module): ").append(newKey.name).append(" (").append(currI).append(" of ").append(total).append(")");
try {
// Don't generate deltas (we'll save it in the end).
this.addAstInfo(newKey, false);
} catch (Exception e) {
Log.log(e);
}
} else {
if (info != null) {
if (isJython && ignoreFiles.contains(newKey.file)) {
continue;
}
buffer.clear().append("Indexing ").append(currI).append(" of ").append(total).append(" (builtin module): ").append(newKey.name);
monitor.setTaskName(buffer.toString());
IModule builtinModule = info.getModulesManager().getModule(newKey.name, info.getModulesManager().getNature(), true, moduleRequest);
if (builtinModule != null) {
if (builtinModule instanceof IAbstractJavaClassModule) {
if (newKey.file != null) {
ignoreFiles.add(newKey.file);
} else {
Log.log("Not expecting null file for java class module: " + newKey);
}
continue;
}
boolean removeFirst = keys.containsKey(new CompleteIndexKey(newKey));
addAstForCompiledModule(builtinModule, info, newKey, removeFirst);
}
}
}
}
}
if (hasNew || hasRemoved) {
if (DebugSettings.DEBUG_INTERPRETER_AUTO_UPDATE) {
org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, StringUtils.format("Additional info modules. Added: %s Removed: %s", newKeys, removedKeys));
}
save();
}
}
use of org.python.pydev.ast.codecompletion.revisited.modules.IAbstractJavaClassModule in project Pydev by fabioz.
the class ItemPointer method getFileAsURI.
public URI getFileAsURI() {
if (this.uri != null) {
return this.uri;
}
// Also see org.python.pydev.editor.actions.PyOpenAction
Object file = this.file;
if (file instanceof File) {
File f = (File) file;
String filename = f.getName();
if (// treating files without any extension!
PythonPathHelper.isValidSourceFile(filename) || filename.indexOf('.') == -1 || (zipFilePath != null && PythonPathHelper.isValidSourceFile(zipFilePath))) {
// Keep on going as we were going...
} else if (definition instanceof IJavaDefinition) {
Log.log(new RuntimeException("Not currently able to convert JavaDefinition to URI."));
return null;
} else {
boolean giveError = true;
if (definition != null && definition.module instanceof IAbstractJavaClassModule) {
Log.log(new RuntimeException("Not currently able to convert AbstractJavaClassModule to URI."));
return null;
} else {
if (FileTypesPreferences.isValidDll(filename)) {
if (f.exists()) {
// It's a pyd or dll, let's check if it was a cython module to open it...
File parentFile = f.getParentFile();
File newFile = new File(parentFile, StringUtils.stripExtension(f.getName()) + "." + "pyx");
if (!newFile.exists()) {
newFile = new File(parentFile, StringUtils.stripExtension(f.getName()) + "." + "pxd");
}
if (!newFile.exists()) {
newFile = new File(parentFile, StringUtils.stripExtension(f.getName()) + "." + "pxi");
}
if (newFile.exists()) {
giveError = false;
file = newFile;
}
}
}
}
if (giveError) {
return null;
}
}
}
if (zipFilePath != null) {
Log.log(StringUtils.format("Not currently able to convert file with zip path to URI.\nFile: %s\nStart: %s\nEnd: %s\nZip path: %s\n", file, start, end, zipFilePath));
return null;
} else if (file instanceof IFile) {
IFile f = (IFile) file;
return f.getRawLocationURI();
} else if (file instanceof IPath) {
IPath path = (IPath) file;
return path.toFile().toURI();
} else if (file instanceof File) {
return ((File) file).toURI();
} else if (file instanceof URI) {
return (URI) file;
}
return null;
}
Aggregations