Convert ResolutionTaskHolder to kotlin
This commit is contained in:
+48
-63
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,94 +14,79 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls.tasks;
|
package org.jetbrains.jet.lang.resolve.calls.tasks
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext
|
||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
public class ResolutionTaskHolder<D : CallableDescriptor, F : D>(
|
||||||
import java.util.List;
|
private val basicCallResolutionContext: BasicCallResolutionContext,
|
||||||
|
private val priorityProvider: ResolutionTaskHolder.PriorityProvider<ResolutionCandidate<D>>,
|
||||||
|
private val tracing: TracingStrategy
|
||||||
|
) {
|
||||||
|
private val isSafeCall: Boolean
|
||||||
|
|
||||||
public class ResolutionTaskHolder<D extends CallableDescriptor, F extends D> {
|
private val candidatesList = Lists.newArrayList<Collection<ResolutionCandidate<D>>>()
|
||||||
private final BasicCallResolutionContext basicCallResolutionContext;
|
|
||||||
private final PriorityProvider<ResolutionCandidate<D>> priorityProvider;
|
|
||||||
private final TracingStrategy tracing;
|
|
||||||
private final boolean isSafeCall;
|
|
||||||
|
|
||||||
private final Collection<Collection<ResolutionCandidate<D>>> candidatesList = Lists.newArrayList();
|
private var internalTasks: MutableList<ResolutionTask<D, F>>? = null
|
||||||
|
|
||||||
private List<ResolutionTask<D, F>> tasks = null;
|
{
|
||||||
|
this.isSafeCall = JetPsiUtil.isSafeCall(basicCallResolutionContext.call)
|
||||||
public ResolutionTaskHolder(
|
|
||||||
@NotNull BasicCallResolutionContext basicCallResolutionContext,
|
|
||||||
@NotNull PriorityProvider<ResolutionCandidate<D>> priorityProvider,
|
|
||||||
@NotNull TracingStrategy tracing
|
|
||||||
) {
|
|
||||||
this.basicCallResolutionContext = basicCallResolutionContext;
|
|
||||||
this.priorityProvider = priorityProvider;
|
|
||||||
this.tracing = tracing;
|
|
||||||
this.isSafeCall = JetPsiUtil.isSafeCall(basicCallResolutionContext.call);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ResolutionCandidate<D>> setIsSafeCall(@NotNull Collection<ResolutionCandidate<D>> candidates) {
|
public fun setIsSafeCall(candidates: Collection<ResolutionCandidate<D>>): Collection<ResolutionCandidate<D>> {
|
||||||
for (ResolutionCandidate<D> candidate : candidates) {
|
for (candidate in candidates) {
|
||||||
candidate.setSafeCall(isSafeCall);
|
candidate.setSafeCall(isSafeCall)
|
||||||
}
|
}
|
||||||
return candidates;
|
return candidates
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCandidates(@NotNull Collection<ResolutionCandidate<D>> candidates) {
|
public fun addCandidates(candidates: Collection<ResolutionCandidate<D>>) {
|
||||||
assertNotFinished();
|
assertNotFinished()
|
||||||
if (!candidates.isEmpty()) {
|
if (!candidates.isEmpty()) {
|
||||||
candidatesList.add(setIsSafeCall(candidates));
|
candidatesList.add(setIsSafeCall(candidates))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCandidates(@NotNull List<Collection<ResolutionCandidate<D>>> candidatesList) {
|
public fun addCandidates(candidatesList: List<Collection<ResolutionCandidate<D>>>) {
|
||||||
assertNotFinished();
|
assertNotFinished()
|
||||||
for (Collection<ResolutionCandidate<D>> candidates : candidatesList) {
|
for (candidates in candidatesList) {
|
||||||
addCandidates(candidates);
|
addCandidates(candidates)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNotFinished() {
|
private fun assertNotFinished() {
|
||||||
assert tasks == null : "Can't add candidates after the resulting tasks were computed.";
|
assert(internalTasks == null, "Can't add candidates after the resulting tasks were computed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResolutionTask<D, F>> getTasks() {
|
public fun getTasks(): List<ResolutionTask<D, F>> {
|
||||||
if (tasks == null) {
|
if (internalTasks == null) {
|
||||||
tasks = Lists.newArrayList();
|
internalTasks = Lists.newArrayList()
|
||||||
|
|
||||||
for (int priority = priorityProvider.getMaxPriority(); priority >= 0; priority--) {
|
run {
|
||||||
final int finalPriority = priority;
|
var priority = priorityProvider.getMaxPriority()
|
||||||
for (Collection<ResolutionCandidate<D>> candidates : candidatesList) {
|
while (priority >= 0) {
|
||||||
Collection<ResolutionCandidate<D>> filteredCandidates = Collections2.filter(
|
for (candidates in candidatesList) {
|
||||||
candidates, new Predicate<ResolutionCandidate<D>>() {
|
val filteredCandidates = candidates.filter { priority == priorityProvider.getPriority(it) }
|
||||||
@Override
|
if (!filteredCandidates.isEmpty()) {
|
||||||
public boolean apply(@Nullable ResolutionCandidate<D> input) {
|
internalTasks!!.add(ResolutionTask(filteredCandidates, basicCallResolutionContext, tracing))
|
||||||
return finalPriority == priorityProvider.getPriority(input);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (!filteredCandidates.isEmpty()) {
|
|
||||||
tasks.add(new ResolutionTask<D, F>(filteredCandidates, basicCallResolutionContext, tracing));
|
|
||||||
}
|
}
|
||||||
|
priority--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tasks;
|
return internalTasks!!
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface PriorityProvider<D> {
|
public trait PriorityProvider<D> {
|
||||||
int getPriority(D candidate);
|
public fun getPriority(candidate: D): Int
|
||||||
|
|
||||||
int getMaxPriority();
|
public fun getMaxPriority(): Int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user