String fPath = def.o1[0];
if (fPath.equals("None")) {
if (TRACE_COMPILED_MODULES) {
System.out.println("CompiledModule.findDefinition:" + token + " = None");
}
Definition[] definition = new Definition[] { new Definition(def.o2[0], def.o2[1], token, null, null,
this) };
this.definitionsFoundCache.add(token, definition);
return definition;
}
File f = new File(fPath);
String foundModName = nature.resolveModule(f);
String foundAs = def.o1[1];
IModule mod;
if (foundModName == null) {
//this can happen in a case where we have a definition that's found from a compiled file which actually
//maps to a file that's outside of the pythonpath known by Pydev.
String n = FullRepIterable.getFirstPart(f.getName());
mod = AbstractModule.createModule(n, f, nature, true);
} else {
mod = nature.getAstManager().getModule(foundModName, nature, true);
}
if (TRACE_COMPILED_MODULES) {
System.out.println("CompiledModule.findDefinition: found at:" + mod.getName());
}
int foundLine = def.o2[0];
if (foundLine == 0 && foundAs != null && foundAs.length() > 0 && mod != null
&& state.canStillCheckFindSourceFromCompiled(mod, foundAs)) {
//TODO: The nature (and so the grammar to be used) must be defined by the file we'll parse
//(so, we need to know the system modules manager that actually created it to know the actual nature)
IModule sourceMod = AbstractModule.createModuleFromDoc(mod.getName(), f,
new Document(FileUtils.getPyFileContents(f)), nature, true);
if (sourceMod instanceof SourceModule) {
Definition[] definitions = (Definition[]) sourceMod.findDefinition(
state.getCopyWithActTok(foundAs), -1, -1, nature);
if (definitions.length > 0) {
this.definitionsFoundCache.add(token, definitions);
return definitions;
}
}
}
if (mod == null) {
mod = this;
}
int foundCol = def.o2[1];
if (foundCol < 0) {
foundCol = 0;
}
if (TRACE_COMPILED_MODULES) {
System.out.println("CompiledModule.findDefinition: found compiled at:" + mod.getName());
}
Definition[] definitions = new Definition[] { new Definition(foundLine + 1, foundCol + 1, token, null,
null, mod) };
this.definitionsFoundCache.add(token, definitions);
return definitions;
}
}