Create from Usage: Support "Create member/extension" corresponding to the extension receiver of enclosing function

#KT-10668 Fixed
(cherry picked from commit bc4c013)
This commit is contained in:
Alexey Sedunov
2016-06-28 17:17:27 +03:00
parent 49b6811b44
commit 2abcd17713
16 changed files with 203 additions and 1 deletions
@@ -156,10 +156,18 @@ fun <T : PsiElement> T.getIfChildIsInBranch(element: PsiElement, branch: T.() ->
return if (branch().isAncestor(element)) this else null
}
fun <T : PsiElement> T.getIfChildIsInBranches(element: PsiElement, branches: T.() -> Iterable<PsiElement?>): T? {
return if (branches().any { it.isAncestor(element) }) this else null
}
inline fun <reified T : PsiElement> PsiElement.getParentOfTypeAndBranch(strict: Boolean = false, noinline branch: T.() -> PsiElement?): T? {
return getParentOfType<T>(strict)?.getIfChildIsInBranch(this, branch)
}
inline fun <reified T : PsiElement> PsiElement.getParentOfTypeAndBranches(strict: Boolean = false, noinline branches: T.() -> Iterable<PsiElement?>): T? {
return getParentOfType<T>(strict)?.getIfChildIsInBranches(this, branches)
}
tailrec fun PsiElement.getOutermostParentContainedIn(container: PsiElement): PsiElement? {
val parent = parent
return if (parent == container) this else parent?.getOutermostParentContainedIn(container)