https://kotlinlang.org logo
#codereview
Title
# codereview
m

Marcello Galhardo

03/20/2023, 3:44 PM
I have a few functions that would be peffect as extension functions. BUT they are only relevant in a specific context (feature package) and I do not want to pollute the whole public namespace of their receiver classes. For context: I’m currently using Soong (not Gradle), and I can’t simple create a module for the feature, so
internal
is not an option. What is the best practice for those cases? Currently, I’m considering to introduce a
object Utils
to hold the functions and limit visibility to reduce pollution but I don’t like it. Maybe there is an alternative approach that I’m not aware of.
I’m not sure if there is a way to do that, but if I could create extension functions that do not appear in the auto-complete but could still be used, that should be good enough I guess to reduce pollution… I guess. 🤔
l

LeoColman

03/20/2023, 5:20 PM
An ugly workaround might be to
@Deprecated
it with
Warning
setting. It will be deprioritized on suggestions and still usable
m

Marcello Galhardo

03/20/2023, 6:09 PM
FYI, my current solution is: 1. Wrapped all extensions in an object. IDEA shows it as last in the auto-complete, it seems. 2. Added an
InternalApi
annotation as an error so people at least is warned if they try to use it.
e

ephemient

03/20/2023, 6:16 PM
if you can modify the build system to add the right
-Xfriend-paths
to the compiler args of dependent modules, you can use
internal
3 Views