if (testPath != null && testPath.length() > 0) {
testNode = NodeUtils.getNodeFromPath(node, testPath);
}
}
ItemPointer itemPointer;
if (testNode != null) {
itemPointer = new ItemPointer(file, testNode);
} else {
//Ok, it's not defined directly here (it's probably in a superclass), so, let's go on and
//do an actual (more costly) find definition.
try {
PySourceLocatorBase locator = new PySourceLocatorBase();
IFile workspaceFile = locator.getWorkspaceFile(file);
if (workspaceFile != null && workspaceFile.exists()) {
IProject project = workspaceFile.getProject();
if (project != null && project.exists()) {
PythonNature nature = PythonNature.getPythonNature(project);
String moduleName = nature.resolveModule(file);
if (moduleName != null) {
IModule mod = nature.getAstManager().getModule(moduleName, nature, true);
if (mod != null) {
ICompletionCache completionCache = new CompletionCache();
IDefinition[] definitions = mod.findDefinition(CompletionStateFactory
.getEmptyCompletionState(testPath, nature, completionCache), -1, -1, nature);
if (definitions != null && definitions.length > 0) {
List<ItemPointer> pointers = new ArrayList<ItemPointer>();
PyRefactoringFindDefinition.getAsPointers(pointers, (Definition[]) definitions);
if (pointers.size() > 0) {
return pointers.get(0);
}
}
}
}
}
}
} catch (Exception e) {
Log.log(e);
}
//if we couldn't actually get the definition line, at least open the file we had (although that may not really
//be the place where it's defined if it's a test in a superclass).
itemPointer = new ItemPointer(file);
}
return itemPointer;
}