-
Notifications
You must be signed in to change notification settings - Fork 68
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
Reduce stubs boilerplate #464
Conversation
@@ -72,12 +73,106 @@ fun <T : PsiElement> PsiElement.parentOfType(vararg classes: KClass<out T>): T? | |||
inline fun <reified T : PsiElement> PsiElement.contextOfType(strict: Boolean = true): T? = | |||
PsiTreeUtil.getContextOfType(this, T::class.java, strict) | |||
|
|||
inline fun <reified T : PsiElement> PsiElement.childOfType(strict: Boolean = true): T? = | |||
PsiTreeUtil.findChildOfType(this, T::class.java, strict) | |||
inline fun <reified T : PsiElement> PsiElement.descendantOfType(): T? = |
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.
Love this rename; I've had to look through the source code multiple times to remember whether this was only direct children or not.
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.
I know, I can't believe that they have built so much code on such poor naming conventions. There were undoubtedly a lot of bugs along the way.
} | ||
} | ||
|
||
inline fun <reified T : PsiElement> PsiElement.stubDescendantsOfTypeStrict(): Collection<T> = |
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 use a strict
parameter rather than separate functions for the strict case? It's fine either way.
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.
I copied this straight from intellij-rust. I don't have a preference either, at least not yet.
Last night I started looking at putting type annotations into the stub system, but it was going to require a ton of boilerplate. Luckily intellij-rust has already dealt with the problem. This should make it a little bit easier to do.