Removed several hacks from ScopeUtils.kt

This commit is contained in:
Stanislav Erokhin
2015-10-31 09:06:43 +03:00
parent 711daa459a
commit cc56cf6292
3 changed files with 14 additions and 45 deletions
@@ -16,9 +16,6 @@
package org.jetbrains.kotlin.resolve.scopes;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
@@ -29,30 +26,13 @@ import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.TraceBasedRedeclarationHandler;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.utils.Printer;
import java.util.Collection;
import java.util.List;
public final class JetScopeUtils {
private JetScopeUtils() {}
@NotNull
public static List<ReceiverValue> getImplicitReceiversHierarchyValues(@NotNull KtScope scope) {
Collection<ReceiverParameterDescriptor> hierarchy = scope.getImplicitReceiversHierarchy();
return Lists.newArrayList(
Collections2.transform(hierarchy,
new Function<ReceiverParameterDescriptor, ReceiverValue>() {
@Override
public ReceiverValue apply(ReceiverParameterDescriptor receiverParameterDescriptor) {
return receiverParameterDescriptor.getValue();
}
})
);
}
public static LexicalScope makeScopeForPropertyAccessor(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull LexicalScope parentScope,
@@ -35,29 +35,12 @@ public val LexicalScope.parents: Sequence<LexicalScope>
/**
* Adds receivers to the list in order of locality, so that the closest (the most local) receiver goes first
*/
public fun LexicalScope.getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
// todo remove hack
var jetScopeRefactoringHack: KtScope? = null
val receivers = collectFromMeAndParent {
if (it is MemberScopeToImportingScopeAdapter) {
jetScopeRefactoringHack = it.memberScope
}
it.implicitReceiver
}
return if (jetScopeRefactoringHack != null) {
receivers + jetScopeRefactoringHack!!.getImplicitReceiversHierarchy()
}
else {
receivers
}
public fun LexicalScope.getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = collectFromMeAndParent {
it.implicitReceiver
}
public fun LexicalScope.getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = collectAllFromMeAndParent {
if(it is MemberScopeToImportingScopeAdapter) { // todo remove this hack
it.memberScope.getDeclarationsByLabel(labelName)
}
else if (it.isOwnerDescriptorAccessibleByLabel && it.ownerDescriptor.name == labelName) {
if (it.isOwnerDescriptorAccessibleByLabel && it.ownerDescriptor.name == labelName) {
listOf(it.ownerDescriptor)
}
else {
@@ -136,16 +119,16 @@ private class MemberScopeToImportingScopeAdapter(override val parent: ImportingS
override fun getContributedPackage(name: Name): PackageViewDescriptor? = memberScope.getPackage(name)
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= memberScope.getSyntheticExtensionProperties(receiverTypes, name, location)
= emptyList<PropertyDescriptor>()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>, name: Name, location: LookupLocation)
= memberScope.getSyntheticExtensionFunctions(receiverTypes, name, location)
= emptyList<FunctionDescriptor>()
override fun getContributedSyntheticExtensionProperties(receiverTypes: Collection<KotlinType>)
= memberScope.getSyntheticExtensionProperties(receiverTypes)
= emptyList<PropertyDescriptor>()
override fun getContributedSyntheticExtensionFunctions(receiverTypes: Collection<KotlinType>)
= memberScope.getSyntheticExtensionFunctions(receiverTypes)
= emptyList<FunctionDescriptor>()
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
= memberScope.getDescriptors(kindFilter, nameFilter)
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform;
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
import org.jetbrains.kotlin.resolve.scopes.ImportingScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
import org.jetbrains.kotlin.test.KotlinTestUtils;
@@ -136,8 +138,12 @@ public class ExpectedResolveDataUtil {
emptyModule.setDependencies(emptyModule);
emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE$);
LexicalScopeImpl lexicalScope = new LexicalScopeImpl(ImportingScope.Empty.INSTANCE, classDescriptor, false,
classDescriptor.getThisAsReceiverParameter(),
"Scope with implicit this for class: " + classDescriptor);
ExpressionTypingContext context = ExpressionTypingContext.newContext(
new BindingTraceContext(), ScopeUtilsKt.memberScopeAsImportingScope(classDescriptor.getDefaultType().getMemberScope()),
new BindingTraceContext(), lexicalScope,
DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE);
OverloadResolutionResults<FunctionDescriptor> functions = container.getFakeCallResolver().resolveFakeCall(