Wrapper around javac to output diagnostics in an easily-configurable way.
./gradlew assemble
will generate build/libs/javac-diagnostics-wrapper-all.jar
.
Simply use instead of your usual javac
command.
Instead of
javac [flags] File1.java File2.java
(where [flags]
is a placeholder for 0 or more actual javac flags you're using)
use
java \
-cp /path/to/javac-diagnostics-wrapper-all.jar \
io.github.wmdietl.diagnostics.json.lsp.Main \
[flags] File1.java File2.java
(where [flags]
is a placeholder for 0 or more actual javac flags you're using)
There are currently two supported output formats:
io.github.wmdietl.diagnostics.json.lsp.Main
produces output in the LSP JSON format.io.github.wmdietl.diagnostics.json.javac.Main
produces output in a JSON format directly corresponding to the javac diagnostics.
Normal compilation of a file with errors, using the javac format:
java \
-cp /path/to/javac-diagnostics-wrapper-all.jar \
io.github.wmdietl.diagnostics.json.javac.Main \
File1.java
results in
{
"diagnostics": [
{
"fileUri": "file:///.../File1.java",
"kind": "ERROR",
"position": 29,
"startPosition": 29,
"endPosition": 30,
"lineNumber": 2,
"columnNumber": 16,
"code": "compiler.err.prob.found.req",
"message": "incompatible types: int cannot be converted to java.lang.String"
},
{
"fileUri": "file:///.../File1.java",
"kind": "ERROR",
"position": 64,
"startPosition": 64,
"endPosition": 69,
"lineNumber": 4,
"columnNumber": 16,
"code": "compiler.err.prob.found.req",
"message": "incompatible types: unexpected return value"
}
]
}
Compilation of a file using the Checker Framework, using the LSP format:
java \
-cp /path/to/javac-diagnostics-wrapper-all.jar \
io.github.wmdietl.diagnostics.json.lsp.Main \
-classpath /path/to/checker-framework/checker/dist/checker.jar \
-processor org.checkerframework.checker.nullness.NullnessChecker \
File2.java
results in:
[
{
"uri": "file://.../File2.java",
"diagnostics": [
{
"range": {
"start": {
"line": 12,
"character": 14
},
"end": {
"line": 12,
"character": 16
}
},
"severity": 1,
"code": "compiler.err.proc.messager",
"source": "Main",
"message": "[argument.type.incompatible] incompatible types in argument.\n found : @Initialized @Nullable InputStream\n required: @Initialized @NonNull InputStream"
}
]
}
]
To format the source code, run ./gradlew spotlessApply
.