1
votes

I'm writing a custom JUnit runner that will have to collect some metadata for the test case under execution. At execution time, we access the test case object via reflection getting a Class object. This runner will be used in Scala, Java, and Kotlin test suites. How do I find which was the source code language that gave origin to a given Class object?

1
Educated guess: you can't. - Gyro Gearless
Compiled to jvm byte code. The artefacts that an object's class has in Scala and Kotlin. Try it out in a debugger. Also the .class file could have artefacts: javap. - Joop Eggen
passing some kind of additional arguments at the beginning of the test execution is also a good idea - Mr. Skip
Yeah, I think we will go with an extra VM argument to disambiguate - Humble Student
@GyroGearless Wrong guess. - Alexey Romanov

1 Answers

3
votes

For Scala, you can check if the class is annotated with scala.reflect.ScalaSignature or scala.reflect.ScalaLongSignature. Kotlin uses kotlin.Metadata for the same.