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
@@ -182,21 +182,21 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
}
private class EnumEntryScope extends MemberScopeImpl {
private final MemoizedFunctionToNotNull<Name, Collection<SimpleFunctionDescriptor>> functions;
private final MemoizedFunctionToNotNull<Name, Collection<PropertyDescriptor>> properties;
private final MemoizedFunctionToNotNull<Name, Collection<? extends SimpleFunctionDescriptor>> functions;
private final MemoizedFunctionToNotNull<Name, Collection<? extends PropertyDescriptor>> properties;
private final NotNullLazyValue<Collection<DeclarationDescriptor>> allDescriptors;
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
public Collection<SimpleFunctionDescriptor> invoke(Name name) {
public Collection<? extends SimpleFunctionDescriptor> invoke(Name name) {
return computeFunctions(name);
}
});
this.properties = storageManager.createMemoizedFunction(new Function1<Name, Collection<PropertyDescriptor>>() {
this.properties = storageManager.createMemoizedFunction(new Function1<Name, Collection<? extends PropertyDescriptor>>() {
@Override
public Collection<PropertyDescriptor> invoke(Name name) {
public Collection<? extends PropertyDescriptor> invoke(Name name) {
return computeProperties(name);
}
});
@@ -210,32 +210,23 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
@NotNull
@Override
// 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) {
public Collection<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
return properties.invoke(name);
}
@NotNull
// 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));
private Collection<? extends PropertyDescriptor> computeProperties(@NotNull Name name) {
return resolveFakeOverrides(name, getSupertypeScope().getContributedVariables(name, NoLookupLocation.FOR_NON_TRACKED_SCOPE));
}
@NotNull
@Override
// 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) {
public Collection<? extends SimpleFunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
return functions.invoke(name);
}
@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));
}
@@ -247,9 +238,9 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
}
@NotNull
private <D extends CallableMemberDescriptor> Collection<D> resolveFakeOverrides(
private <D extends CallableMemberDescriptor> Collection<? extends D> resolveFakeOverrides(
@NotNull Name name,
@NotNull Collection<D> fromSupertypes
@NotNull Collection<? extends D> fromSupertypes
) {
final Set<D> result = new LinkedHashSet<D>();
@@ -587,8 +587,7 @@ public class DescriptorUtils {
@Nullable
public static FunctionDescriptor getFunctionByNameOrNull(@NotNull MemberScope scope, @NotNull Name name) {
Collection<SimpleFunctionDescriptor> functions = scope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND);
for (SimpleFunctionDescriptor d : functions) {
for (SimpleFunctionDescriptor d : scope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)) {
if (name.equals(d.getOriginal().getName())) {
return d;
}
@@ -599,8 +598,7 @@ public class DescriptorUtils {
@NotNull
public static PropertyDescriptor getPropertyByName(@NotNull MemberScope scope, @NotNull Name name) {
Collection<PropertyDescriptor> properties = scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND);
for (PropertyDescriptor d : properties) {
for (PropertyDescriptor d : scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND)) {
if (name.equals(d.getOriginal().getName())) {
return d;
}
@@ -25,8 +25,9 @@ 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>
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<@JvmWildcard PropertyDescriptor>
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<@JvmWildcard SimpleFunctionDescriptor>
/**
* 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 {
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,
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = emptyList()
@@ -39,9 +39,9 @@ interface ResolutionScope {
fun getContributedClassifierIncludeDeprecated(name: Name, location: LookupLocation): DescriptorWithDeprecation<ClassifierDescriptor>? =
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
@@ -198,19 +198,13 @@ public class ErrorUtils {
@NotNull
@Override
// 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) {
public Set<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
return ERROR_PROPERTY_GROUP;
}
@NotNull
@Override
// 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) {
public Set<? extends SimpleFunctionDescriptor> getContributedFunctions(@NotNull Name name, @NotNull LookupLocation location) {
return Collections.singleton(createErrorFunction(this));
}
@@ -284,17 +278,15 @@ public class ErrorUtils {
@NotNull
@Override
@SuppressWarnings({"unchecked"}) // KT-9898 Impossible implement kotlin interface from java
public Collection getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
public Collection<? extends PropertyDescriptor> getContributedVariables(@NotNull Name name, @NotNull LookupLocation location) {
throw new IllegalStateException(debugMessage+", required name: " + name);
}
@NotNull
@Override
// 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) {
public Collection<? extends SimpleFunctionDescriptor> getContributedFunctions(
@NotNull Name name, @NotNull LookupLocation location
) {
throw new IllegalStateException(debugMessage+", required name: " + name);
}