Refactoring

This commit is contained in:
Valentin Kipyatkov
2020-02-10 11:18:35 +02:00
parent 1b5b0d2839
commit f60d24c621
3 changed files with 11 additions and 10 deletions
@@ -100,14 +100,14 @@ class InflowSlicer(
&& function.hasModifier(KtTokens.OPERATOR_KEYWORD) && function.hasModifier(KtTokens.OPERATOR_KEYWORD)
) { ) {
ReferencesSearch.search(function, parentUsage.scope.toSearchScope()) ReferencesSearch.search(function, analysisScope)
.filterIsInstance<KtPropertyDelegationMethodsReference>() .filterIsInstance<KtPropertyDelegationMethodsReference>()
.forEach { (it.element.parent as? KtProperty)?.processPropertyAssignments() } .forEach { (it.element.parent as? KtProperty)?.processPropertyAssignments() }
} }
val parameterDescriptor = parameter.resolveToParameterDescriptorIfAny(BodyResolveMode.FULL) ?: return val parameterDescriptor = parameter.resolveToParameterDescriptorIfAny(BodyResolveMode.FULL) ?: return
(function as? KtFunction)?.processCalls(parentUsage.scope.toSearchScope(), includeOverriders) body@{ (function as? KtFunction)?.processCalls(analysisScope, includeOverriders) body@{
val refElement = it.element ?: return@body val refElement = it.element ?: return@body
val refParent = refElement.parent val refParent = refElement.parent
@@ -132,7 +132,7 @@ class InflowSlicer(
} }
if (parameter.valOrVarKeyword.toValVar() == KotlinValVar.Var) { if (parameter.valOrVarKeyword.toValVar() == KotlinValVar.Var) {
processAssignments(parameter, parentUsage.scope.toSearchScope()) processAssignments(parameter, analysisScope)
} }
} }
@@ -201,7 +201,6 @@ class InflowSlicer(
} }
private fun KtProperty.processPropertyAssignments() { private fun KtProperty.processPropertyAssignments() {
val analysisScope = parentUsage.scope.toSearchScope()
val accessSearchScope = if (isVar) { val accessSearchScope = if (isVar) {
analysisScope analysisScope
} else { } else {
@@ -272,7 +271,7 @@ class InflowSlicer(
private fun PsiElement.passDeclarationToProcessorWithOverriders() { private fun PsiElement.passDeclarationToProcessorWithOverriders() {
passToProcessor() passToProcessor()
HierarchySearchRequest(this, parentUsage.scope.toSearchScope()) HierarchySearchRequest(this, analysisScope)
.searchOverriders() .searchOverriders()
.forEach { it.namedUnwrappedElement?.passToProcessor() } .forEach { it.namedUnwrappedElement?.passToProcessor() }
} }
@@ -41,7 +41,7 @@ class OutflowSlicer(
val accessKind = if (withDereferences) AccessKind.READ_OR_WRITE else AccessKind.READ_ONLY val accessKind = if (withDereferences) AccessKind.READ_OR_WRITE else AccessKind.READ_ONLY
processVariableAccesses( processVariableAccesses(
variable, variable,
parentUsage.scope.toSearchScope(), analysisScope,
accessKind accessKind
) body@{ ) body@{
val refElement = it.element val refElement = it.element
@@ -62,12 +62,12 @@ class OutflowSlicer(
private fun processFunction(function: KtFunction) { private fun processFunction(function: KtFunction) {
if (function is KtConstructor<*> || function is KtNamedFunction && function.name != null) { if (function is KtConstructor<*> || function is KtNamedFunction && function.name != null) {
function.processCalls(this.parentUsage.scope.toSearchScope(), includeOverriders = false) { function.processCalls(analysisScope, includeOverriders = false) {
when (val refElement = it.element) { when (val refElement = it.element) {
null -> (it.reference as? LightMemberReference)?.element?.passToProcessor() null -> (it.reference as? LightMemberReference)?.element?.passToProcessor()
is KtExpression -> { is KtExpression -> {
refElement.getCallElementForExactCallee()?.passToProcessor() refElement.getCallElementForExactCallee()?.passToProcessor()
refElement.getCallableReferenceForExactCallee()?.passToProcessor(this.parentUsage.lambdaLevel + 1) refElement.getCallableReferenceForExactCallee()?.passToProcessor(parentUsage.lambdaLevel + 1)
} }
else -> refElement.passToProcessor() else -> refElement.passToProcessor()
} }
@@ -88,8 +88,8 @@ class OutflowSlicer(
when (instr) { when (instr) {
is WriteValueInstruction -> instr.target.accessedDescriptor?.originalSource?.getPsi()?.passToProcessor() is WriteValueInstruction -> instr.target.accessedDescriptor?.originalSource?.getPsi()?.passToProcessor()
is CallInstruction -> { is CallInstruction -> {
if (this.parentUsage.lambdaLevel > 0 && instr.receiverValues[pseudoValue] != null) { if (parentUsage.lambdaLevel > 0 && instr.receiverValues[pseudoValue] != null) {
instr.element.passToProcessor(this.parentUsage.lambdaLevel - 1) instr.element.passToProcessor(parentUsage.lambdaLevel - 1)
} else { } else {
instr.arguments[pseudoValue]?.originalSource?.getPsi()?.passToProcessor() instr.arguments[pseudoValue]?.originalSource?.getPsi()?.passToProcessor()
} }
@@ -38,6 +38,8 @@ abstract class Slicer(
) { ) {
abstract fun processChildren() abstract fun processChildren()
protected val analysisScope = parentUsage.scope.toSearchScope()
protected class PseudocodeCache { protected class PseudocodeCache {
private val computedPseudocodes = HashMap<KtElement, Pseudocode>() private val computedPseudocodes = HashMap<KtElement, Pseudocode>()