Use kotlin.Function1 instead of intellij Function in OverrideResolver
This commit is contained in:
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
@@ -44,6 +43,7 @@ import org.jetbrains.kotlin.resolve.calls.callResolverUtil.CallResolverUtilKt;
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsKt;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
import org.jetbrains.kotlin.utils.FunctionsKt;
|
||||
import org.jetbrains.kotlin.utils.HashSetUtil;
|
||||
|
||||
import java.util.*;
|
||||
@@ -130,7 +130,7 @@ public class OverrideResolver {
|
||||
@NotNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <D extends CallableDescriptor> Set<D> filterOutOverridden(@NotNull Set<D> candidateSet) {
|
||||
return filterOverrides(candidateSet, Function.ID);
|
||||
return filterOverrides(candidateSet, FunctionsKt.<CallableDescriptor>identity());
|
||||
}
|
||||
|
||||
// In a multi-module project different "copies" of the same class may be present in different libraries,
|
||||
@@ -142,12 +142,12 @@ public class OverrideResolver {
|
||||
@NotNull
|
||||
private static <D> Set<D> noDuplicates(
|
||||
@NotNull Set<D> candidateSet,
|
||||
@NotNull final Function<? super D, ? extends CallableDescriptor> transform
|
||||
@NotNull final Function1<? super D, ? extends CallableDescriptor> transform
|
||||
) {
|
||||
List<D> fromSourcesGoesFirst = sortedBy(candidateSet, new Function1<D, Integer>() {
|
||||
@Override
|
||||
public Integer invoke(D d) {
|
||||
return DescriptorToSourceUtils.descriptorToDeclaration(transform.fun(d)) != null ? 0 : 1;
|
||||
return DescriptorToSourceUtils.descriptorToDeclaration(transform.invoke(d)) != null ? 0 : 1;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -156,13 +156,13 @@ public class OverrideResolver {
|
||||
new EqualityPolicy<D>() {
|
||||
@Override
|
||||
public int getHashCode(D d) {
|
||||
return DescriptorUtils.getFqName(transform.fun(d).getContainingDeclaration()).hashCode();
|
||||
return DescriptorUtils.getFqName(transform.invoke(d).getContainingDeclaration()).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEqual(D d1, D d2) {
|
||||
CallableDescriptor f = transform.fun(d1).getOriginal();
|
||||
CallableDescriptor g = transform.fun(d2).getOriginal();
|
||||
CallableDescriptor f = transform.invoke(d1).getOriginal();
|
||||
CallableDescriptor g = transform.invoke(d2).getOriginal();
|
||||
|
||||
boolean ignoreReturnType = (DescriptorToSourceUtils.descriptorToDeclaration(f) == null) !=
|
||||
(DescriptorToSourceUtils.descriptorToDeclaration(g) == null);
|
||||
@@ -175,7 +175,7 @@ public class OverrideResolver {
|
||||
@NotNull
|
||||
public static <D> Set<D> filterOverrides(
|
||||
@NotNull Set<D> candidateSet,
|
||||
@NotNull Function<? super D, ? extends CallableDescriptor> transform
|
||||
@NotNull Function1<? super D, ? extends CallableDescriptor> transform
|
||||
) {
|
||||
if (candidateSet.size() <= 1) return candidateSet;
|
||||
|
||||
@@ -187,9 +187,9 @@ public class OverrideResolver {
|
||||
Set<D> candidates = Sets.newLinkedHashSet();
|
||||
outerLoop:
|
||||
for (D meD : noDuplicates) {
|
||||
CallableDescriptor me = transform.fun(meD);
|
||||
CallableDescriptor me = transform.invoke(meD);
|
||||
for (D otherD : noDuplicates) {
|
||||
CallableDescriptor other = transform.fun(otherD);
|
||||
CallableDescriptor other = transform.invoke(otherD);
|
||||
if (me != other && overrides(other, me)) {
|
||||
continue outerLoop;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.resolve.calls.model;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -47,13 +46,6 @@ import static org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.UNKNOW
|
||||
public class ResolvedCallImpl<D extends CallableDescriptor> implements MutableResolvedCall<D> {
|
||||
private static final Logger LOG = Logger.getInstance(ResolvedCallImpl.class);
|
||||
|
||||
public static final Function<MutableResolvedCall<?>, CallableDescriptor> MAP_TO_RESULT = new Function<MutableResolvedCall<?>, CallableDescriptor>() {
|
||||
@Override
|
||||
public CallableDescriptor fun(MutableResolvedCall<?> resolvedCall) {
|
||||
return resolvedCall.getResultingDescriptor();
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public static <D extends CallableDescriptor> ResolvedCallImpl<D> create(
|
||||
@NotNull ResolutionCandidate<D> candidate,
|
||||
|
||||
+10
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.results;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
@@ -32,10 +33,17 @@ import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl.MAP_TO_RESULT;
|
||||
import static org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus.*;
|
||||
|
||||
public class ResolutionResultsHandler {
|
||||
private static final Function1<MutableResolvedCall<?>, CallableDescriptor> MAP_RESOLVED_CALL_TO_RESULTING_DESCRIPTOR =
|
||||
new Function1<MutableResolvedCall<?>, CallableDescriptor>() {
|
||||
@Override
|
||||
public CallableDescriptor invoke(MutableResolvedCall<?> resolvedCall) {
|
||||
return resolvedCall.getResultingDescriptor();
|
||||
}
|
||||
};
|
||||
|
||||
private final OverloadingConflictResolver overloadingConflictResolver;
|
||||
|
||||
public ResolutionResultsHandler(@NotNull OverloadingConflictResolver overloadingConflictResolver) {
|
||||
@@ -193,7 +201,7 @@ public class ResolutionResultsHandler {
|
||||
candidates = overloadingConflictResolver.findMaximallySpecificVariableAsFunctionCalls(candidates);
|
||||
}
|
||||
|
||||
Set<MutableResolvedCall<D>> noOverrides = OverrideResolver.filterOverrides(candidates, MAP_TO_RESULT);
|
||||
Set<MutableResolvedCall<D>> noOverrides = OverrideResolver.filterOverrides(candidates, MAP_RESOLVED_CALL_TO_RESULTING_DESCRIPTOR);
|
||||
if (noOverrides.size() == 1) {
|
||||
return OverloadResolutionResultsImpl.success(noOverrides.iterator().next());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user