Refine return type of MemberScope.getContributedFunctions

This commit is contained in:
Denis Zharkov
2016-03-11 15:50:21 +03:00
parent 50d258e7f4
commit 78c9dffe00
26 changed files with 81 additions and 63 deletions
@@ -50,7 +50,7 @@ public class CodegenUtil {
@NotNull ClassifierDescriptor returnedClassifier,
@NotNull ClassifierDescriptor... valueParameterClassifiers
) {
Collection<FunctionDescriptor> functions = owner.getDefaultType().getMemberScope().getContributedFunctions(name, NoLookupLocation.FROM_BACKEND);
Collection<SimpleFunctionDescriptor> functions = owner.getDefaultType().getMemberScope().getContributedFunctions(name, NoLookupLocation.FROM_BACKEND);
for (FunctionDescriptor function : functions) {
if (!CallResolverUtilKt.isOrOverridesSynthesized(function)
&& function.getTypeParameters().isEmpty()
@@ -413,7 +413,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
private boolean isGenericToArrayPresent() {
Collection<FunctionDescriptor> functions =
Collection<SimpleFunctionDescriptor> functions =
descriptor.getDefaultType().getMemberScope().getContributedFunctions(Name.identifier("toArray"), NoLookupLocation.FROM_BACKEND);
for (FunctionDescriptor function : functions) {
if (CallResolverUtilKt.isOrOverridesSynthesized(function)) {
@@ -203,7 +203,7 @@ public class SignaturesPropagationData {
Method autoSignature = null;
boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor);
for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
Collection<FunctionDescriptor> superFunctionCandidates =
Collection<SimpleFunctionDescriptor> superFunctionCandidates =
supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates)) continue;
@@ -46,7 +46,7 @@ class DynamicCallableDescriptors(private val builtIns: KotlinBuiltIns) {
p.println(javaClass.simpleName, ": dynamic candidates for " + call)
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
if (isAugmentedAssignmentConvention(name)) return listOf()
if (call.callType == Call.CallType.INVOKE
&& call.valueArgumentList == null && call.functionLiteralArguments.isEmpty()) {
@@ -17,10 +17,7 @@
package org.jetbrains.kotlin.resolve.lazy.descriptors
import com.google.common.collect.Sets
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.name.Name
@@ -49,7 +46,7 @@ protected constructor(
protected val storageManager: StorageManager = c.storageManager
private val classDescriptors: MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> = storageManager.createMemoizedFunction { resolveClassDescriptor(it) }
private val functionDescriptors: MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>> = storageManager.createMemoizedFunction { doGetFunctions(it) }
private val functionDescriptors: MemoizedFunctionToNotNull<Name, Collection<SimpleFunctionDescriptor>> = storageManager.createMemoizedFunction { doGetFunctions(it) }
private val propertyDescriptors: MemoizedFunctionToNotNull<Name, Collection<PropertyDescriptor>> = storageManager.createMemoizedFunction { doGetProperties(it) }
private fun resolveClassDescriptor(name: Name): List<ClassDescriptor> {
@@ -66,13 +63,13 @@ protected constructor(
return classDescriptors(name).firstOrNull()
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
recordLookup(name, location)
return functionDescriptors(name)
}
private fun doGetFunctions(name: Name): Collection<FunctionDescriptor> {
val result = Sets.newLinkedHashSet<FunctionDescriptor>()
private fun doGetFunctions(name: Name): Collection<SimpleFunctionDescriptor> {
val result = Sets.newLinkedHashSet<SimpleFunctionDescriptor>()
val declarations = declarationProvider.getFunctionDeclarations(name)
for (functionDeclaration in declarations) {
@@ -92,7 +89,7 @@ protected constructor(
protected abstract fun getScopeForMemberDeclarationResolution(declaration: KtDeclaration): LexicalScope
protected abstract fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>)
protected abstract fun getNonDeclaredFunctions(name: Name, result: MutableSet<SimpleFunctionDescriptor>)
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
recordLookup(name, location)
@@ -120,26 +120,26 @@ open class LazyClassMemberScope(
OverrideResolver.resolveUnknownVisibilities(result, trace)
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
// TODO: this should be handled by lazy function descriptors
val functions = super.getContributedFunctions(name, location)
resolveUnknownVisibilitiesForMembers(functions)
return functions
}
override fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>) {
override fun getNonDeclaredFunctions(name: Name, result: MutableSet<SimpleFunctionDescriptor>) {
val location = NoLookupLocation.FOR_ALREADY_TRACKED
val fromSupertypes = Lists.newArrayList<FunctionDescriptor>()
val fromSupertypes = Lists.newArrayList<SimpleFunctionDescriptor>()
for (supertype in thisDescriptor.typeConstructor.supertypes) {
fromSupertypes.addAll(supertype.memberScope.getContributedFunctions(name, location))
}
result.addAll(generateDelegatingDescriptors(name, EXTRACT_FUNCTIONS, result))
generateDataClassMethods(result, name, location)
generateFakeOverrides(name, fromSupertypes, result, FunctionDescriptor::class.java)
generateFakeOverrides(name, fromSupertypes, result, SimpleFunctionDescriptor::class.java)
}
private fun generateDataClassMethods(result: MutableCollection<FunctionDescriptor>, name: Name, location: LookupLocation) {
private fun generateDataClassMethods(result: MutableCollection<SimpleFunctionDescriptor>, name: Name, location: LookupLocation) {
if (!thisDescriptor.isData) return
val constructor = getPrimaryConstructor() ?: return
@@ -319,8 +319,8 @@ open class LazyClassMemberScope(
override fun toString() = "lazy scope for class ${thisDescriptor.name}"
companion object {
private val EXTRACT_FUNCTIONS: MemberExtractor<FunctionDescriptor> = object : MemberExtractor<FunctionDescriptor> {
override fun extract(extractFrom: KotlinType, name: Name): Collection<FunctionDescriptor> {
private val EXTRACT_FUNCTIONS: MemberExtractor<SimpleFunctionDescriptor> = object : MemberExtractor<SimpleFunctionDescriptor> {
override fun extract(extractFrom: KotlinType, name: Name): Collection<SimpleFunctionDescriptor> {
return extractFrom.memberScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}
}
@@ -37,7 +37,7 @@ class LazyPackageMemberScope(
override fun getScopeForMemberDeclarationResolution(declaration: KtDeclaration)
= resolveSession.fileScopeProvider.getFileResolutionScope(declaration.getContainingKtFile())
override fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>) {
override fun getNonDeclaredFunctions(name: Name, result: MutableSet<SimpleFunctionDescriptor>) {
// No extra functions
}
@@ -87,7 +87,7 @@ public class DataFlowAnalyzer {
}
private static boolean typeHasOverriddenEquals(@NotNull KotlinType type, @NotNull KtElement lookupElement) {
Collection<FunctionDescriptor> members = type.getMemberScope().getContributedFunctions(
Collection<SimpleFunctionDescriptor> members = type.getMemberScope().getContributedFunctions(
OperatorNameConventions.EQUALS, new KotlinLookupLocation(lookupElement));
for (FunctionDescriptor member : members) {
KotlinType returnType = member.getReturnType();
@@ -169,7 +169,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
Name functionName = Name.identifier(name);
MemberScope memberScope = packageView.getMemberScope();
Collection<FunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
Collection<SimpleFunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName();
return functions.iterator().next();
}
@@ -178,7 +178,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name functionName = Name.identifier(name);
MemberScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<FunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
Collection<SimpleFunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName();
return functions.iterator().next();
}
@@ -20,6 +20,7 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
@@ -72,7 +73,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
private void doTest(String text, String expected) {
KtFile jetFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text);
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
Collection<FunctionDescriptor> functions =
Collection<SimpleFunctionDescriptor> functions =
module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
assert functions.size() == 1 : "Many functions defined";
FunctionDescriptor function = ContainerUtil.getFirstItem(functions);
@@ -138,7 +138,7 @@ class LazyJavaPackageScope(
return deserializedPackageScope.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}
override fun getContributedFunctions(name: Name, location: LookupLocation): List<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): List<SimpleFunctionDescriptor> {
// We should track lookups here because this scope can be used for kotlin packages too (if it doesn't contain toplevel properties nor functions).
recordLookup(name, location)
return deserializedPackageScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED) + super.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)
@@ -72,7 +72,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
protected abstract fun getDispatchReceiverParameter(): ReceiverParameterDescriptor?
private val functions = c.storageManager.createMemoizedFunction<Name, Collection<FunctionDescriptor>> {
private val functions = c.storageManager.createMemoizedFunction<Name, Collection<SimpleFunctionDescriptor>> {
name ->
val result = LinkedHashSet<SimpleFunctionDescriptor>()
@@ -214,7 +214,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
return ResolvedValueParameters(descriptors, synthesizedNames)
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
recordLookup(name, location)
return functions(name)
}
@@ -48,8 +48,8 @@ class FunctionClassScope(
return allDescriptors()
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
return allDescriptors().filterIsInstance<FunctionDescriptor>().filter { it.name == name }
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
return allDescriptors().filterIsInstance<SimpleFunctionDescriptor>().filter { it.name == name }
}
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
@@ -178,14 +178,14 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
}
private class EnumEntryScope extends MemberScopeImpl {
private final MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>> functions;
private final MemoizedFunctionToNotNull<Name, Collection<SimpleFunctionDescriptor>> functions;
private final MemoizedFunctionToNotNull<Name, Collection<PropertyDescriptor>> properties;
private final NotNullLazyValue<Collection<DeclarationDescriptor>> allDescriptors;
public EnumEntryScope(@NotNull StorageManager storageManager) {
this.functions = storageManager.createMemoizedFunction(new Function1<Name, Collection<FunctionDescriptor>>() {
this.functions = storageManager.createMemoizedFunction(new Function1<Name, Collection<SimpleFunctionDescriptor>>() {
@Override
public Collection<FunctionDescriptor> invoke(Name name) {
public Collection<SimpleFunctionDescriptor> invoke(Name name) {
return computeFunctions(name);
}
});
@@ -206,25 +206,32 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
@NotNull
@Override
@SuppressWarnings({"unchecked"}) // KT-9898 Impossible implement kotlin interface in java
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations
// method is covariantly overridden in Kotlin, but collections in Java are invariant
@SuppressWarnings({"unchecked"})
public Collection getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
return properties.invoke(name);
}
@NotNull
@SuppressWarnings("unchecked")
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations
// method is covariantly overridden in Kotlin, but collections in Java are invariant
@SuppressWarnings({"unchecked"})
private Collection<PropertyDescriptor> computeProperties(@NotNull Name name) {
return resolveFakeOverrides(name, (Collection) getSupertypeScope().getContributedVariables(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE));
}
@NotNull
@Override
public Collection<FunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations
// method is covariantly overridden in Kotlin, but collections in Java are invariant
@SuppressWarnings({"unchecked"})
public Collection getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
return functions.invoke(name);
}
@NotNull
private Collection<FunctionDescriptor> computeFunctions(@NotNull Name name) {
private Collection<SimpleFunctionDescriptor> computeFunctions(@NotNull Name name) {
return resolveFakeOverrides(name, getSupertypeScope().getContributedFunctions(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE));
}
@@ -33,7 +33,7 @@ abstract class AbstractScopeAdapter : MemberScope {
else
workerScope
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
return workerScope.getContributedFunctions(name, location)
}
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.util.collectionUtils.getFirstMatch
@@ -35,7 +36,7 @@ class ChainedMemberScope(
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor>
= getFromAllScopes(scopes) { it.getContributedVariables(name, location) }
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor>
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor>
= getFromAllScopes(scopes) { it.getContributedFunctions(name, location) }
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
@@ -26,6 +26,7 @@ import java.lang.reflect.Modifier
interface MemberScope : ResolutionScope {
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor>
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor>
/**
* Is supposed to be used in tests and debug only
@@ -26,7 +26,7 @@ abstract class MemberScopeImpl : MemberScope {
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList()
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> = emptyList()
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> = emptyList()
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = emptyList()
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorFactory.createEnumValueOfMethod
@@ -34,14 +35,14 @@ class StaticScopeForKotlinEnum(private val containingClass: ClassDescriptor) : M
override fun getContributedClassifier(name: Name, location: LookupLocation) = null // TODO
private val functions: List<FunctionDescriptor> by lazy {
private val functions: List<SimpleFunctionDescriptor> by lazy {
listOf(createEnumValueOfMethod(containingClass), createEnumValuesMethod(containingClass))
}
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = functions
override fun getContributedFunctions(name: Name, location: LookupLocation) =
functions.filterTo(ArrayList<FunctionDescriptor>(1)) { it.name == name }
functions.filterTo(ArrayList<SimpleFunctionDescriptor>(1)) { it.name == name }
override fun printScopeStructure(p: Printer) {
p.println("Static scope for $containingClass")
@@ -184,15 +184,20 @@ public class ErrorUtils {
@NotNull
@Override
@SuppressWarnings({"unchecked"}) // KT-9898 Impossible implement kotlin interface in java
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations
// method is covariantly overridden in Kotlin, but collections in Java are invariant
@SuppressWarnings({"unchecked"})
public Set getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
return ERROR_PROPERTY_GROUP;
}
@NotNull
@Override
public Set<FunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
return Collections.<FunctionDescriptor>singleton(createErrorFunction(this));
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations
// method is covariantly overridden in Kotlin, but collections in Java are invariant
@SuppressWarnings({"unchecked"})
public Set getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
return Collections.singleton(createErrorFunction(this));
}
@NotNull
@@ -236,7 +241,10 @@ public class ErrorUtils {
@NotNull
@Override
public Collection<FunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations
// method is covariantly overridden in Kotlin, but collections in Java are invariant
@SuppressWarnings({"unchecked"})
public Collection getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException();
}
@@ -139,7 +139,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
return lowSixBits + rest
}
fun loadFunction(proto: ProtoBuf.Function): FunctionDescriptor {
fun loadFunction(proto: ProtoBuf.Function): SimpleFunctionDescriptor {
val flags = if (proto.hasFlags()) proto.flags else loadOldFlags(proto.oldFlags)
val annotations = getAnnotations(proto, flags, AnnotatedCallableKind.FUNCTION)
val receiverAnnotations = if (proto.hasReceiver())
@@ -203,8 +203,8 @@ class DeserializedClassDescriptor(
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors()
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
val fromSupertypes = ArrayList<FunctionDescriptor>()
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
val fromSupertypes = ArrayList<SimpleFunctionDescriptor>()
for (supertype in classDescriptor.getTypeConstructor().supertypes) {
fromSupertypes.addAll(supertype.memberScope.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED))
}
@@ -48,7 +48,7 @@ abstract class DeserializedMemberScope protected constructor(
}
private val functions =
c.storageManager.createMemoizedFunction<Name, Collection<FunctionDescriptor>> { computeFunctions(it) }
c.storageManager.createMemoizedFunction<Name, Collection<SimpleFunctionDescriptor>> { computeFunctions(it) }
private val properties =
c.storageManager.createMemoizedFunction<Name, Collection<PropertyDescriptor>> { computeProperties(it) }
@@ -63,7 +63,7 @@ abstract class DeserializedMemberScope protected constructor(
return map
}
private fun computeFunctions(name: Name): Collection<FunctionDescriptor> {
private fun computeFunctions(name: Name): Collection<SimpleFunctionDescriptor> {
val protos = functionProtos()[ProtoKey(name, isExtension = false)].orEmpty() +
functionProtos()[ProtoKey(name, isExtension = true)].orEmpty()
@@ -75,10 +75,10 @@ abstract class DeserializedMemberScope protected constructor(
return descriptors.toReadOnlyList()
}
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
protected open fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<SimpleFunctionDescriptor>) {
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
recordLookup(name, location)
return functions(name)
}
@@ -244,7 +244,7 @@ public class ManglingUtils {
@NotNull
public static String getStableMangledNameForDescriptor(@NotNull ClassDescriptor descriptor, @NotNull String functionName) {
Collection<FunctionDescriptor> functions =
Collection<SimpleFunctionDescriptor> functions =
descriptor.getDefaultType().getMemberScope().getContributedFunctions(Name.identifier(functionName), NoLookupLocation.FROM_BACKEND);
assert functions.size() == 1 : "Can't select a single function: " + functionName + " in " + descriptor;
return getSuggestedName((DeclarationDescriptor) functions.iterator().next());
@@ -16,7 +16,10 @@
package org.jetbrains.kotlin.android.synthetic.descriptors
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.FqName
@@ -31,10 +34,10 @@ class PredefinedPackageFragmentDescriptor(
module: ModuleDescriptor,
private val storageManager: StorageManager,
val subpackages: List<PackageFragmentDescriptor> = emptyList(),
private val descriptors: (PredefinedPackageFragmentDescriptor) -> Collection<DeclarationDescriptor> = { emptyList() }
private val functions: (PredefinedPackageFragmentDescriptor) -> Collection<SimpleFunctionDescriptor> = { emptyList() }
) : PackageFragmentDescriptorImpl(module, FqName(fqName)) {
private val calculatedDescriptors = storageManager.createLazyValue {
descriptors(this)
private val calculatedFunctions = storageManager.createLazyValue {
functions(this)
}
private val scope = PredefinedScope()
@@ -42,15 +45,14 @@ class PredefinedPackageFragmentDescriptor(
inner class PredefinedScope : MemberScopeImpl() {
@Suppress("UNCHECKED_CAST")
override fun getContributedVariables(name: Name, location: LookupLocation) =
calculatedDescriptors().filter { it is PropertyDescriptor && it.name == name } as List<PropertyDescriptor>
override fun getContributedVariables(name: Name, location: LookupLocation) = emptyList<PropertyDescriptor>()
@Suppress("UNCHECKED_CAST")
override fun getContributedFunctions(name: Name, location: LookupLocation) =
calculatedDescriptors().filter { it is FunctionDescriptor && it.name == name } as List<FunctionDescriptor>
calculatedFunctions().filter { it.name == name }
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) =
calculatedDescriptors().filter { nameFilter(it.name) && kindFilter.accepts(it) }
calculatedFunctions().filter { nameFilter(it.name) && kindFilter.accepts(it) }
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName)
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable
private class XmlSourceElement(override val psi: PsiElement) : PsiSourceElement
internal fun genClearCacheFunction(packageFragmentDescriptor: PackageFragmentDescriptor, receiverType: KotlinType): FunctionDescriptor {
internal fun genClearCacheFunction(packageFragmentDescriptor: PackageFragmentDescriptor, receiverType: KotlinType): SimpleFunctionDescriptor {
val function = object : AndroidSyntheticFunction, SimpleFunctionDescriptorImpl(
packageFragmentDescriptor,
null,