diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtil.kt index cbeb5875b82..b40fbd43d58 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/pseudocodeUtil.kt @@ -192,7 +192,7 @@ public fun JetElement.getContainingPseudocode(context: BindingContext): Pseudoco ?: return null val enclosingPseudocodeDeclaration = (pseudocodeDeclaration as? JetFunctionLiteral)?.let { - it.parents(withItself = false).firstOrNull { it is JetDeclaration && it !is JetFunctionLiteral } as? JetDeclaration + it.parents.firstOrNull { it is JetDeclaration && it !is JetFunctionLiteral } as? JetDeclaration } ?: pseudocodeDeclaration val enclosingPseudocode = PseudocodeUtil.generatePseudocode(enclosingPseudocodeDeclaration, context) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt index e6c8853afa3..27eaf5eea8a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/createByPattern.kt @@ -26,10 +26,7 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.renderName -import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange -import org.jetbrains.kotlin.psi.psiUtil.endOffset -import org.jetbrains.kotlin.psi.psiUtil.parents -import org.jetbrains.kotlin.psi.psiUtil.startOffset +import org.jetbrains.kotlin.psi.psiUtil.* import java.util.ArrayList import java.util.HashMap import java.util.LinkedHashMap @@ -124,7 +121,7 @@ public fun createByPattern(pattern: String, vararg args: for ((range, text) in placeholders) { val token = resultElement.findElementAt(range.getStartOffset())!! - for (element in token.parents()) { + for (element in token.parentsWithSelf) { val elementRange = element.getTextRange().shiftRight(-start) if (elementRange == range && expectedElementType.isInstance(element)) { val pointer = pointerManager.createSmartPsiElementPointer(element) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt index 0251d529bbb..79befec138d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt @@ -38,10 +38,11 @@ public fun PsiElement.siblings(forward: Boolean = true, withItself: Boolean = tr return if (withItself) sequence else sequence.drop(1) } -public fun PsiElement.parents(withItself: Boolean = true): Sequence { - val sequence = sequence(this) { if (it is PsiFile) null else it.getParent() } - return if (withItself) sequence else sequence.drop(1) -} +public val PsiElement.parentsWithSelf: Sequence + get() = sequence(this) { if (it is PsiFile) null else it.getParent() } + +public val PsiElement.parents: Sequence + get() = parentsWithSelf.drop(1) public fun PsiElement.prevLeaf(skipEmptyElements: Boolean = false): PsiElement? = PsiTreeUtil.prevLeaf(this, skipEmptyElements) @@ -216,7 +217,7 @@ public fun PsiFile.elementsInRange(range: TextRange): List { val leaf = findFirstLeafWhollyInRange(this, currentRange) ?: break val element = leaf - .parents(withItself = true) + .parentsWithSelf .first { val parent = it.getParent() it is PsiFile || parent.getTextRange() !in currentRange diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt index c718b3beacc..26f0ddaee94 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/JetSelfTargetingIntention.kt @@ -26,6 +26,7 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.idea.JetBundle import org.jetbrains.kotlin.psi.JetElement import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf public abstract class JetSelfTargetingIntention( public val elementType: Class, @@ -55,13 +56,13 @@ public abstract class JetSelfTargetingIntention( var elementsToCheck: Sequence = sequence { null } if (leaf1 != null) { - elementsToCheck += leaf1.parents().takeWhile { it != commonParent } + elementsToCheck += leaf1.parentsWithSelf.takeWhile { it != commonParent } } if (leaf2 != null) { - elementsToCheck += leaf2.parents().takeWhile { it != commonParent } + elementsToCheck += leaf2.parentsWithSelf.takeWhile { it != commonParent } } if (commonParent != null) { - elementsToCheck += commonParent.parents() + elementsToCheck += commonParent.parentsWithSelf } val elementsOfType = elementsToCheck.filterIsInstance(elementType) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt index 8760c86b82c..062a09d427a 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/util/ShortenReferences.kt @@ -183,7 +183,7 @@ public class ShortenReferences(val options: (JetElement) -> Options = { Options. val elementSet = elements.toSet() val newElements = LinkedHashSet(elementSet.size()) for (element in elementSet) { - if (!element.parents(withItself = false).any { it in elementSet }) { + if (!element.parents.any { it in elementSet }) { newElements.add(element) } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt index 08d2c2695e3..c87d312ea8d 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionSession.kt @@ -43,10 +43,7 @@ import org.jetbrains.kotlin.idea.util.makeNotNullable import org.jetbrains.kotlin.lexer.JetTokens import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorKindExclude import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.isAncestor -import org.jetbrains.kotlin.psi.psiUtil.parents -import org.jetbrains.kotlin.psi.psiUtil.prevLeaf +import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo import org.jetbrains.kotlin.resolve.calls.callUtil.getCall @@ -96,7 +93,7 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess } } - protected val bindingContext: BindingContext = resolutionFacade.analyze(position.parents().firstIsInstance(), BodyResolveMode.PARTIAL_FOR_COMPLETION) + protected val bindingContext: BindingContext = resolutionFacade.analyze(position.parentsWithSelf.firstIsInstance(), BodyResolveMode.PARTIAL_FOR_COMPLETION) protected val inDescriptor: DeclarationDescriptor? = expression?.let { bindingContext.get(BindingContext.RESOLUTION_SCOPE, it)?.getContainingDeclaration() } private val kotlinIdentifierStartPattern: ElementPattern diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt index 3ac09e2ec6a..6ef026d1387 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/CompletionUtils.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.renderName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils @@ -220,7 +221,7 @@ fun thisExpressionItems(bindingContext: BindingContext, position: JetExpression, fun returnExpressionItems(bindingContext: BindingContext, position: JetElement): Collection { val result = ArrayList() - for (parent in position.parents()) { + for (parent in position.parentsWithSelf) { if (parent is JetDeclarationWithBody) { val returnsUnit = returnsUnit(parent, bindingContext) if (parent is JetFunctionLiteral) { @@ -279,7 +280,7 @@ fun breakOrContinueExpressionItems(position: JetElement, breakOrContinue: String val result = ArrayList() parentsLoop@ - for (parent in position.parents()) { + for (parent in position.parentsWithSelf) { when (parent) { is JetLoopExpression -> { if (result.isEmpty()) { diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt index bf4c83c1f23..289ff2e29f9 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/KotlinCompletionContributor.kt @@ -138,13 +138,13 @@ public class KotlinCompletionContributor : CompletionContributor() { } private fun isInFunctionLiteralParameterList(tokenBefore: PsiElement?): Boolean { - val parameterList = tokenBefore?.parents(false)?.firstOrNull { it is JetParameterList } ?: return false + val parameterList = tokenBefore?.parents?.firstOrNull { it is JetParameterList } ?: return false val parent = parameterList.getParent() return parent is JetFunctionLiteral && parent.getValueParameterList() == parameterList } private fun isInClassHeader(tokenBefore: PsiElement?): Boolean { - val classOrObject = tokenBefore?.parents(false)?.firstIsInstanceOrNull() ?: return false + val classOrObject = tokenBefore?.parents?.firstIsInstanceOrNull() ?: return false val name = classOrObject.getNameIdentifier() ?: return false val body = classOrObject.getBody() ?: return false val offset = tokenBefore!!.startOffset diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/CommentSaver.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/CommentSaver.kt index 6355121573f..85c3757aadc 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/CommentSaver.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/CommentSaver.kt @@ -207,7 +207,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB val token = original.findElementAt(element.getStartOffsetIn(createdElement) + rangeInOriginal.getStartOffset()) if (token != null) { val elementLength = element.getTextLength() - for (originalElement in token.parents()) { + for (originalElement in token.parentsWithSelf) { val length = originalElement.getTextLength() if (length < elementLength) continue if (length == elementLength) { @@ -396,7 +396,7 @@ public class CommentSaver(originalElements: PsiChildRange, private val saveLineB } private fun PsiElement.anchorToAddCommentOrSpace(before: Boolean): PsiElement { - return parents() + return parentsWithSelf .dropWhile { it.getParent() !is PsiFile && (if (before) it.getPrevSibling() else it.getNextSibling()) == null } .first() } diff --git a/idea/src/org/jetbrains/kotlin/idea/conversion/copy/DataForConversion.kt b/idea/src/org/jetbrains/kotlin/idea/conversion/copy/DataForConversion.kt index 6c8a3963c97..2e69c170aa4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/conversion/copy/DataForConversion.kt +++ b/idea/src/org/jetbrains/kotlin/idea/conversion/copy/DataForConversion.kt @@ -22,10 +22,7 @@ import com.intellij.openapi.util.TextRange import com.intellij.psi.* import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.platform.JavaToKotlinClassMap -import org.jetbrains.kotlin.psi.psiUtil.allChildren -import org.jetbrains.kotlin.psi.psiUtil.elementsInRange -import org.jetbrains.kotlin.psi.psiUtil.parents -import org.jetbrains.kotlin.psi.psiUtil.siblings +import org.jetbrains.kotlin.psi.psiUtil.* import java.util.ArrayList data class DataForConversion private( @@ -132,8 +129,8 @@ data class DataForConversion private( } private fun PsiElement.maximalParentToClip(range: TextRange): PsiElement? { - val firstNotInRange = parents().takeWhile { it !is PsiDirectory }.firstOrNull { it.range !in range } ?: return null - return firstNotInRange.parents().lastOrNull { it.minimizedTextRange() in range } + val firstNotInRange = parentsWithSelf.takeWhile { it !is PsiDirectory }.firstOrNull { it.range !in range } ?: return null + return firstNotInRange.parentsWithSelf.lastOrNull { it.minimizedTextRange() in range } } private fun PsiElement.minimizedTextRange(): TextRange { diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightExitPointsHandlerFactory.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightExitPointsHandlerFactory.kt index 573c9357ef4..87af908319c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightExitPointsHandlerFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightExitPointsHandlerFactory.kt @@ -83,7 +83,7 @@ private fun JetExpression.getRelevantFunction(): JetFunction? { if (this is JetReturnExpression) { (this.getTargetLabel()?.getReference()?.resolve() as? JetFunction)?.let { return it } } - for (parent in parents(false)) { + for (parent in parents) { if (InlineUtil.canBeInlineArgument(parent) && !InlineUtil.isInlinedArgument(parent as JetFunction, parent.analyze(), false)) { return parent as JetFunction } diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt index cdf616bead1..bdbd0010fd1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinRecursiveCallLineMarkerProvider.kt @@ -54,7 +54,7 @@ public class KotlinRecursiveCallLineMarkerProvider() : LineMarkerProvider { } private fun getEnclosingFunction(element: JetElement): JetNamedFunction? { - for (parent in element.parents(false)) { + for (parent in element.parents) { when (parent) { is JetFunctionLiteral -> if (!InlineUtil.isInlinedArgument(parent, parent.analyze(), false)) return null is JetNamedFunction -> if (!InlineUtil.isInlinedArgument(parent, parent.analyze(), false)) return parent diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt index 895e2aead83..e05afb48806 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/KotlinCleanupInspection.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm import kotlin.properties.Delegates @@ -64,7 +65,7 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe val diagnostics = analysisResult.bindingContext.getDiagnostics() class ProblemData(val problemDescriptor: ProblemDescriptor, elementToBeInvalidated: PsiElement) { - val depth = elementToBeInvalidated.parents(withItself = true).takeWhile { it !is PsiFile }.count() + val depth = elementToBeInvalidated.parentsWithSelf.takeWhile { it !is PsiFile }.count() } val problems = arrayListOf() diff --git a/idea/src/org/jetbrains/kotlin/idea/joinLines/JoinDeclarationAndAssignmentHandler.kt b/idea/src/org/jetbrains/kotlin/idea/joinLines/JoinDeclarationAndAssignmentHandler.kt index b3eb6277618..1ea38e1df56 100644 --- a/idea/src/org/jetbrains/kotlin/idea/joinLines/JoinDeclarationAndAssignmentHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/joinLines/JoinDeclarationAndAssignmentHandler.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.JetSimpleNameExpression import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.lexer.JetTokens import com.intellij.openapi.util.text.StringUtil +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf public class JoinDeclarationAndAssignmentHandler : JoinRawLinesHandlerDelegate { @@ -39,7 +40,7 @@ public class JoinDeclarationAndAssignmentHandler : JoinRawLinesHandlerDelegate { ?.siblings(forward = false, withItself = false) ?.firstOrNull { !isToSkip(it) } ?: return -1 - val pair = element.parents(withItself = true) + val pair = element.parentsWithSelf .map { getPropertyAndAssignment(it) } .filterNotNull() .firstOrNull() ?: return -1 diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt index 2006bc04a53..ac0d2b24eca 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt @@ -57,7 +57,7 @@ public class AddLoopLabelFix(loop: JetLoopExpression, val jumpExpression: JetEle usedLabels.add(expression.getLabelName()) } }) - element.parents(false).forEach { + element.parents.forEach { if (it is JetLabeledExpression) { usedLabels.add(it.getLabelName()) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index cf16e0c0a25..106248d2cb0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -531,7 +531,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { fun addNextToOriginalElementContainer(addBefore: Boolean): JetNamedDeclaration { val actualContainer = (containingElement as? JetClassOrObject)?.getBody() ?: containingElement - val sibling = config.originalElement.parents().first { it.getParent() == actualContainer } + val sibling = config.originalElement.parentsWithSelf.first { it.getParent() == actualContainer } return if (addBefore) { actualContainer.addBefore(declaration, sibling) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt index 42a30280928..3d287989a93 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt @@ -43,7 +43,7 @@ object CreateLocalVariableActionFactory: JetSingleIntentionActionFactory() { val propertyName = refExpr.getReferencedName() - val container = refExpr.parents(false) + val container = refExpr.parents .filter { it is JetBlockExpression || it is JetDeclarationWithBody } .firstOrNull() as? JetElement ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterActionFactory.kt index ca2b5b3a18c..60bfe2d3729 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterActionFactory.kt @@ -75,11 +75,11 @@ object CreateParameterActionFactory: JetSingleIntentionActionFactory() { fun chooseContainingClass(it: PsiElement): JetClass? { valOrVar = if (varExpected) JetValVar.Var else JetValVar.Val - return it.parents(false).firstIsInstanceOrNull() as? JetClass + return it.parents.firstIsInstanceOrNull() as? JetClass } // todo: skip lambdas for now because Change Signature doesn't apply to them yet - val container = refExpr.parents(false) + val container = refExpr.parents .filter { it is JetNamedFunction || it is JetPropertyAccessor || it is JetClassBody || it is JetClassInitializer || it is JetDelegationSpecifier diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index 28eb54d5136..be8203e127e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -584,7 +584,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration( // Ascend to the level of targetSibling val targetParent = targetSibling.getParent() - marginalCandidate.parents().first { it.getParent() == targetParent } + marginalCandidate.parentsWithSelf.first { it.getParent() == targetParent } } val shouldInsert = !(generatorOptions.inTempFile || generatorOptions.target == ExtractionTarget.FAKE_LAMBDALIKE_FUNCTION) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt index 3bc1f69c6b8..5aa12e2f160 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterHandler.kt @@ -49,10 +49,7 @@ import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext -import org.jetbrains.kotlin.psi.psiUtil.getValueParameterList -import org.jetbrains.kotlin.psi.psiUtil.getValueParameters -import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils import java.util.Collections @@ -90,7 +87,7 @@ public data class IntroduceParameterDescriptor( } } if (occurrencesToReplace.all { - PsiTreeUtil.findCommonParent(it.elements)?.parents()?.any(modifierIsUnnecessary) ?: false + PsiTreeUtil.findCommonParent(it.elements)?.parentsWithSelf?.any(modifierIsUnnecessary) ?: false }) JetValVar.None else JetValVar.Val } else JetValVar.None @@ -154,12 +151,12 @@ fun selectNewParameterContext( editor = editor, file = file, getContainers = { elements, parent -> - val parents = parent.parents(withItself = false) - val stopAt = (parent.parents(withItself = false) zip parent.parents(withItself = false).drop(1)) + val parents = parent.parents + val stopAt = (parent.parents zip parent.parents.drop(1)) .firstOrNull { isObjectOrNonInnerClass(it.first) } ?.second - (if (stopAt != null) parent.parents(withItself = false).takeWhile { it != stopAt } else parents) + (if (stopAt != null) parent.parents.takeWhile { it != stopAt } else parents) .filter { ((it is JetClass && !it.isInterface() && it !is JetEnumEntry) || it is JetNamedFunction || it is JetSecondaryConstructor) && ((it as JetNamedDeclaration).getValueParameterList() != null || it.getNameIdentifier() != null) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt index 3a6385ae8d2..53ad8302a78 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt @@ -42,6 +42,7 @@ import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetProperty import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.types.JetType import javax.swing.* import javax.swing.event.PopupMenuEvent @@ -164,7 +165,7 @@ public class KotlinInplacePropertyIntroducer( } override fun checkLocalScope(): PsiElement? { - return myElementToRename.parents().first { it is JetClassOrObject || it is JetFile } + return myElementToRename.parentsWithSelf.first { it is JetClassOrObject || it is JetFile } } override fun collectRefs(referencesSearchScope: SearchScope): MutableCollection? { diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt index 3ea12915df6..131b30d6ec7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/jetRefactoringUtil.kt @@ -151,7 +151,7 @@ public fun PsiElement.getAllExtractionContainers(strict: Boolean = true): List { fun getEnclosingDeclaration(element: PsiElement, strict: Boolean): PsiElement? { - return element.parents(!strict) + return (if (strict) element.parents else element.parentsWithSelf) .filter { (it is JetDeclarationWithBody && it !is JetFunctionLiteral) || it is JetClassInitializer diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt index b4fc6d7193a..58fb76b35b7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractPartialBodyResolveTest.kt @@ -104,7 +104,7 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur builder.append("----------------------------------------------\n") val skippedStatements = set - .filter { !it.parents(withItself = false).any { it in set } } // do not include skipped statements which are inside other skipped statement + .filter { !it.parents.any { it in set } } // do not include skipped statements which are inside other skipped statement .sortBy { it.getTextOffset() } myFixture.getProject().executeWriteCommand("") { diff --git a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractJetPsiUnifierTest.kt b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractJetPsiUnifierTest.kt index c74ff0f5f7d..10644ce6e7c 100644 --- a/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractJetPsiUnifierTest.kt +++ b/idea/tests/org/jetbrains/kotlin/psi/patternMatching/AbstractJetPsiUnifierTest.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.JetExpression import org.jetbrains.kotlin.psi.JetTypeReference import org.jetbrains.kotlin.psi.JetWhenCondition import org.jetbrains.kotlin.idea.test.DirectiveBasedActionUtils +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf public abstract class AbstractJetPsiUnifierTest: JetLightCodeInsightFixtureTestCase() { public fun doTest(filePath: String) { @@ -38,7 +39,7 @@ public abstract class AbstractJetPsiUnifierTest: JetLightCodeInsightFixtureTestC val start = selectionModel.getSelectionStart() val end = selectionModel.getSelectionEnd() val selectionRange = TextRange(start, end) - return file.findElementAt(start)?.parents()?.last { + return file.findElementAt(start)?.parentsWithSelf?.last { (it is JetExpression || it is JetTypeReference || it is JetWhenCondition) && selectionRange.contains(it.getTextRange() ?: TextRange.EMPTY_RANGE) } as JetElement diff --git a/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt index 58b72d85f34..b6e03bb816c 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/ForConverter.kt @@ -104,7 +104,7 @@ class ForConverter( statement.isInSingleLine()).assignNoPrototype() if (initializationConverted.isEmpty) return whileStatement - val kind = if (statement.parents(withItself = false).filter { it !is PsiLabeledStatement }.first() !is PsiCodeBlock) { + val kind = if (statement.parents.filter { it !is PsiLabeledStatement }.first() !is PsiCodeBlock) { WhileWithInitializationPseudoStatement.Kind.WITH_BLOCK } else if (hasNameConflict()) diff --git a/j2k/src/org/jetbrains/kotlin/j2k/JavaToKotlinConverter.kt b/j2k/src/org/jetbrains/kotlin/j2k/JavaToKotlinConverter.kt index 80ae8ef87d3..7c94473e34d 100644 --- a/j2k/src/org/jetbrains/kotlin/j2k/JavaToKotlinConverter.kt +++ b/j2k/src/org/jetbrains/kotlin/j2k/JavaToKotlinConverter.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.psi.psiUtil.parents +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf import org.jetbrains.kotlin.resolve.BindingContext import java.util.ArrayList import java.util.Comparator @@ -173,7 +174,7 @@ public class JavaToKotlinConverter( val file: PsiFile, val processings: Collection ) { - val depth: Int by Delegates.lazy { target.parents(withItself = true).takeWhile { it !is PsiFile }.count() } + val depth: Int by Delegates.lazy { target.parentsWithSelf.takeWhile { it !is PsiFile }.count() } } private fun buildExternalCodeProcessing(