Moved matcher

This commit is contained in:
Valentin Kipyatkov
2016-10-14 16:49:16 +03:00
parent b28d016709
commit 49ef880f3a
2 changed files with 32 additions and 32 deletions
@@ -48,7 +48,7 @@ object MatcherRegistrar {
SumTransformationBase.Matcher,
MaxOrMinTransformation.Matcher,
IntroduceIndexMatcher,
FilterTransformation.Matcher,
FilterTransformationBase.Matcher,
MapTransformation.Matcher,
FlatMapTransformation.Matcher,
ForEachTransformation.Matcher
@@ -31,36 +31,6 @@ abstract class FilterTransformationBase : SequenceTransformation {
override val affectsIndex: Boolean
get() = true
}
class FilterTransformation(
override val loop: KtForExpression,
override val inputVariable: KtCallableDeclaration,
override val indexVariable: KtCallableDeclaration?,
val condition: KtExpression,
val isInverse: Boolean
) : FilterTransformationBase() {
override val effectiveCondition: KtExpression by lazy {
if (isInverse) condition.negate() else condition
}
private val functionName = when {
indexVariable != null -> "filterIndexed"
isInverse -> "filterNot"
else -> "filter"
}
override val presentation: String
get() = "$functionName{}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = if (indexVariable != null)
generateLambda(inputVariable, indexVariable, effectiveCondition)
else
generateLambda(inputVariable, condition)
return chainedCallGenerator.generate("$0$1:'{}'", functionName, lambda)
}
/**
* Matches:
@@ -161,7 +131,7 @@ class FilterTransformation(
indexVariable: KtCallableDeclaration?,
condition: KtExpression,
isInverse: Boolean
): SequenceTransformation {
): FilterTransformationBase {
val effectiveCondition = if (isInverse) condition.negate() else condition
@@ -192,6 +162,36 @@ class FilterTransformation(
}
}
class FilterTransformation(
override val loop: KtForExpression,
override val inputVariable: KtCallableDeclaration,
override val indexVariable: KtCallableDeclaration?,
val condition: KtExpression,
val isInverse: Boolean
) : FilterTransformationBase() {
override val effectiveCondition: KtExpression by lazy {
if (isInverse) condition.negate() else condition
}
private val functionName = when {
indexVariable != null -> "filterIndexed"
isInverse -> "filterNot"
else -> "filter"
}
override val presentation: String
get() = "$functionName{}"
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
val lambda = if (indexVariable != null)
generateLambda(inputVariable, indexVariable, effectiveCondition)
else
generateLambda(inputVariable, condition)
return chainedCallGenerator.generate("$0$1:'{}'", functionName, lambda)
}
}
class FilterIsInstanceTransformation(
override val loop: KtForExpression,
override val inputVariable: KtCallableDeclaration,