Code refactoring

This commit is contained in:
Valentin Kipyatkov
2020-04-11 13:18:15 +03:00
parent 6928700320
commit 5040d37e2f
3 changed files with 8 additions and 8 deletions
@@ -16,6 +16,11 @@ import org.jetbrains.kotlin.psi.psiUtil.isAncestor
object CallSliceProducer : SliceProducer {
override fun produce(usage: UsageInfo, behaviour: KotlinSliceUsage.SpecialBehaviour?, parent: SliceUsage): Collection<SliceUsage>? {
if ((parent as? KotlinSliceUsage)?.behaviour is LambdaCallsBehaviour) {
// UsageInfo produced by LambdaCallsBehaviour has full call-element and does not require any processing
return null
}
when (val refElement = usage.element) {
null -> {
val element = (usage.reference as? LightMemberReference)?.element ?: return emptyList()
@@ -190,8 +190,8 @@ class InflowSlicer(
val anonymousFunction = accessedDescriptor.containingDeclaration as? AnonymousFunctionDescriptor
if (anonymousFunction != null && accessedDescriptor.name.asString() == "it") {
val functionLiteral = anonymousFunction.source.getPsi() as KtFunctionLiteral
val sliceTransformer = ArgumentSliceProducer(anonymousFunction.valueParameters.first())
processCalls(functionLiteral, false, sliceTransformer)
val parameterDescriptor = anonymousFunction.valueParameters.first()
processCalls(functionLiteral, false, ArgumentSliceProducer(parameterDescriptor))
}
} else {
accessedDeclaration.passDeclarationToProcessorWithOverriders()
@@ -148,12 +148,7 @@ class OutflowSlicer(
}
private fun processFunction(function: KtFunction) {
//TODO: CallSliceProducer in all cases
if (function is KtConstructor<*> || function is KtNamedFunction && function.name != null) {
processCalls(function, includeOverriders = false, sliceProducer = CallSliceProducer)
} else {
processCalls(function, false, SliceProducer.Trivial)
}
processCalls(function, includeOverriders = false, CallSliceProducer)
}
private fun processExtensionReceiver(declaration: KtCallableDeclaration, declarationWithBody: KtDeclarationWithBody) {