diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt index bcd51198016..96ba9e8511b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/baseTransformations.kt @@ -23,7 +23,10 @@ import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.PsiChildRange -abstract class ReplaceLoopResultTransformation(final override val loop: KtForExpression): ResultTransformation { +/** + * Base class for [ResultTransformation]'s that replaces the loop-expression with the result call chain + */ +abstract class ReplaceLoopResultTransformation(final override val loop: KtForExpression) : ResultTransformation { override val commentSavingRange = PsiChildRange.singleElement(loop.unwrapIfLabeled()) @@ -35,6 +38,9 @@ abstract class ReplaceLoopResultTransformation(final override val loop: KtForExp } } +/** + * Base class for [ResultTransformation]'s that replaces initialization of a variable with the result call chain + */ abstract class AssignToVariableResultTransformation( final override val loop: KtForExpression, protected val initialization: VariableInitialization @@ -88,6 +94,9 @@ abstract class AssignToVariableResultTransformation( } } +/** + * [ResultTransformation] that replaces initialization of a variable with the call chain produced by the given [SequenceTransformation] + */ class AssignSequenceResultTransformation( private val sequenceTransformation: SequenceTransformation, initialization: VariableInitialization diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt index 70beabbe960..94819b230cc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/IntroduceIndexMatcher.kt @@ -29,6 +29,10 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.psi.psiUtil.isAncestor import java.util.* +/** + * Analyzes the rest of the loop and detects index variable manually incremented inside. + * So it does not produce any transformation in its result but adds an index variable. + */ object IntroduceIndexMatcher : TransformationMatcher { override val indexVariableAllowed: Boolean get() = false // old index variable is still needed - cannot introduce another one