Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnnotationSuppressor now resolves Full Qualified Annotation Names without type solving #4570

Merged
merged 12 commits into from Feb 23, 2022
Expand Up @@ -39,13 +39,16 @@ class FullQualifiedNameGuesser internal constructor(
if (packageName != null) {
add("$packageName.$name")
}
if (name.first().isLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that reason we use a heuristic here: If the first character is lower case we assume it's a package name. Therefore I think this is to handle cases like dagger\..*. First uppercase indicates a class name and Component\..* would not be a valid case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @schalkms, I didn't see this comment before.

Yes the reason was that heuristic... but now that I think about that I'm not sure if this class needs to know about this. We could assume that any string that we can't match with an import could be a FullQualifiedName. But I don't know if that's better or worse... That's the issue with this mixed behaviour. The "general use cases" are easy to manage but all this edge cases are really difficult to manage because we can't know for sure.

add(name)
}
}
}
}

private fun findName(name: String): String? {
val searchName = name.substringBefore('.')
val resolvedName = resolvedNames[searchName]
val resolvedName = resolvedNames[searchName] ?: return null
return if (name == searchName) {
resolvedName
} else {
Expand Down
Expand Up @@ -61,6 +61,12 @@ class FullQualifiedNameGuesserSpec {
assertThat(sut.getFullQualifiedName("Static.Factory"))
.containsExactlyInAnyOrder("kotlin.jvm.JvmStatic.Factory")
}

@Test
fun `when don't use the import`() {
BraisGabin marked this conversation as resolved.
Show resolved Hide resolved
assertThat(sut.getFullQualifiedName("kotlin.jvm.JvmField"))
.containsExactlyInAnyOrder("kotlin.jvm.JvmField", "foo.kotlin.jvm.JvmField")
}
}

@Nested
Expand Down