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

Migrate ProvidesMethodFactoryCodeGen to KSP #806

Merged
merged 12 commits into from
Dec 11, 2023
1 change: 1 addition & 0 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {

compileOnly libs.auto.service.annotations
compileOnly libs.kotlin.compiler
compileOnly libs.ksp.compilerPlugin
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is for internal API access, see comment below

compileOnly libs.ksp.api

kapt libs.auto.service.processor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.devtools.ksp.getAnnotationsByType
import com.google.devtools.ksp.getDeclaredProperties
import com.google.devtools.ksp.getVisibility
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSValueParameter
Expand Down Expand Up @@ -581,3 +582,21 @@ internal fun assertNoDuplicateFunctions(
)
}
}

internal fun assertNoDuplicateFunctions(
declaringClass: KSClassDeclaration,
functions: Sequence<KSFunctionDeclaration>,
) {
// Check for duplicate function names.
val duplicateFunctions = functions
.groupBy { it.qualifiedName!!.asString() }
.filterValues { it.size > 1 }

if (duplicateFunctions.isNotEmpty()) {
throw KspAnvilException(
node = declaringClass,
message = "Cannot have more than one binding method with the same name in " +
"a single module: ${duplicateFunctions.keys.joinToString()}",
)
}
}
Loading