Hi, I'm trying to change the visibility on certai...
# compiler
a
Hi, I'm trying to change the visibility on certain functions from
public
to lower values. So, I created this a synthetic resolver with this method:
Copy code
override fun generateSyntheticMethods(
    thisDescriptor: ClassDescriptor,
    name: Name,
    bindingContext: BindingContext,
    fromSupertypes: List<SimpleFunctionDescriptor>,
    result: MutableCollection<SimpleFunctionDescriptor>
) {

    /* ... */
    result.elementAt(methodIndex).let { descriptor ->
        val replacement = descriptor.createCustomCopy {
            it.newCopyBuilder().setVisibility(newVisibility)
        }
        result.remove(descriptor)
        result.add(replacement)
    }
}
This works for if
newVisibility
is
private
and
protected
but does not work if it's
internal
and gives this error:
Copy code
Exception in thread "main" java.lang.NoSuchMethodError: dev.ahmedmourad.sample.SomeClass.functionName$ModuleName(Ljava/lang/String;)Ldev/ahmedmourad/sample/SomeClass;
	at dev.ahmedmourad.sample.MainKt.main(Main.kt:25)
	at dev.ahmedmourad.sample.MainKt.main(Main.kt)
I know that the
internal
modifier doesn't exist in the JVM and that synthetic methods are used to simulate it, so I guess I need to create a synthetic method whenever I change access to
internal
, how and where do I do that?
r
I'm not sure, but you might be able to look at how the allopen compiler plugin works and replicate it. I think it uses FIR, so most of that should be handled. It's in the kotlin repo.