Hi, I'm writing (trying) a kotlin compiler plugin,...
# compiler
d
Hi, I'm writing (trying) a kotlin compiler plugin, which uses the IrGenerationExtension. I am trying to access dependencies of the module, and to iterate the declarations (Classes, etc) in each depended on module. How should I do this? I tried `
Copy code
moduleFragment.descriptor.allDependencyModules
but it does not seem to give me the depended on modules? I also tried `
Copy code
(pluginContext.symbolTable as SymbolTable).forEachPublicSymbol {
but I only get the symbols from the current module. some pointers in the right direction for either of these would be great, thanks
r
Why exactly do you need this? I'm not aware of a way, and it would be really slow if there is one.
d
1. I want to search for a particular set of classes on the class path by a regex pattern. 2. I want to find a something specific in each module separately
I don't mind too much if it is slow (with reason), I just need it to be possible.
It must be possible....the referenceClass function must ultimately access this information somehow!
via packageFragments I guess
I only need a IrClassSymbol in each case, not the IrClass
a
As far as I know, you only have access to the files of the current module, since each module is compiled independently. From descriptors you can get classes by package name, but they are built from already compiled files. Not sure if this is the default for files of another module of the current project. But I can be wrong
s
There's an extension on module descriptor, something like
findClassesInDependencies
. Don't remember exact name, but looks like something you want.
Note that it will find you a descriptor, not its IR
d
The qualified names of classses is sufficient, i can use that to get the irclassymbol. I can get all classes from a package fragment, and i can call getPackage(FqName), but that still needs the name of a package.
I feel there should be a path along the lines of, module.dependencies.packages.fragments.declarations. But i can’t find it.
findClassAcrossModuleDependencies
, but it requires a ClassId as parameter 😞
s
ClassId is just basically a fqName, no?
d
but it doesn't help, I need to get the list of classes without knowing the fqname classid or anything else
s
You can lookup that method and check what it is doing It goes through all descriptors and tries to find the matching one. You can copy the part you need from there :)
d
it uses getPackage(), which needs a package fqname. so I need to get a list of package fqnames to search.
and yes I've looked at the code for getPackage....it uses various things, all of which rely on knowing the package fqname up front. I can't find anywhere that holds or created the list of package fqnames, fragments or something similar. Some pointers would really help