Skip to content

Commit

Permalink
JavaStackTrace: Added support stack frame element class loaders and m…
Browse files Browse the repository at this point in the history
…odules (#2658)
  • Loading branch information
RunDevelopment authored Nov 28, 2020
1 parent 0803525 commit 0bb4f09
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 11 deletions.
54 changes: 50 additions & 4 deletions components/prism-javastacktrace.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Specification:
// https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Throwable.html#printStackTrace()

Prism.languages.javastacktrace = {

// java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]
Expand Down Expand Up @@ -38,12 +41,30 @@ Prism.languages.javastacktrace = {

// at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
// at org.hsqldb.jdbc.Util.throwError(Unknown Source) here could be some notes
// at java.base/java.lang.Class.forName0(Native Method)
// at Util.<init>(Unknown Source)
// at com.foo.loader/foo@9.0/com.foo.Main.run(Main.java:101)
// at com.foo.loader//com.foo.bar.App.run(App.java:12)
// at acme@2.1/org.acme.Lib.test(Lib.java:80)
// at MyClass.mash(MyClass.java:9)
//
// More information:
// https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/StackTraceElement.html#toString()
//
// A valid Java module name is defined as:
// "A module name consists of one or more Java identifiers (§3.8) separated by "." tokens."
// https://docs.oracle.com/javase/specs/jls/se9/html/jls-6.html#jls-ModuleName
//
// A Java module version is defined by this class:
// https://docs.oracle.com/javase/9/docs/api/java/lang/module/ModuleDescriptor.Version.html
// This is the implementation of the `parse` method in JDK13:
// https://github.com/matcdac/jdk/blob/2305df71d1b7710266ae0956d73927a225132c0f/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java#L1108
// However, to keep this simple, a version will be matched by the pattern /@[\w$.+-]*/.
'stack-frame': {
pattern: /^[\t ]*at [\w$.]+(?:<init>)?\([^()]*\)/m,
pattern: /^[\t ]*at (?:[\w$./]|@[\w$.+-]*\/)+(?:<init>)?\([^()]*\)/m,
inside: {
'keyword': {
pattern: /^(\s*)at/,
pattern: /^(\s*)at(?= )/,
lookbehind: true
},
'source': [
Expand Down Expand Up @@ -74,8 +95,33 @@ Prism.languages.javastacktrace = {
],
'class-name': /[\w$]+(?=\.(?:<init>|[\w$]+)\()/,
'function': /(?:<init>|[\w$]+)(?=\()/,
'namespace': /[a-z]\w*/,
'punctuation': /[.()]/
'class-loader': {
pattern: /(\s)[a-z]\w*(?:\.[a-z]\w*)*(?=\/[\w@$.]*\/)/,
lookbehind: true,
alias: 'namespace',
inside: {
'punctuation': /\./
}
},
'module': {
pattern: /([\s/])[a-z]\w*(?:\.[a-z]\w*)*(?:@[\w$.+-]*)?(?=\/)/,
lookbehind: true,
inside: {
'version': {
pattern: /(@)[\s\S]+/,
lookbehind: true,
alias: 'number'
},
'punctuation': /[@.]/
}
},
'namespace': {
pattern: /(?:[a-z]\w*\.)+/,
inside: {
'punctuation': /\./
}
},
'punctuation': /[()/.]/
}
},

Expand Down
2 changes: 1 addition & 1 deletion components/prism-javastacktrace.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 195 additions & 6 deletions tests/languages/javastacktrace/stack-frame_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ at Main.main(Main.java:13)
at Main.main(Main.java:13) Same but with some additional notes
at com.foo.bar.Main$FooBar.main(Native Method)
at Main$FooBar.<init>(Unknown Source)
at java.base/java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(JavaUtilJarAccessImpl.java:69)
at java.base/java.lang.Class.forName0(Native Method)
at com.foo.loader/foo@9.0/com.foo.Main.run(Main.java:101)
at com.foo.loader//com.foo.bar.App.run(App.java:12)
at acme@2.1/org.acme.Lib.test(Lib.java:80)
at MyClass.mash(MyClass.java:9)

// not to forget our swiss friends
at at.foo.bar.Main$FooBar.main(Native Method)

----------------------------------------------------

Expand Down Expand Up @@ -37,12 +46,14 @@ at Main$FooBar.<init>(Unknown Source)

["stack-frame", [
["keyword", "at"],
["namespace", "com"],
["punctuation", "."],
["namespace", "foo"],
["punctuation", "."],
["namespace", "bar"],
["punctuation", "."],
["namespace", [
"com",
["punctuation", "."],
"foo",
["punctuation", "."],
"bar",
["punctuation", "."]
]],
["class-name", "Main$FooBar"],
["punctuation", "."],
["function", "main"],
Expand All @@ -63,6 +74,184 @@ at Main$FooBar.<init>(Unknown Source)
["keyword", "Unknown Source"]
]],
["punctuation", ")"]
]],

["stack-frame", [
["keyword", "at"],
["module", [
"java",
["punctuation", "."],
"base"
]],
["punctuation", "/"],
["namespace", [
"java",
["punctuation", "."],
"util",
["punctuation", "."],
"jar",
["punctuation", "."]
]],
["class-name", "JavaUtilJarAccessImpl"],
["punctuation", "."],
["function", "ensureInitialization"],
["punctuation", "("],
["source", [
["file", "JavaUtilJarAccessImpl.java"],
["punctuation", ":"],
["line-number", "69"]
]],
["punctuation", ")"]
]],

["stack-frame", [
["keyword", "at"],
["module", [
"java",
["punctuation", "."],
"base"
]],
["punctuation", "/"],
["namespace", [
"java",
["punctuation", "."],
"lang",
["punctuation", "."]
]],
["class-name", "Class"],
["punctuation", "."],
["function", "forName0"],
["punctuation", "("],
["source", [
["keyword", "Native Method"]
]],
["punctuation", ")"]
]],

["stack-frame", [
["keyword", "at"],
["class-loader", [
"com",
["punctuation", "."],
"foo",
["punctuation", "."],
"loader"
]],
["punctuation", "/"],
["module", [
"foo",
["punctuation", "@"],
["version", "9.0"]
]],
["punctuation", "/"],
["namespace", [
"com",
["punctuation", "."],
"foo",
["punctuation", "."]
]],
["class-name", "Main"],
["punctuation", "."],
["function", "run"],
["punctuation", "("],
["source", [
["file", "Main.java"],
["punctuation", ":"],
["line-number", "101"]
]],
["punctuation", ")"]
]],

["stack-frame", [
["keyword", "at"],
["class-loader", [
"com",
["punctuation", "."],
"foo",
["punctuation", "."],
"loader"
]],
["punctuation", "/"],
["punctuation", "/"],
["namespace", [
"com",
["punctuation", "."],
"foo",
["punctuation", "."],
"bar",
["punctuation", "."]
]],
["class-name", "App"],
["punctuation", "."],
["function", "run"],
["punctuation", "("],
["source", [
["file", "App.java"],
["punctuation", ":"],
["line-number", "12"]
]],
["punctuation", ")"]
]],

["stack-frame", [
["keyword", "at"],
["module", [
"acme",
["punctuation", "@"],
["version", "2.1"]
]],
["punctuation", "/"],
["namespace", [
"org",
["punctuation", "."],
"acme",
["punctuation", "."]
]],
["class-name", "Lib"],
["punctuation", "."],
["function", "test"],
["punctuation", "("],
["source", [
["file", "Lib.java"],
["punctuation", ":"],
["line-number", "80"]
]],
["punctuation", ")"]
]],

["stack-frame", [
["keyword", "at"],
["class-name", "MyClass"],
["punctuation", "."],
["function", "mash"],
["punctuation", "("],
["source", [
["file", "MyClass.java"],
["punctuation", ":"],
["line-number", "9"]
]],
["punctuation", ")"]
]],

"\n\n// not to forget our swiss friends\n",
["stack-frame", [
["keyword", "at"],
["namespace", [
"at",
["punctuation", "."],
"foo",
["punctuation", "."],
"bar",
["punctuation", "."]
]],
["class-name", "Main$FooBar"],
["punctuation", "."],
["function", "main"],
["punctuation", "("],
["source", [
["keyword", "Native Method"]
]],
["punctuation", ")"]
]]
]

Expand Down

0 comments on commit 0bb4f09

Please sign in to comment.