Skip to content

Commit

Permalink
Add configuration to suppress name collision warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Nov 27, 2023
1 parent db900c8 commit 6933427
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package co.touchlab.skie.configuration.annotations

@Target
annotation class SuppressSkieWarning {

/**
* Suppresses a warning about SKIE renaming a declaration because of a name collision.
*/
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.BINARY)
annotation class NameCollision(val suppress: Boolean = true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.touchlab.skie.configuration

import co.touchlab.skie.configuration.annotations.SuppressSkieWarning

object SuppressSkieWarning {

/**
* If true, SKIE will not raise a warning that it renamed the given declaration because of a name collision.
*/
object NameCollision : ConfigurationKey.Boolean {

override val defaultValue: Boolean = false

override val skieRuntimeValue: Boolean = false

override fun getAnnotationValue(configurationTarget: ConfigurationTarget): Boolean? =
configurationTarget.findAnnotation<SuppressSkieWarning.NameCollision>()?.suppress
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

package co.touchlab.skie.util

import co.touchlab.skie.configuration.SuppressSkieWarning
import co.touchlab.skie.configuration.getConfiguration
import co.touchlab.skie.kir.element.KirCallableDeclaration
import co.touchlab.skie.kir.element.KirClass
import co.touchlab.skie.kir.element.KirElement
import co.touchlab.skie.kir.element.KirEnumEntry
import co.touchlab.skie.kir.element.classDescriptorOrNull
Expand Down Expand Up @@ -114,7 +117,7 @@ private inline fun <T, K : KirElement> T.resolveCollisionWithWarning(
val newName = getName()

val kirElement = findKirElement()
if (kirElement != null) {
if (kirElement != null && kirElement.shouldReportCollision) {
reportCollision(
originalName = originalName,
newName = newName,
Expand All @@ -132,6 +135,15 @@ private inline fun <T> T.resolveCollision(collisionReasonProvider: T.() -> Strin
} while (collisionReasonProvider() != null)
}

context(SirPhase.Context)
private val KirElement.shouldReportCollision: Boolean
get() = when (this) {
is KirCallableDeclaration<*> -> !getConfiguration(SuppressSkieWarning.NameCollision)
is KirClass -> !getConfiguration(SuppressSkieWarning.NameCollision)
is KirEnumEntry -> owner.shouldReportCollision
else -> true
}

context(SirPhase.Context)
private fun reportCollision(
originalName: String,
Expand All @@ -142,7 +154,8 @@ private fun reportCollision(
reporter.warning(
message = "'$originalName' was renamed to '$newName' because of a name collision with $collisionReason. " +
"Consider resolving the conflict either by changing the name in Kotlin, or via the @ObjCName annotation. " +
"Using renamed declarations from Swift is not recommended because their name will change if the conflict is resolved.",
"You can also suppress this warning using the 'SuppressSkieWarning.NameCollision' configuration. " +
"However using renamed declarations from Swift is not recommended because their name will change if the conflict is resolved.",
declaration = declarationDescriptor,
)
}

0 comments on commit 6933427

Please sign in to comment.