mardi 22 décembre 2020

Kotlin Reflection get parameter as String

I know that the title is probably misleading but I have no idea how to name it, so let me describe.

Lets take a simple assertion method

fun assertTrue(condition: Boolean) {
  Assert.assertTrue(condition)
}

Simple 'useless' wrapper. Then usage:

fun foo() {
  assertTrue((bool1 && bool2) || bool3)
}

Now in my assertTrue method I want to retrieve string like: "(bool1 && bool2) || bool3". I want to pass this to my logger so:

fun assertTrue(condition: Boolean) {
  logger.log("Condition [(bool1 && bool2) || bool3] == $condition")
  Assert.assertTrue(condition)
}

Is it possible to get this string via reflection or PsiManager?





Aucun commentaire:

Enregistrer un commentaire