Ruslan Latypov
10/31/2024, 7:41 PMclass Test () {
fun test() {
val a: List<Person> = someFunction()
}
}
into:
class Test(private val someContext: SomeContext) {
fun test() {
val a: List<Person> = someFunction(SOME_ID, someContext.someField)
}
}
We're using an FirTransformer to transform constructors and function's callsites and we are using FirDeclarationGenerationExtension to create the property and to bind it's initializer to the constructor's parameter.
The property generation part looks like:
val property = createMemberProperty(...)
property.replaceInitializer(buildPropertyAccessExpression(...))
The transformations look fine until we get a function call inside an init block:
init {
val a: List<Person> = someFunction()
}
In the case when the function is called inside an init block, the property is not initialized yet and it's null.
Is there a way we can define order of initialization for the property to make sure it's initialized before the init block?Javier
10/31/2024, 10:22 PMRuslan Latypov
11/01/2024, 9:49 AMJavier
11/01/2024, 9:55 AMRuslan Latypov
11/01/2024, 10:41 AMJavier
11/02/2024, 7:36 PMRuslan Latypov
11/03/2024, 4:31 PMJavier
11/03/2024, 4:47 PMdmitriy.novozhilov
11/04/2024, 9:31 AMdmitriy.novozhilov
11/04/2024, 9:31 AMRuslan Latypov
11/04/2024, 12:36 PMclass Test () {
fun test() {
val a: List<Person> = someFunction()
}
}
into:
class Test(private val someContext: SomeContext) {
fun test() {
val a: List<Person> = someFunction(SOME_ID, someContext.someField)
}
}
We are adding a parameter to the constructor, a property to the class and transforming a function's callsite to use the property and an integer.dmitriy.novozhilov
11/04/2024, 12:39 PMRuslan Latypov
11/04/2024, 12:44 PMdmitriy.novozhilov
11/04/2024, 12:49 PM// compose
// user writes
@Composable fun foo() {}
@Composable fun bar() {
foo()
}
// transformed code
fun foo(c: Composer) {}
fun bar(c: Composer) {
foo(c)
}
// serialization
// user writes
@Serializable
class Some
fun foo(s: Some) {
Some.serialize(s)
}
// plugin generates
@Serializable
class Some {
companion object {
fun serialize(s: Some)
}
}
Ruslan Latypov
11/04/2024, 3:54 PMclass Test () {
fun test() {
val a: List<Person> = someFunction()
}
}
And we have framework defining the function:
someFunction(a: Int, context: SomeContext)
So the transformed code looks like this:
class Test(private val someContext: SomeContext) {
fun test() {
val a: List<Person> = someFunction(SOME_ID, someContext.someField)
}
}
Ruslan Latypov
11/04/2024, 3:55 PMclass Test ()
into:
class Test(private val someContext: SomeContext) {
And:
someFunction()
into
someFunction(SOME_ID, someContext.someField)
dmitriy.novozhilov
11/04/2024, 3:57 PMfun someFunction()
in the framework, all transformation could be moved to the IRRuslan Latypov
11/04/2024, 3:58 PMdmitriy.novozhilov
11/04/2024, 3:58 PM