Use JvmWildcard on return type of getContributedVariables/getContributedFunctions

This commit is contained in:
Alexander Udalov
2018-07-07 12:38:48 +02:00
parent 9dc53c38f3
commit 23c210e9f2
15 changed files with 53 additions and 63 deletions
@@ -349,7 +349,7 @@ public abstract class AnnotationCodegen {
private String getAnnotationArgumentJvmName(@Nullable ClassDescriptor annotationClass, @NotNull Name parameterName) { private String getAnnotationArgumentJvmName(@Nullable ClassDescriptor annotationClass, @NotNull Name parameterName) {
if (annotationClass == null) return parameterName.asString(); if (annotationClass == null) return parameterName.asString();
Collection<PropertyDescriptor> variables = Collection<? extends PropertyDescriptor> variables =
annotationClass.getUnsubstitutedMemberScope().getContributedVariables(parameterName, NoLookupLocation.FROM_BACKEND); annotationClass.getUnsubstitutedMemberScope().getContributedVariables(parameterName, NoLookupLocation.FROM_BACKEND);
if (variables.size() != 1) return parameterName.asString(); if (variables.size() != 1) return parameterName.asString();
@@ -467,7 +467,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
return; return;
} }
Collection<SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions( Collection<? extends SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions(
Name.identifier("toArray"), NoLookupLocation.FROM_BACKEND Name.identifier("toArray"), NoLookupLocation.FROM_BACKEND
); );
boolean hasGenericToArray = false; boolean hasGenericToArray = false;
@@ -203,7 +203,7 @@ public class SignaturesPropagationData {
Method autoSignature = null; Method autoSignature = null;
boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor); boolean autoMethodContainsVararg = SignaturePropagationUtilKt.containsVarargs(autoMethodDescriptor);
for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) { for (KotlinType supertype : containingClass.getTypeConstructor().getSupertypes()) {
Collection<SimpleFunctionDescriptor> superFunctionCandidates = Collection<? extends SimpleFunctionDescriptor> superFunctionCandidates =
supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS); supertype.getMemberScope().getContributedFunctions(name, NoLookupLocation.WHEN_GET_SUPER_MEMBERS);
if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates)) continue; if (!autoMethodContainsVararg && !SignaturePropagationUtilKt.containsAnyNotTrivialSignature(superFunctionCandidates)) continue;
@@ -1187,8 +1187,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
KotlinType refinedType = KotlinBuiltIns.isNothingOrNullableNothing(receiver.getType()) ? KotlinType refinedType = KotlinBuiltIns.isNothingOrNullableNothing(receiver.getType()) ?
components.builtIns.getNullableAnyType() : components.builtIns.getNullableAnyType() :
receiver.getType(); receiver.getType();
Collection<SimpleFunctionDescriptor> equalsMembers = refinedType.getMemberScope().getContributedFunctions( Collection<? extends SimpleFunctionDescriptor> equalsMembers = refinedType.getMemberScope().getContributedFunctions(
OperatorNameConventions.EQUALS, new KotlinLookupLocation(expression.getOperationReference())); OperatorNameConventions.EQUALS, new KotlinLookupLocation(expression.getOperationReference())
);
return CollectionsKt.filter(equalsMembers, descriptor -> { return CollectionsKt.filter(equalsMembers, descriptor -> {
if (ErrorUtils.isError(descriptor)) return true; if (ErrorUtils.isError(descriptor)) return true;
@@ -99,8 +99,9 @@ public class DataFlowAnalyzer {
} }
private boolean typeHasOverriddenEquals(@NotNull KotlinType type, @NotNull KtElement lookupElement) { private boolean typeHasOverriddenEquals(@NotNull KotlinType type, @NotNull KtElement lookupElement) {
Collection<SimpleFunctionDescriptor> members = type.getMemberScope().getContributedFunctions( Collection<? extends SimpleFunctionDescriptor> members = type.getMemberScope().getContributedFunctions(
OperatorNameConventions.EQUALS, new KotlinLookupLocation(lookupElement)); OperatorNameConventions.EQUALS, new KotlinLookupLocation(lookupElement)
);
for (FunctionDescriptor member : members) { for (FunctionDescriptor member : members) {
KotlinType returnType = member.getReturnType(); KotlinType returnType = member.getReturnType();
if (returnType == null || !KotlinBuiltIns.isBoolean(returnType)) continue; if (returnType == null || !KotlinBuiltIns.isBoolean(returnType)) continue;
@@ -169,7 +169,8 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) { protected static FunctionDescriptor getFunctionDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name) {
Name functionName = Name.identifier(name); Name functionName = Name.identifier(name);
MemberScope memberScope = packageView.getMemberScope(); MemberScope memberScope = packageView.getMemberScope();
Collection<SimpleFunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST); Collection<? extends SimpleFunctionDescriptor> functions =
memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName(); assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + packageView.getName();
return functions.iterator().next(); return functions.iterator().next();
} }
@@ -178,7 +179,8 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) { private static FunctionDescriptor getFunctionDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name functionName = Name.identifier(name); Name functionName = Name.identifier(name);
MemberScope memberScope = classDescriptor.getMemberScope(Collections.emptyList()); MemberScope memberScope = classDescriptor.getMemberScope(Collections.emptyList());
Collection<SimpleFunctionDescriptor> functions = memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST); Collection<? extends SimpleFunctionDescriptor> functions =
memberScope.getContributedFunctions(functionName, NoLookupLocation.FROM_TEST);
assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName(); assert functions.size() == 1 : "Failed to find function " + functionName + " in class" + "." + classDescriptor.getName();
return functions.iterator().next(); return functions.iterator().next();
} }
@@ -187,12 +189,13 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) { protected static PropertyDescriptor getPropertyDescriptor(@NotNull PackageFragmentDescriptor packageView, @NotNull String name, boolean failOnMissing) {
Name propertyName = Name.identifier(name); Name propertyName = Name.identifier(name);
MemberScope memberScope = packageView.getMemberScope(); MemberScope memberScope = packageView.getMemberScope();
Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST); Collection<? extends PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
if (properties.isEmpty()) { if (properties.isEmpty()) {
for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(memberScope)) { for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(memberScope)) {
if (descriptor instanceof ClassDescriptor) { if (descriptor instanceof ClassDescriptor) {
Collection<PropertyDescriptor> classProperties = ((ClassDescriptor) descriptor).getMemberScope(Collections.emptyList()) Collection<? extends PropertyDescriptor> classProperties =
.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST); ((ClassDescriptor) descriptor).getMemberScope(Collections.emptyList())
.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
if (!classProperties.isEmpty()) { if (!classProperties.isEmpty()) {
properties = classProperties; properties = classProperties;
break; break;
@@ -213,7 +216,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) { private static PropertyDescriptor getPropertyDescriptor(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
Name propertyName = Name.identifier(name); Name propertyName = Name.identifier(name);
MemberScope memberScope = classDescriptor.getMemberScope(Collections.emptyList()); MemberScope memberScope = classDescriptor.getMemberScope(Collections.emptyList());
Collection<PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST); Collection<? extends PropertyDescriptor> properties = memberScope.getContributedVariables(propertyName, NoLookupLocation.FROM_TEST);
assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName(); assert properties.size() == 1 : "Failed to find property " + propertyName + " in class " + classDescriptor.getName();
return properties.iterator().next(); return properties.iterator().next();
} }
@@ -72,7 +72,7 @@ public class BoundsSubstitutorTest extends KotlinTestWithEnvironment {
private void doTest(String text, String expected) { private void doTest(String text, String expected) {
KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text); KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile("fun.kt", text);
ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor(); ModuleDescriptor module = JvmResolveUtil.analyze(ktFile, getEnvironment()).getModuleDescriptor();
Collection<SimpleFunctionDescriptor> functions = Collection<? extends SimpleFunctionDescriptor> functions =
module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST); module.getPackage(FqName.ROOT).getMemberScope().getContributedFunctions(Name.identifier("f"), NoLookupLocation.FROM_TEST);
FunctionDescriptor substituted = BoundsSubstitutor.substituteBounds(CollectionsKt.single(functions)); FunctionDescriptor substituted = BoundsSubstitutor.substituteBounds(CollectionsKt.single(functions));
String actual = DescriptorRenderer.COMPACT.render(substituted); String actual = DescriptorRenderer.COMPACT.render(substituted);
@@ -182,21 +182,21 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
} }
private class EnumEntryScope extends MemberScopeImpl { private class EnumEntryScope extends MemberScopeImpl {
private final MemoizedFunctionToNotNull<Name, Collection<SimpleFunctionDescriptor>> functions; private final MemoizedFunctionToNotNull<Name, Collection<? extends SimpleFunctionDescriptor>> functions;
private final MemoizedFunctionToNotNull<Name, Collection<PropertyDescriptor>> properties; private final MemoizedFunctionToNotNull<Name, Collection<? extends PropertyDescriptor>> properties;
private final NotNullLazyValue<Collection<DeclarationDescriptor>> allDescriptors; private final NotNullLazyValue<Collection<DeclarationDescriptor>> allDescriptors;
public EnumEntryScope(@NotNull StorageManager storageManager) { public EnumEntryScope(@NotNull StorageManager storageManager) {
this.functions = storageManager.createMemoizedFunction(new Function1<Name, Collection<SimpleFunctionDescriptor>>() { this.functions = storageManager.createMemoizedFunction(new Function1<Name, Collection<? extends SimpleFunctionDescriptor>>() {
@Override @Override
public Collection<SimpleFunctionDescriptor> invoke(Name name) { public Collection<? extends SimpleFunctionDescriptor> invoke(Name name) {
return computeFunctions(name); return computeFunctions(name);
} }
}); });
this.properties = storageManager.createMemoizedFunction(new Function1<Name, Collection<PropertyDescriptor>>() { this.properties = storageManager.createMemoizedFunction(new Function1<Name, Collection<? extends PropertyDescriptor>>() {
@Override @Override
public Collection<PropertyDescriptor> invoke(Name name) { public Collection<? extends PropertyDescriptor> invoke(Name name) {
return computeProperties(name); return computeProperties(name);
} }
}); });
@@ -210,32 +210,23 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
@NotNull @NotNull
@Override @Override
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations public Collection<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
// 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); return properties.invoke(name);
} }
@NotNull @NotNull
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations private Collection<? extends PropertyDescriptor> computeProperties(@NotNull Name name) {
// method is covariantly overridden in Kotlin, but collections in Java are invariant return resolveFakeOverrides(name, getSupertypeScope().getContributedVariables(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE));
@SuppressWarnings({"unchecked"})
private Collection<PropertyDescriptor> computeProperties(@NotNull Name name) {
return resolveFakeOverrides(name, (Collection) getSupertypeScope().getContributedVariables(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE));
} }
@NotNull @NotNull
@Override @Override
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations public Collection<? extends SimpleFunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
// 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); return functions.invoke(name);
} }
@NotNull @NotNull
private Collection<SimpleFunctionDescriptor> computeFunctions(@NotNull Name name) { private Collection<? extends SimpleFunctionDescriptor> computeFunctions(@NotNull Name name) {
return resolveFakeOverrides(name, getSupertypeScope().getContributedFunctions(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE)); return resolveFakeOverrides(name, getSupertypeScope().getContributedFunctions(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE));
} }
@@ -247,9 +238,9 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
} }
@NotNull @NotNull
private <D extends CallableMemberDescriptor> Collection<D> resolveFakeOverrides( private <D extends CallableMemberDescriptor> Collection<? extends D> resolveFakeOverrides(
@NotNull Name name, @NotNull Name name,
@NotNull Collection<D> fromSupertypes @NotNull Collection<? extends D> fromSupertypes
) { ) {
final Set<D> result = new LinkedHashSet<D>(); final Set<D> result = new LinkedHashSet<D>();
@@ -587,8 +587,7 @@ public class DescriptorUtils {
@Nullable @Nullable
public static FunctionDescriptor getFunctionByNameOrNull(@NotNull MemberScope scope, @NotNull Name name) { public static FunctionDescriptor getFunctionByNameOrNull(@NotNull MemberScope scope, @NotNull Name name) {
Collection<SimpleFunctionDescriptor> functions = scope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND); for (SimpleFunctionDescriptor d : scope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)) {
for (SimpleFunctionDescriptor d : functions) {
if (name.equals(d.getOriginal().getName())) { if (name.equals(d.getOriginal().getName())) {
return d; return d;
} }
@@ -599,8 +598,7 @@ public class DescriptorUtils {
@NotNull @NotNull
public static PropertyDescriptor getPropertyByName(@NotNull MemberScope scope, @NotNull Name name) { public static PropertyDescriptor getPropertyByName(@NotNull MemberScope scope, @NotNull Name name) {
Collection<PropertyDescriptor> properties = scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND); for (PropertyDescriptor d : scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND)) {
for (PropertyDescriptor d : properties) {
if (name.equals(d.getOriginal().getName())) { if (name.equals(d.getOriginal().getName())) {
return d; return d;
} }
@@ -25,8 +25,9 @@ import java.lang.reflect.Modifier
interface MemberScope : ResolutionScope { interface MemberScope : ResolutionScope {
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> override fun getContributedVariables(name: Name, location: LookupLocation): Collection<@JvmWildcard PropertyDescriptor>
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor>
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<@JvmWildcard SimpleFunctionDescriptor>
/** /**
* These methods may return a superset of an actual names' set * These methods may return a superset of an actual names' set
@@ -25,9 +25,11 @@ import org.jetbrains.kotlin.utils.alwaysTrue
abstract class MemberScopeImpl : MemberScope { abstract class MemberScopeImpl : MemberScope {
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = null
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> = emptyList() override fun getContributedVariables(name: Name, location: LookupLocation): Collection<@JvmWildcard PropertyDescriptor> =
emptyList()
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> = emptyList() override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<@JvmWildcard SimpleFunctionDescriptor> =
emptyList()
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, override fun getContributedDescriptors(kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = emptyList() nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = emptyList()
@@ -39,9 +39,9 @@ interface ResolutionScope {
fun getContributedClassifierIncludeDeprecated(name: Name, location: LookupLocation): DescriptorWithDeprecation<ClassifierDescriptor>? = fun getContributedClassifierIncludeDeprecated(name: Name, location: LookupLocation): DescriptorWithDeprecation<ClassifierDescriptor>? =
getContributedClassifier(name, location)?.let { DescriptorWithDeprecation.createNonDeprecated(it) } getContributedClassifier(name, location)?.let { DescriptorWithDeprecation.createNonDeprecated(it) }
fun getContributedVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> fun getContributedVariables(name: Name, location: LookupLocation): Collection<@JvmWildcard VariableDescriptor>
fun getContributedFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> fun getContributedFunctions(name: Name, location: LookupLocation): Collection<@JvmWildcard FunctionDescriptor>
/** /**
* All visible descriptors from current scope possibly filtered by the given name and kind filters * All visible descriptors from current scope possibly filtered by the given name and kind filters
@@ -198,19 +198,13 @@ public class ErrorUtils {
@NotNull @NotNull
@Override @Override
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations public Set<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
// 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; return ERROR_PROPERTY_GROUP;
} }
@NotNull @NotNull
@Override @Override
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations public Set<? extends SimpleFunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
// 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)); return Collections.singleton(createErrorFunction(this));
} }
@@ -284,17 +278,15 @@ public class ErrorUtils {
@NotNull @NotNull
@Override @Override
@SuppressWarnings({"unchecked"}) // KT-9898 Impossible implement kotlin interface from java public Collection<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
public Collection getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException(debugMessage+", required name: " + name); throw new IllegalStateException(debugMessage+", required name: " + name);
} }
@NotNull @NotNull
@Override @Override
// TODO: Convert to Kotlin or add @JvmWildcard to MemberScope declarations public Collection<? extends SimpleFunctionDescriptor> getContributedFunctions(
// method is covariantly overridden in Kotlin, but collections in Java are invariant @NotNull Name name, @NotNull LookupLocation location
@SuppressWarnings({"unchecked"}) ) {
public Collection getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException(debugMessage+", required name: " + name); throw new IllegalStateException(debugMessage+", required name: " + name);
} }
@@ -216,8 +216,9 @@ public final class Namer {
// TODO: get rid of this function // TODO: get rid of this function
@NotNull @NotNull
private static String getStableMangledNameForDescriptor(@NotNull ClassDescriptor descriptor, @NotNull String functionName) { private static String getStableMangledNameForDescriptor(@NotNull ClassDescriptor descriptor, @NotNull String functionName) {
Collection<SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions( Collection<? extends SimpleFunctionDescriptor> functions = descriptor.getDefaultType().getMemberScope().getContributedFunctions(
Name.identifier(functionName), NoLookupLocation.FROM_BACKEND); Name.identifier(functionName), NoLookupLocation.FROM_BACKEND
);
assert functions.size() == 1 : "Can't select a single function: " + functionName + " in " + descriptor; assert functions.size() == 1 : "Can't select a single function: " + functionName + " in " + descriptor;
SuggestedName suggested = new NameSuggestion().suggest(functions.iterator().next()); SuggestedName suggested = new NameSuggestion().suggest(functions.iterator().next());
assert suggested != null : "Suggested name for class members is always non-null: " + functions.iterator().next(); assert suggested != null : "Suggested name for class members is always non-null: " + functions.iterator().next();
@@ -152,7 +152,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
@Nullable @Nullable
private static VariableDescriptor getVariableByName(@NotNull LexicalScope scope, @NotNull Name name) { private static VariableDescriptor getVariableByName(@NotNull LexicalScope scope, @NotNull Name name) {
while (true) { while (true) {
Collection<VariableDescriptor> variables = scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND); Collection<? extends VariableDescriptor> variables = scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND);
if (!variables.isEmpty()) { if (!variables.isEmpty()) {
return variables.size() == 1 ? variables.iterator().next() : null; return variables.size() == 1 ? variables.iterator().next() : null;
} }