aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorDaniel Santiago <danyboricua91@gmail.com>2021-09-02 16:16:28 -0700
committerlaszio <ting-yuan@users.noreply.github.com>2021-10-25 16:42:28 -0700
commitd06daf29816f4ce3f1c13094428fc7de12645c4e (patch)
tree2809aa79f1e3fca8bcce4eacc56b48878f94ba6d /api
parent0ccc06ddfd999f0567de5d6649040a250480722c (diff)
downloadksp-d06daf29816f4ce3f1c13094428fc7de12645c4e.tar.gz
Add annotation argument validation to validate API
Fixes: https://github.com/google/ksp/issues/603
Diffstat (limited to 'api')
-rw-r--r--api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt21
1 files changed, 20 insertions, 1 deletions
diff --git a/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt b/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt
index 3b1ef354..8e2747df 100644
--- a/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt
+++ b/api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt
@@ -41,7 +41,16 @@ open class KSValidateVisitor(
}
override fun visitAnnotation(annotation: KSAnnotation, data: KSNode?): Boolean {
- return !predicate(data, annotation) || annotation.annotationType.accept(this, annotation)
+ if (!predicate(data, annotation)) {
+ return true
+ }
+ if (!annotation.annotationType.accept(this, annotation)) {
+ return false
+ }
+ if (annotation.arguments.any { !it.accept(this, it) }) {
+ return false
+ }
+ return true
}
override fun visitTypeReference(typeReference: KSTypeReference, data: KSNode?): Boolean {
@@ -89,6 +98,16 @@ open class KSValidateVisitor(
return true
}
+ override fun visitValueArgument(valueArgument: KSValueArgument, data: KSNode?): Boolean {
+ fun visitValue(value: Any?): Boolean = when (value) {
+ is KSType -> this.validateType(value)
+ is KSAnnotation -> this.visitAnnotation(value, data)
+ is List<*> -> value.all { visitValue(it) }
+ else -> true
+ }
+ return visitValue(valueArgument.value)
+ }
+
override fun visitValueParameter(valueParameter: KSValueParameter, data: KSNode?): Boolean {
return valueParameter.type.accept(this, valueParameter)
}