Introduce Property: Do not skip outer classes if extractable expression is contained in object literal. Skip outer classes of non-inner class
#KT-12084 Fixed (cherry picked from commit 2852f44)
This commit is contained in:
@@ -119,6 +119,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
|||||||
|
|
||||||
- [`KT-12294`](https://youtrack.jetbrains.com/issue/KT-12294) Introduce Property: Fix extraction of expressions referring to primary constructor parameters
|
- [`KT-12294`](https://youtrack.jetbrains.com/issue/KT-12294) Introduce Property: Fix extraction of expressions referring to primary constructor parameters
|
||||||
- [`KT-12413`](https://youtrack.jetbrains.com/issue/KT-12413) Change Signature: Fix bogus warning about unresolved type parameters/invalid functional type replacement
|
- [`KT-12413`](https://youtrack.jetbrains.com/issue/KT-12413) Change Signature: Fix bogus warning about unresolved type parameters/invalid functional type replacement
|
||||||
|
- [`KT-12084`](https://youtrack.jetbrains.com/issue/KT-12084) Introduce Property: Do not skip outer classes if extractable expression is contained in object literal
|
||||||
|
|
||||||
## 1.0.3
|
## 1.0.3
|
||||||
|
|
||||||
|
|||||||
@@ -146,20 +146,25 @@ fun KtFile.createTempCopy(text: String? = null): KtFile {
|
|||||||
fun PsiElement.getAllExtractionContainers(strict: Boolean = true): List<KtElement> {
|
fun PsiElement.getAllExtractionContainers(strict: Boolean = true): List<KtElement> {
|
||||||
val containers = ArrayList<KtElement>()
|
val containers = ArrayList<KtElement>()
|
||||||
|
|
||||||
var objectFound = false
|
var objectOrNonInnerNestedClassFound = false
|
||||||
val parents = if (strict) parents else parentsWithSelf
|
val parents = if (strict) parents else parentsWithSelf
|
||||||
for (element in parents) {
|
for (element in parents) {
|
||||||
val isValidContainer = when (element) {
|
val isValidContainer = when (element) {
|
||||||
is KtFile -> true
|
is KtFile -> true
|
||||||
is KtClassBody -> !objectFound || element.parent is KtObjectDeclaration
|
is KtClassBody -> !objectOrNonInnerNestedClassFound || element.parent is KtObjectDeclaration
|
||||||
is KtBlockExpression -> !objectFound
|
is KtBlockExpression -> !objectOrNonInnerNestedClassFound
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
if (!isValidContainer) continue
|
if (!isValidContainer) continue
|
||||||
|
|
||||||
containers.add(element as KtElement)
|
containers.add(element as KtElement)
|
||||||
|
|
||||||
((element as? KtClassBody)?.parent as? KtObjectDeclaration)?.let { objectFound = true }
|
if (!objectOrNonInnerNestedClassFound) {
|
||||||
|
val bodyParent = (element as? KtClassBody)?.parent
|
||||||
|
objectOrNonInnerNestedClassFound =
|
||||||
|
(bodyParent is KtObjectDeclaration && !bodyParent.isObjectLiteral())
|
||||||
|
|| (bodyParent is KtClass && !bodyParent.isInner())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return containers
|
return containers
|
||||||
|
|||||||
Reference in New Issue
Block a user