Add location parameter to JetScope::getFunctions

This commit is contained in:
Zalim Bashorov
2015-07-14 22:05:46 +03:00
parent f79155df97
commit 0f92036353
37 changed files with 56 additions and 44 deletions
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilPackage;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
@@ -59,7 +60,7 @@ public class CodegenUtil {
@NotNull ClassifierDescriptor returnedClassifier,
@NotNull ClassifierDescriptor... valueParameterClassifiers
) {
Collection<FunctionDescriptor> functions = owner.getDefaultType().getMemberScope().getFunctions(name);
Collection<FunctionDescriptor> functions = owner.getDefaultType().getMemberScope().getFunctions(name, Location.NOWHERE);
for (FunctionDescriptor function : functions) {
if (!CallResolverUtilPackage.isOrOverridesSynthesized(function)
&& function.getTypeParameters().isEmpty()
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
import org.jetbrains.kotlin.psi.JetElement;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import org.jetbrains.kotlin.utils.UtilsPackage;
@@ -452,6 +453,6 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
ClassDescriptor elementClass = elementDescriptor.getExtensionReceiverParameter() == null
? getBuiltIns(elementDescriptor).getFunction(arity)
: getBuiltIns(elementDescriptor).getExtensionFunction(arity);
return elementClass.getDefaultType().getMemberScope().getFunctions(OperatorConventions.INVOKE).iterator().next();
return elementClass.getDefaultType().getMemberScope().getFunctions(OperatorConventions.INVOKE, Location.NOWHERE).iterator().next();
}
}
@@ -62,6 +62,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
@@ -401,7 +402,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
private boolean isGenericToArrayPresent() {
Collection<FunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("toArray"));
Collection<FunctionDescriptor> functions =
descriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("toArray"), Location.NOWHERE);
for (FunctionDescriptor function : functions) {
if (CallResolverUtilPackage.isOrOverridesSynthesized(function)) {
continue;
@@ -815,7 +817,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
Type type = typeMapper.mapType(getBuiltIns(descriptor).getArrayType(INVARIANT, descriptor.getDefaultType()));
FunctionDescriptor valuesFunction =
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES), new Function1<FunctionDescriptor, Boolean>() {
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUES, Location.NOWHERE), new Function1<FunctionDescriptor, Boolean>() {
@Override
public Boolean invoke(FunctionDescriptor descriptor) {
return CodegenUtil.isEnumValuesMethod(descriptor);
@@ -835,7 +837,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void generateEnumValueOfMethod() {
FunctionDescriptor valueOfFunction =
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUE_OF), new Function1<FunctionDescriptor, Boolean>() {
KotlinPackage.single(descriptor.getStaticScope().getFunctions(ENUM_VALUE_OF, Location.NOWHERE), new Function1<FunctionDescriptor, Boolean>() {
@Override
public Boolean invoke(FunctionDescriptor descriptor) {
return CodegenUtil.isEnumValueOfMethod(descriptor);
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
@@ -148,7 +149,7 @@ public class SamWrapperCodegen {
(ClassDescriptor) erasedInterfaceFunction.getContainingDeclaration(), OwnerKind.IMPLEMENTATION, state), cv, state, parentCodegen);
FunctionDescriptor invokeFunction =
functionJetType.getMemberScope().getFunctions(OperatorConventions.INVOKE).iterator().next().getOriginal();
functionJetType.getMemberScope().getFunctions(OperatorConventions.INVOKE, Location.NOWHERE).iterator().next().getOriginal();
StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false, StackValue.none());
codegen.genDelegate(erasedInterfaceFunction, invokeFunction, functionField);
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmSignaturePackage;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.KotlinToJvmSignatureMapper;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.types.*;
import java.util.*;
@@ -302,7 +303,7 @@ public class SignaturesPropagationData {
Name name = method.getName();
JvmMethodSignature autoSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(autoMethodDescriptor);
for (JetType supertype : containingClass.getTypeConstructor().getSupertypes()) {
Collection<FunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getFunctions(name);
Collection<FunctionDescriptor> superFunctionCandidates = supertype.getMemberScope().getFunctions(name, Location.NOWHERE);
for (FunctionDescriptor candidate : superFunctionCandidates) {
JvmMethodSignature candidateSignature = SIGNATURE_MAPPER.mapToJvmMethodSignature(candidate);
if (JvmSignaturePackage.erasedSignaturesEqualIgnoringReturnTypes(autoSignature, candidateSignature)) {
@@ -50,7 +50,7 @@ class AllUnderImportsScope : JetScope {
return scopes.flatMap { it.getProperties(name) }
}
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
return scopes.flatMap { it.getFunctions(name) }
}
@@ -734,7 +734,7 @@ public class OverrideResolver {
) {
for (JetType supertype : declaringClass.getTypeConstructor().getSupertypes()) {
Set<CallableMemberDescriptor> all = Sets.newLinkedHashSet();
all.addAll(supertype.getMemberScope().getFunctions(declared.getName()));
all.addAll(supertype.getMemberScope().getFunctions(declared.getName(), Location.NOWHERE));
//noinspection unchecked
all.addAll((Collection) supertype.getMemberScope().getProperties(declared.getName(), Location.NOWHERE));
for (CallableMemberDescriptor fromSuper : all) {
@@ -234,7 +234,7 @@ public class QualifiedExpressionResolver {
}
if (lookupMode == LookupMode.EVERYTHING) {
descriptors.addAll(outerScope.getFunctions(referencedName));
descriptors.addAll(outerScope.getFunctions(referencedName, Location.NOWHERE));
descriptors.addAll(outerScope.getProperties(referencedName, Location.NOWHERE));
VariableDescriptor localVariable = outerScope.getLocalVariable(referencedName);
@@ -33,7 +33,7 @@ class SingleImportScope(private val aliasName: Name, private val descriptors: Co
override fun getProperties(name: Name, location: Location)
= if (name == aliasName) descriptors.filterIsInstance<VariableDescriptor>() else emptyList()
override fun getFunctions(name: Name)
override fun getFunctions(name: Name, location: Location)
= if (name == aliasName) descriptors.filterIsInstance<FunctionDescriptor>() else emptyList()
override fun getContainingDeclaration(): DeclarationDescriptor = throw UnsupportedOperationException()
@@ -49,7 +49,7 @@ object DynamicCallableDescriptors {
p.println(javaClass.getSimpleName(), ": dynamic candidates for " + call)
}
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
if (isAugmentedAssignmentConvention(name)) return listOf()
if (call.getCallType() == Call.CallType.INVOKE
&& call.getValueArgumentList() == null && call.getFunctionLiteralArguments().isEmpty()) {
@@ -134,7 +134,7 @@ public class LazyDeclarationResolver {
@Override
public DeclarationDescriptor visitNamedFunction(@NotNull JetNamedFunction function, Void data) {
JetScope scopeForDeclaration = resolutionScopeToResolveDeclaration(function);
scopeForDeclaration.getFunctions(function.getNameAsSafeName());
scopeForDeclaration.getFunctions(function.getNameAsSafeName(), Location.NOWHERE);
return getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
}
@@ -253,7 +253,7 @@ class LazyImportScope(
override fun getLocalVariable(name: Name) = null
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
if (filteringKind == FilteringKind.INVISIBLE_CLASSES) return listOf()
return importResolver.collectFromImports(name, LookupMode.EVERYTHING) { scope, name -> scope.getFunctions(name) }
}
@@ -64,7 +64,7 @@ protected constructor(
override fun getClassifier(name: Name): ClassDescriptor? = classDescriptors(name).firstOrNull()
override fun getFunctions(name: Name): Collection<FunctionDescriptor> = functionDescriptors(name)
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> = functionDescriptors(name)
private fun doGetFunctions(name: Name): Collection<FunctionDescriptor> {
val result = Sets.newLinkedHashSet<FunctionDescriptor>()
@@ -115,7 +115,7 @@ public open class LazyClassMemberScope(
OverrideResolver.resolveUnknownVisibilities(result, trace)
}
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
// TODO: this should be handled by lazy function descriptors
val functions = super.getFunctions(name)
resolveUnknownVisibilitiesForMembers(functions)
@@ -156,7 +156,7 @@ public class WritableScopeImpl @jvmOverloads constructor(
functionsByName!![name] = functionsByName!![name] + descriptorIndex
}
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
checkMayRead()
return concatInOrder(functionsByName(name), workerScope.getFunctions(name))
@@ -270,7 +270,7 @@ public class WritableScopeImpl @jvmOverloads constructor(
return workerScope.getLocalVariable(name)
}
override fun getFunctions(name: Name): Collection<FunctionDescriptor> {
override fun getFunctions(name: Name, location: Location): Collection<FunctionDescriptor> {
checkMayRead()
return concatInOrder(functionsByName(name, descriptorLimit), workerScope.getFunctions(name))
@@ -153,7 +153,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
Name functionName = Name.identifier(name);
JetScope memberScope = packageView.getMemberScope();
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName);
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName, Location.NOWHERE);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName();
return functions.iterator().next();
}
@@ -162,7 +162,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFix
private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name functionName = Name.identifier(name);
JetScope memberScope = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList());
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName);
Collection<FunctionDescriptor> functions = memberScope.getFunctions(functionName, Location.NOWHERE);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName();
return functions.iterator().next();
}
@@ -418,7 +418,7 @@ public class DescriptorValidator {
public Void visitFunctionDescriptor(
FunctionDescriptor descriptor, JetScope scope
) {
assertFound(scope, descriptor, scope.getFunctions(descriptor.getName()));
assertFound(scope, descriptor, scope.getFunctions(descriptor.getName(), Location.NOWHERE));
return null;
}
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
import org.jetbrains.kotlin.resolve.scopes.Location;
import org.jetbrains.kotlin.test.ConfigurationKind;
import java.util.Collection;
@@ -72,7 +73,8 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
private void doTest(String text, String expected) {
JetFile jetFile = JetPsiFactory(getProject()).createFile("fun.kt", text);
ModuleDescriptor module = LazyResolveTestUtil.resolveLazily(Collections.singletonList(jetFile), getEnvironment());
Collection<FunctionDescriptor> functions = module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"));
Collection<FunctionDescriptor> functions =
module.getPackage(FqName.ROOT).getMemberScope().getFunctions(Name.identifier("f"), Location.NOWHERE);
assert functions.size() == 1 : "Many functions defined";
FunctionDescriptor function = ContainerUtil.getFirstItem(functions);