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