Hello, I'm trying to create a compiler plugin to c...
# compiler
a
Hello, I'm trying to create a compiler plugin to create a
copy
method (as in data classes), but
open
for normal classes. I want to annotate a class and the IDE to know that a new method
copy
is available to use. I'm using
IrElementTransformerVoidWithContext
and
FirDeclarationGenerationExtension
to do the transformation, but when adding
SyntheticResolveExtension
to generate the synthetic method, the compiler throws the following error:
Copy code
FUN name:copy visibility:public modality:OPEN <> (a:<http://kotlin.Int|kotlin.Int>, value:kotlin.String) returnType:com.example.MyClass
  VALUE_PARAMETER name:id index:0 type:<http://kotlin.Int|kotlin.Int>
    EXPRESSION_BODY
      ERROR_EXPR 'Default Stub' type=<http://kotlin.Int|kotlin.Int>
  VALUE_PARAMETER name:value index:1 type:kotlin.String
    EXPRESSION_BODY
      ERROR_EXPR 'Default Stub' type=kotlin.String
...
Function has no body: FUN name:copy visibility:public modality:OPEN <> (id:<http://kotlin.Int|kotlin.Int>, value:kotlin.String) returnType:com.example.MyClass
Here is the code for the three classes: https://gist.github.com/alvr/6b03b122464226db79dd20d6cd1380bb
y
Btw, Synthetic resolve is for the old frontend, not FIR, hence it won't work or do anything on K2
I believe from your code you're accidentally generating a second copy method. I believe what you want is to find the copy method that got generated from FIR, and fill the body in the IR
nod 1
a
I got it working. Is there a way for the IDE to know that the class has a new function available for K2?
y
I think you can turn on K2 mode in IDE. IDE integration for K2 plugins should theoretically come "for free". You might also need to enable some flag to allow custom K2 plugins in IDE? I can't quite remember
a
Yes, I activated K2 mode and unchecked
kotlin.k2.only.bundled.compiler.plugins.enabled
in the registry, but still no autocompletion. The method is in red but compiling is working
y
If compiling is working, then it must be an IDE bug