raulraja
06/18/2019, 3:16 PMPackageFragmentProviderExtension
and now I’m verifying that all the code is generated properly and I can even import classes and they compile fine from the command line. For example this compiles:
import sample.GeneratedClass
And also this:
Class.forName("sample.GeneratedClass")
I’m still seeing these issues:
1. This compiles fine only in the command line. IDEA still shows redlines for all the types it can’t find. Does IDEA use automatically the PackageFramentDescriptor
and SyntheticResolver
info or am I missing additional setup to get this to work on IDEA?
2. It only compiles fine with import sample.GeneratedClass
if its in the same module. If I add the compilation result with codegen as dependency in a different module it does not compile but shows instead:
sample/test.kt: (3, 21): Unresolved reference: GeneratedClass
Any help is appreciated, thanks!raulraja
06/18/2019, 6:14 PMclass SyntheticClassOrObjectDescriptor(
c: LazyClassContext,
parentClassOrObject: KtPureClassOrObject,
containingDeclaration: DeclarationDescriptor,
name: Name,
source: SourceElement,
outerScope: LexicalScope,
private val modality: Modality,
private val visibility: Visibility,
override val annotations: Annotations,
constructorVisibility: Visibility,
private val kind: ClassKind,
private val isCompanionObject: Boolean
)
If that is the case how can I obtain a KtPureClassOrObject
that actually is the package (not a class)?. The GeneratedClass
I’m adding goes top level into the package and it’s not a synthetic nested class.kralli
06/18/2019, 7:59 PMComponentRegistrar
and some other extensions are different for these two. IDEA directly utilizes the com.intellij
package, whereas the command line uses the those same classes but shadowed under the org.jetbrains.kotlin.com.intellij
package. That means that you have to build two separate versions of your compiler plugin using the gradle shadow plugin, which is really inconvenient.raulraja
06/18/2019, 8:04 PMkralli
06/18/2019, 8:05 PMkralli
06/18/2019, 8:08 PMSyntheticResolveExtension
KtPureClassOrObject
is only implemented by these classes. I don't think it is designed to create top-level classes.raulraja
06/18/2019, 8:09 PMraulraja
06/18/2019, 8:09 PMraulraja
06/18/2019, 8:09 PMraulraja
06/18/2019, 8:10 PMkralli
06/18/2019, 8:15 PMExpressionCodegenExtension
. Within that extension you can get hold of the ExpressionCodegenExtension.Context
. It contains the ExpressionCodegen
and more importantly the GenerationState
. That class is managing the classes that are getting generated via the ClassFileFactory
. There should be a way of telling it to generate your class. Might not be the prettiest way, but it probably works.raulraja
06/18/2019, 8:20 PMraulraja
06/18/2019, 8:20 PMraulraja
06/18/2019, 8:21 PMraulraja
06/18/2019, 8:22 PMkralli
06/19/2019, 5:50 AMkralli
06/19/2019, 5:53 AMdmitriy.novozhilov
06/19/2019, 7:59 AMCan someone confirm if this is case? What are other plugins like the serialization plugin or jetpack compose do in these cases?Yes, it's true that you need install separate IDEA plugin to support your compiler plugin in IDE. Serialization plugin for IDE is bundled into kotlin plugin. Plugin for Jetpack Compose most likely bundled into Android Studio
kralli
06/19/2019, 8:25 AMraulraja
06/19/2019, 8:48 AMdsavvinov
06/19/2019, 9:19 AMIf I create a Class the class is in the jar. Idea already parses .class content to determine structure. Isn’t the code I’m adding contributing to such structure?That’s true only for binary dependencies, in which case it is reasonable, because binary .jars rarely change. For source-code, IDEA doesn’t read produced jars (that would mean that after you’ve added several lines of code in your project, you have to recompile application completely), instead, it analyzes sources “on-the-fly”. Therefore, if some extensions (say, compiler plugins) add some declarations “on-the-fly” too, IDEA should be aware of it, and you’ll have to ship your own IDE plugin. Yeah, that’s not an ideal world, and theoretically, nothing prevents from improving it, but it’s just another non-trivial slab of work we have to do 🙂
dsavvinov
06/19/2019, 9:26 AMAre we expected to try to bundle our plugins inside the Kotlin plugin to take advantage of seamless adoption?No, you can ship separate IDEA plugin, which should be installed alongside with Kotlin Plugin. That’s how some large frameworks which rely on code generation heavily do, AFAIK
raulraja
06/19/2019, 9:57 AMdsavvinov
06/19/2019, 10:03 AMraulraja
06/19/2019, 12:48 PMdsavvinov
06/19/2019, 12:55 PMdsavvinov
06/19/2019, 12:58 PMI’d like to fix IDEA to automatically recognize generated membersYes, that’s a very nice feature, and if it were easy, we would have implemented it long ago.
Ryan Mentley
06/20/2019, 1:22 AMRyan Mentley
06/20/2019, 1:23 AM