org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-compiler-embeddable Show documentation
Show all versions of kotlin-compiler-embeddable Show documentation
the Kotlin compiler embeddable
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.results;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.tower.*;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.resolve.calls.util.ResolvedCallUtilKt;
import java.util.Collection;
public class OverloadResolutionResultsUtil {
@NotNull
@SuppressWarnings("unchecked")
public static OverloadResolutionResults ambiguity(OverloadResolutionResults results1, OverloadResolutionResults results2) {
Collection> resultingCalls = Lists.newArrayList();
resultingCalls.addAll((Collection>) results1.getResultingCalls());
resultingCalls.addAll((Collection>) results2.getResultingCalls());
return OverloadResolutionResultsImpl.ambiguity(resultingCalls);
}
@Nullable
public static KotlinType getResultingType(
@NotNull OverloadResolutionResults results,
@NotNull ResolutionContext> context
) {
ResolvedCall resultingCall = getResultingCall(results, context);
return resultingCall != null ? resultingCall.getResultingDescriptor().getReturnType() : null;
}
@Nullable
public static ResolvedCall getResultingCall(
@NotNull OverloadResolutionResults results,
@NotNull ResolutionContext> context
) {
if (results.isSingleResult() && context.contextDependency == ContextDependency.INDEPENDENT) {
ResolvedCall resultingCall = results.getResultingCall();
NewAbstractResolvedCall> newResolvedCall;
if (resultingCall instanceof NewVariableAsFunctionResolvedCallImpl) {
newResolvedCall = ((NewVariableAsFunctionResolvedCallImpl) resultingCall).getFunctionCall();
}
else if (resultingCall instanceof NewAbstractResolvedCall>) {
newResolvedCall = (NewAbstractResolvedCall>) resultingCall;
} else {
newResolvedCall = null;
}
if (newResolvedCall != null) {
if (!ResolvedCallUtilKt.hasInferredReturnType(newResolvedCall)) {
return null;
}
} else if (!((MutableResolvedCall) resultingCall).hasInferredReturnType()) {
return null;
}
}
return results.isSingleResult() ? results.getResultingCall() : null;
}
}