Create SyntheticMemberDescriptor interface

Implement this interface by sam adapters/constructors and use it in navigation

 #KT-11708 Fixed
This commit is contained in:
Pavel V. Talanov
2016-06-20 18:16:51 +03:00
parent 4087e650aa
commit bafe8e55ce
15 changed files with 106 additions and 48 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -18,12 +18,14 @@ package org.jetbrains.kotlin.load.java.sam;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.SourceElement;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.load.java.descriptors.JavaConstructorDescriptor;
import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
/* package */ class SamAdapterConstructorDescriptor extends JavaConstructorDescriptor implements SamAdapterDescriptor<JavaConstructorDescriptor> {
/* package */ class SamAdapterConstructorDescriptor extends JavaConstructorDescriptor
implements SamAdapterDescriptor<JavaConstructorDescriptor> {
private final JavaConstructorDescriptor declaration;
public SamAdapterConstructorDescriptor(@NotNull JavaConstructorDescriptor declaration) {
@@ -61,7 +63,7 @@ import org.jetbrains.kotlin.load.java.descriptors.SamAdapterDescriptor;
@NotNull
@Override
public JavaConstructorDescriptor getOriginForSam() {
public JavaConstructorDescriptor getBaseDescriptorForSynthetic() {
return declaration;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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,12 +45,6 @@ import org.jetbrains.kotlin.name.Name;
setParameterNamesStatus(declaration.hasStableParameterNames(), declaration.hasSynthesizedParameterNames());
}
@NotNull
@Override
public JavaMethodDescriptor getOriginForSam() {
return declaration;
}
@NotNull
@Override
protected JavaMethodDescriptor createSubstitutedCopy(
@@ -63,4 +57,10 @@ import org.jetbrains.kotlin.name.Name;
) {
return new SamAdapterFunctionDescriptor(newOwner, (SimpleFunctionDescriptor) original, kind, declaration);
}
@NotNull
@Override
public JavaMethodDescriptor getBaseDescriptorForSynthetic() {
return declaration;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -106,7 +106,7 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
return null;
}
SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getOriginForSam();
SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getBaseDescriptorForSynthetic();
return ((SimpleFunctionDescriptor) originalDeclarationOfSam.substitute(TypeSubstitutor.create(declarationOrSynthesized.ownerType)));
}
@@ -33,7 +33,7 @@ object ProtectedSyntheticExtensionCallChecker : SimpleCallChecker {
val sourceFunction = when (descriptor) {
is SyntheticJavaPropertyDescriptor -> descriptor.getMethod
is SamAdapterExtensionFunctionDescriptor -> descriptor.sourceFunction
is SamAdapterExtensionFunctionDescriptor -> descriptor.baseDescriptorForSynthetic
else -> return
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -20,6 +20,7 @@ import com.intellij.util.SmartList
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils
import org.jetbrains.kotlin.name.Name
@@ -33,8 +34,8 @@ import org.jetbrains.kotlin.types.*
import java.util.*
import kotlin.properties.Delegates
interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor {
val sourceFunction: FunctionDescriptor
interface SamAdapterExtensionFunctionDescriptor : FunctionDescriptor, SyntheticMemberDescriptor<FunctionDescriptor> {
override val baseDescriptorForSynthetic: FunctionDescriptor
}
class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope {
@@ -92,7 +93,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
source: SourceElement
) : SamAdapterExtensionFunctionDescriptor, SimpleFunctionDescriptorImpl(containingDeclaration, original, annotations, name, kind, source) {
override var sourceFunction: FunctionDescriptor by Delegates.notNull()
override var baseDescriptorForSynthetic: FunctionDescriptor by Delegates.notNull()
private set
private var toSourceFunctionTypeParameters: Map<TypeParameterDescriptor, TypeParameterDescriptor>? = null
@@ -105,7 +106,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
sourceFunction.name,
CallableMemberDescriptor.Kind.SYNTHESIZED,
sourceFunction.original.source)
descriptor.sourceFunction = sourceFunction
descriptor.baseDescriptorForSynthetic = sourceFunction
val sourceTypeParams = (sourceFunction.typeParameters).toMutableList()
val ownerClass = sourceFunction.containingDeclaration as ClassDescriptor
@@ -138,8 +139,8 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
}
}
override fun hasStableParameterNames() = sourceFunction.hasStableParameterNames()
override fun hasSynthesizedParameterNames() = sourceFunction.hasSynthesizedParameterNames()
override fun hasStableParameterNames() = baseDescriptorForSynthetic.hasStableParameterNames()
override fun hasSynthesizedParameterNames() = baseDescriptorForSynthetic.hasSynthesizedParameterNames()
override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor,
@@ -152,7 +153,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
return MyFunctionDescriptor(
containingDeclaration, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, source
).apply {
sourceFunction = this@MyFunctionDescriptor.sourceFunction
baseDescriptorForSynthetic = this@MyFunctionDescriptor.baseDescriptorForSynthetic
}
}
@@ -176,7 +177,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : SyntheticScope
TypeConstructorSubstitution.createByConstructorsMap(
substitutionMap, configuration.substitution.approximateCapturedTypes()).buildSubstitutor()
descriptor.sourceFunction = original.sourceFunction.substitute(sourceFunctionSubstitutor)
descriptor.baseDescriptorForSynthetic = original.baseDescriptorForSynthetic.substitute(sourceFunctionSubstitutor)
return descriptor
}