org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil Maven / Gradle / Ivy
/*
* Copyright 2010-2015 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.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.types.KotlinType;
import java.util.Collection;
public class OverloadResolutionResultsUtil {
@NotNull
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 ContextDependency contextDependency
) {
ResolvedCall resultingCall = getResultingCall(results, contextDependency);
return resultingCall != null ? resultingCall.getResultingDescriptor().getReturnType() : null;
}
@Nullable
public static ResolvedCall getResultingCall(
@NotNull OverloadResolutionResults results,
@NotNull ContextDependency contextDependency
) {
if (results.isSingleResult() && contextDependency == ContextDependency.INDEPENDENT) {
ResolvedCall resultingCall = results.getResultingCall();
if (!((MutableResolvedCall)resultingCall).hasInferredReturnType()) {
return null;
}
}
return results.isSingleResult() ? results.getResultingCall() : null;
}
}