Adapt changes in IDE after moving SAM adapters to synthetic scope

The main change is that now to get static sam adapters one should do it using synthetic scopes and static scope of container
This commit is contained in:
Mikhail Zarechenskiy
2017-05-02 15:03:17 +03:00
parent 8e233162ed
commit 429f0e4f68
8 changed files with 66 additions and 16 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
import org.jetbrains.kotlin.resolve.scopes.collectSyntheticMemberFunctions
import org.jetbrains.kotlin.resolve.scopes.collectSyntheticStaticFunctions
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
@@ -181,9 +182,10 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
val originalFunctionDescriptor = functionResolvedCall.resultingDescriptor.original as? FunctionDescriptor ?: return emptyList()
val containingClass = originalFunctionDescriptor.containingDeclaration as? ClassDescriptor ?: return emptyList()
val syntheticScopes = functionCall.getResolutionFacade().getFrontendService(SyntheticScopes::class.java)
// SAM adapters for static functions
val contributedFunctions = containingClass.staticScope.getContributedFunctions(
functionResolvedCall.resultingDescriptor.name, NoLookupLocation.FROM_IDE)
val contributedFunctions = syntheticScopes.collectSyntheticStaticFunctions(containingClass.staticScope)
for (staticFunWithSameName in contributedFunctions) {
if (staticFunWithSameName is SamAdapterDescriptor<*>) {
if (isSamAdapterSuitableForCall(staticFunWithSameName, originalFunctionDescriptor, samConstructorCallArgumentMap.size)) {
@@ -193,7 +195,6 @@ class RedundantSamConstructorInspection : AbstractKotlinInspection() {
}
// SAM adapters for member functions
val syntheticScopes = functionCall.getResolutionFacade().getFrontendService(SyntheticScopes::class.java)
val syntheticExtensions = syntheticScopes.collectSyntheticMemberFunctions(
listOf(containingClass.defaultType),
functionResolvedCall.resultingDescriptor.name,
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.core.OptionalParametersHelper
import org.jetbrains.kotlin.idea.core.resolveCandidates
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren
import org.jetbrains.kotlin.psi.psiUtil.parents
@@ -390,6 +391,13 @@ abstract class KotlinParameterInfoWithCallHandlerBase<TArgumentList : KtElement,
// we should not compare descriptors directly because partial resolve is involved
private fun descriptorsEqual(descriptor1: FunctionDescriptor, descriptor2: FunctionDescriptor): Boolean {
if (descriptor1.original == descriptor2.original) return true
val isSamDescriptor1 = descriptor1 is SamAdapterDescriptor<*>
val isSamDescriptor2 = descriptor2 is SamAdapterDescriptor<*>
// Previously it worked because of different order
// If descriptor1 is SamAdapter and descriptor2 isn't, this function shouldn't return `true` because of equal declaration
if (isSamDescriptor1 xor isSamDescriptor2) return false
val declaration1 = DescriptorToSourceUtils.descriptorToDeclaration(descriptor1) ?: return false
val declaration2 = DescriptorToSourceUtils.descriptorToDeclaration(descriptor2)
return declaration1 == declaration2