-
Notifications
You must be signed in to change notification settings - Fork 294
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
add symbol validation API #128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried on a larger project to see if the visitor is complete?
@@ -78,6 +79,14 @@ fun KSDeclaration.isLocal(): Boolean { | |||
return this.parentDeclaration != null && this.parentDeclaration !is KSClassDeclaration | |||
} | |||
|
|||
/** | |||
* Perform a validation on a given symbol to check if all interested types in symbols enclosed scope are valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you define valid? E.g., all immediate type references are resolvable.
@@ -78,6 +79,14 @@ fun KSDeclaration.isLocal(): Boolean { | |||
return this.parentDeclaration != null && this.parentDeclaration !is KSClassDeclaration | |||
} | |||
|
|||
/** | |||
* Perform a validation on a given symbol to check if all interested types in symbols enclosed scope are valid. | |||
* @param shouldValidate: A lambda for filtering interested symbols. Default checks all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe explain why filtering is needed, i.e., performance.
api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt
Show resolved
Hide resolved
api/src/main/kotlin/com/google/devtools/ksp/visitor/KSValidateVisitor.kt
Show resolved
Hide resolved
} | ||
|
||
override fun visitPropertyDeclaration(property: KSPropertyDeclaration, data: Unit): Boolean { | ||
if (property.type.resolve().isError) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be property.type.accept(this, Unit)
, so that shouldValidate
has a chance to skip it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is to skip before jumping into this check, since when checking a property, its type should be valid for the property to be valid.
* Perform a validation on a given symbol to check if all interested types in symbols enclosed scope are valid, i.e. resolvable. | ||
* @param predict: A lambda for filtering interested symbols for performance purpose. Default checks all. | ||
*/ | ||
fun KSNode.validate(predict: (KSNode, KSNode) -> Boolean = { _, _-> true } ): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/predict/predicate/g
No description provided.