Leland Takamine
12/19/2019, 11:08 PM// Transform all instances of this call...
foo()
// ...into this via a compiler plugin:
foo("Hello")
I'm playing around with CallResolutionInterceptorExtension
but wondering if there are any other extensions I should be looking at.jereksel
12/20/2019, 5:24 AMjereksel
12/20/2019, 5:24 AMLeland Takamine
12/20/2019, 6:52 PMLeland Takamine
12/21/2019, 12:38 AMclass FooExpressionCodegenExtension(private val project: Project) : ExpressionCodegenExtension {
override fun applyFunction(
receiver: StackValue,
resolvedCall: ResolvedCall<*>,
c: ExpressionCodegenExtension.Context
): StackValue? {
val newExpression = KtPsiFactory(project).createExpression("foo()")
return c.codegen.gen(newExpression)
}
}
With the code above I'm getting the following error:
No resolved call for 'foo()' at (2,1) in dummy.kt
I've taken a look at some different API's and it seems like I'm always getting stuck figuring out how to provide a ResolvedCall
. Are there any examples I can take a look at to figure this out or is there any tribal knowledge that anyone can provide here?Leland Takamine
12/21/2019, 1:10 AMreturn StackValue.expression(
Type.getMethodType("()V"),
KtPsiFactory(project).createExpression("foo()"),
c.codegen
)
jereksel
12/21/2019, 3:27 PMjereksel
12/21/2019, 3:30 PMjereksel
12/21/2019, 4:55 PMLeland Takamine
12/27/2019, 5:50 PM#line
/ #file
/ #function
/ etc macros:
// Swift
func logFunctionName(string: String = #function) {
print(string)
}
func myFunction() {
logFunctionName() // Prints "myFunction()".
}
Leland Takamine
01/06/2020, 9:30 PM