private StackTraceElement buildStacktraceElement(String stacktraceLine) {
Matcher m = STACKTRACE_UNIVERSAL_JS_PATTERN.matcher(stacktraceLine);
if (!m.matches()) {
// wrong pattern !?
throw new STJSRuntimeException("Unknown location format:" + stacktraceLine);
}
try {
String methodName = m.group(STACKTRACE_GROUP_METHOD);
URL url = new URL(m.group(STACKTRACE_GROUP_LOCATION));
String file = url.getFile();
String[] fileParts = file.split(":");
// source file
String jsSourceFile = fileParts[0];
String sourceFile = jsSourceFile.replaceAll("\\.js$", ".java");
// java line
String cleanJsPath = url.getPath().split(":")[0];
int jsLineNumber = Integer.valueOf(fileParts[1]);
int line = getJavaLine(cleanJsPath, jsLineNumber);
String stjsPropertyFile = cleanJsPath.replaceAll("\\.js$", ".stjs");
// class name
String className = getClassName(stjsPropertyFile);
if (className == null) {
className = "<Unknown class>";
sourceFile = jsSourceFile;
}
return new StackTraceElement(className, methodName, sourceFile, line);
}
catch (MalformedURLException e) {
throw new STJSRuntimeException(e);
}
}