I have cloned the Kotlin Compiler Plugin template ...
# compiler
j
I have cloned the Kotlin Compiler Plugin template and after adding a new test I am getting the error next error:
Copy code
Module Module <CommonOne> doesn't contain package <http://com.foo.dev.app|com.foo.dev.app>
It is throwed inside this function:
Copy code
override fun getPackage(fqName: FqName): PackageViewDescriptor {
    val symbolProvider = session.symbolProvider
    if (symbolProvider.hasPackage(fqName)) {
        return FirPackageViewDescriptor(fqName, this)
    }
    error("Module $moduleData doesn't contain package $fqName")
}
The test file is
Copy code
// MODULE: CommonOne
// file: CommonOneFooDao.kt

package com.foo.common.one

import androidx.room.Dao

@Dao
interface CommonOneFooDao {

    fun foo()
}

// MODULE: FeatureOne(CommonOne)
// file: FeatureOneFooDao.kt

package com.foo.feature.one

import androidx.room.Dao

@Dao
interface FeatureOneFooDao {

    fun foo()
}


// MODULE: DevApp(FeatureOne, CommonOne)
// file: main.kt
package com.foo.dev.app.feature.one

fun main() {

}
The compiler plugin module package, ID, and so on is
com.foo.dev.app
, but I don't know why it is limiting to me to only work on those packages. On the other hand, is there a way to skip a module in the test file to be compiled by my plugin?
I guess this?
Copy code
// IGNORE_FIR
// IGNORE_BACKEND: ANY
Well,
IGNORE_BACKEND
cannot be used per module/file, it is global
b
We'll need a bit more information to help figure out what is going wrong. Could you provide the full stacktrace for the error?
On the other hand, is there a way to skip a module in the test file to be compiled by my plugin?
You can create a custom directive that skips registering your plugin when applied to a module. So in the
EnvironmentConfigurator
where your extensions are registered, you can skip if
module.directives
contains this directive.
j
Untitled
It would be nice if we can just get some comment checker to remove a file from being compiled, something like
// excluded
@bnorm if on all test
// file: …
I change the packages to include the one I am getting in the error, the test works.
b
This might be a problem with the
hasPackage
function from your
FirDeclarationgenerationExtension
. If the extension says it has the package but never actually generates anything in that package, you might get this exception. https://github.com/Kotlin/compiler-plugin-template/blob/master/compiler-plugin/src[…]ins/kotlin/compiler/plugin/template/fir/SimpleClassGenerator.kt That's my guess right now at least, haven't had time to dig fully into this yet.
j
I commented the whole
SimpleClassGenerator
to create the mine one, which is not including that override 🤔
@bnorm I have seen this is not only failing on tests, but on a real project too