Skip to content

Commit

Permalink
Don't crash when using com.sun.tools.javac.* classes (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin authored Nov 24, 2023
1 parent 1046d3b commit 9252c10
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lightsaber/src/main/java/schwarz/it/lightsaber/Finding.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ internal fun Elements.getCodePosition(
annotationMirror: AnnotationMirror? = null,
annotationValue: AnnotationValue? = null,
): CodePosition {
try {
return try {
this as JavacElements
val pair = getTreeAndTopLevel(element, annotationMirror, annotationValue) ?: return CodePosition.Unknown
val sourceFile = pair.snd.sourcefile
val diagnosticSource = DiagnosticSource(sourceFile, null)
val line = diagnosticSource.getLineNumber(pair.fst.pos)
val column = diagnosticSource.getColumnNumber(pair.fst.pos, true)
CodePosition(sourceFile.name, line, column)
} catch (_: IllegalAccessError) {
println("w: To get the correct issue position you should run the compilation with `--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED`. More information here: https://github.com/SchwarzIT/dagger-lightsaber/issues/102 [Lightsaber]")
return CodePosition.Unknown
println("w: To get the correct issue position you should run the compilation with `--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED`. More information here: https://github.com/SchwarzIT/dagger-lightsaber/issues/102 [Lightsaber]")
CodePosition.Unknown
}
val pair = getTreeAndTopLevel(element, annotationMirror, annotationValue) ?: return CodePosition.Unknown
val sourceFile = pair.snd.sourcefile
val diagnosticSource = DiagnosticSource(sourceFile, null)
val line = diagnosticSource.getLineNumber(pair.fst.pos)
val column = diagnosticSource.getColumnNumber(pair.fst.pos, true)
return CodePosition(sourceFile.name, line, column)
}

internal fun Location.toCodePosition(): CodePosition {
Expand Down

0 comments on commit 9252c10

Please sign in to comment.