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

Reduce stubs boilerplate #464

Merged
merged 2 commits into from
Aug 8, 2019
Merged

Reduce stubs boilerplate #464

merged 2 commits into from
Aug 8, 2019

Conversation

klazuka
Copy link
Collaborator

@klazuka klazuka commented Aug 8, 2019

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.

@klazuka klazuka requested a review from ajalt August 8, 2019 16:05
@@ -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? =
Copy link
Collaborator

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.

Copy link
Collaborator Author

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> =
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@klazuka klazuka merged commit 5248ace into master Aug 8, 2019
@klazuka klazuka deleted the kl/stubs2 branch August 8, 2019 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants