JSONObject describe = jsonResult.getJSONObject("describe");
String desc = describe.getString("desc");
if(areEqual(desc, "source file")) {
return new FindDefinitionResult(null, null);
}
if(!areEqual(desc, "identifier")) {
return new FindDefinitionResult(
"Selected name does not refer to a source element, rather it's a:\n" + desc, null);
}
JSONObject value = describe.getJSONObject("value");
String pathStr = value.getString("objpos");
// We will need to parse objpos from the end, because on Windows the filePath can contain the ':' char
String columnStr = StringUtil.segmentAfterLastMatch(pathStr, ":");
pathStr = StringUtil.substringUntilLastMatch(pathStr, ":");
String lineStr = StringUtil.segmentAfterLastMatch(pathStr, ":");
pathStr = StringUtil.substringUntilLastMatch(pathStr, ":");
if(columnStr == null || lineStr == null) {
throw new CommonException("No line or column position given.", null);
}
int line = parseInt(lineStr, "Invalid number for line: " + lineStr);
int column = parseInt(columnStr, "Invalid number for column: " + columnStr);
Path path = parsePath(pathStr);
return new FindDefinitionResult(null, new SourceLineColumnLocation(path, line, column));
}