Minor refactoring
This commit is contained in:
+2
-5
@@ -215,7 +215,7 @@ class FilterToTransformation private constructor(
|
||||
|
||||
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
|
||||
val lambda = if (indexVariable != null)
|
||||
generateLambda(effectiveCondition(), indexVariable, inputVariable)
|
||||
generateLambda(inputVariable, indexVariable, effectiveCondition())
|
||||
else
|
||||
generateLambda(inputVariable, condition)
|
||||
return chainedCallGenerator.generate("$functionName($0) $1:'{}'", targetCollection, lambda)
|
||||
@@ -289,10 +289,7 @@ class MapToTransformation private constructor(
|
||||
get() = "$functionName(){}"
|
||||
|
||||
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
|
||||
val lambda = if (indexVariable != null)
|
||||
generateLambda(mapping, indexVariable, inputVariable)
|
||||
else
|
||||
generateLambda(inputVariable, mapping)
|
||||
val lambda = generateLambda(inputVariable, indexVariable, mapping)
|
||||
return chainedCallGenerator.generate("$functionName($0) $1:'{}'", targetCollection, lambda)
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -34,10 +34,7 @@ class ForEachTransformation(
|
||||
get() = functionName + "{}"
|
||||
|
||||
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
|
||||
val lambda = if (indexVariable != null)
|
||||
generateLambda(statement, indexVariable, inputVariable)
|
||||
else
|
||||
generateLambda(inputVariable, statement)
|
||||
val lambda = generateLambda(inputVariable, indexVariable, statement)
|
||||
return chainedCallGenerator.generate("$functionName $0:'{}'", lambda)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class FilterTransformation(
|
||||
|
||||
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
|
||||
val lambda = if (indexVariable != null)
|
||||
generateLambda(effectiveCondition(), indexVariable, inputVariable)
|
||||
generateLambda(inputVariable, indexVariable, effectiveCondition())
|
||||
else
|
||||
generateLambda(inputVariable, condition)
|
||||
return chainedCallGenerator.generate("$0$1:'{}'", functionName, lambda)
|
||||
|
||||
+1
-4
@@ -40,10 +40,7 @@ class MapTransformation(
|
||||
get() = "$functionName{}"
|
||||
|
||||
override fun generateCode(chainedCallGenerator: ChainedCallGenerator): KtExpression {
|
||||
val lambda = if (indexVariable != null)
|
||||
generateLambda(mapping, indexVariable, inputVariable)
|
||||
else
|
||||
generateLambda(inputVariable, mapping)
|
||||
val lambda = generateLambda(inputVariable, indexVariable, mapping)
|
||||
return chainedCallGenerator.generate("$functionName$0:'{}'", lambda)
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,11 @@ fun generateLambda(inputVariable: KtCallableDeclaration, expression: KtExpressio
|
||||
return psiFactory.createExpressionByPattern("{ $0 }", lambdaExpression.bodyExpression!!) as KtLambdaExpression
|
||||
}
|
||||
|
||||
fun generateLambda(expression: KtExpression, indexVariable: KtCallableDeclaration, inputVariable: KtCallableDeclaration): KtLambdaExpression {
|
||||
fun generateLambda(inputVariable: KtCallableDeclaration, indexVariable: KtCallableDeclaration?, expression: KtExpression): KtLambdaExpression {
|
||||
if (indexVariable == null) {
|
||||
return generateLambda(inputVariable, expression)
|
||||
}
|
||||
|
||||
val lambdaExpression = generateLambda(expression, *arrayOf(indexVariable, inputVariable))
|
||||
|
||||
// replace "index++" with "index" or "index + 1" (see IntroduceIndexMatcher)
|
||||
|
||||
Reference in New Issue
Block a user