Moved matcher
This commit is contained in:
@@ -48,7 +48,7 @@ object MatcherRegistrar {
|
|||||||
SumTransformationBase.Matcher,
|
SumTransformationBase.Matcher,
|
||||||
MaxOrMinTransformation.Matcher,
|
MaxOrMinTransformation.Matcher,
|
||||||
IntroduceIndexMatcher,
|
IntroduceIndexMatcher,
|
||||||
FilterTransformation.Matcher,
|
FilterTransformationBase.Matcher,
|
||||||
MapTransformation.Matcher,
|
MapTransformation.Matcher,
|
||||||
FlatMapTransformation.Matcher,
|
FlatMapTransformation.Matcher,
|
||||||
ForEachTransformation.Matcher
|
ForEachTransformation.Matcher
|
||||||
|
|||||||
+31
-31
@@ -31,36 +31,6 @@ abstract class FilterTransformationBase : SequenceTransformation {
|
|||||||
|
|
||||||
override val affectsIndex: Boolean
|
override val affectsIndex: Boolean
|
||||||
get() = true
|
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:
|
* Matches:
|
||||||
@@ -161,7 +131,7 @@ class FilterTransformation(
|
|||||||
indexVariable: KtCallableDeclaration?,
|
indexVariable: KtCallableDeclaration?,
|
||||||
condition: KtExpression,
|
condition: KtExpression,
|
||||||
isInverse: Boolean
|
isInverse: Boolean
|
||||||
): SequenceTransformation {
|
): FilterTransformationBase {
|
||||||
|
|
||||||
val effectiveCondition = if (isInverse) condition.negate() else condition
|
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(
|
class FilterIsInstanceTransformation(
|
||||||
override val loop: KtForExpression,
|
override val loop: KtForExpression,
|
||||||
override val inputVariable: KtCallableDeclaration,
|
override val inputVariable: KtCallableDeclaration,
|
||||||
|
|||||||
Reference in New Issue
Block a user