Remove dependency of "descriptors" on Function/Condition/Processor
This commit is contained in:
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
|
import kotlin.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||||
@@ -70,12 +70,11 @@ public interface Importer {
|
|||||||
@NotNull DeclarationDescriptor descriptor,
|
@NotNull DeclarationDescriptor descriptor,
|
||||||
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
|
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
|
||||||
) {
|
) {
|
||||||
final Collection<ClassDescriptor> kotlinAnalogsForClassesInside = platformToKotlinClassMap.mapPlatformClassesInside(
|
final Collection<ClassDescriptor> kotlinAnalogsForClassesInside = platformToKotlinClassMap.mapPlatformClassesInside(descriptor);
|
||||||
descriptor);
|
|
||||||
if (kotlinAnalogsForClassesInside.isEmpty()) return scope;
|
if (kotlinAnalogsForClassesInside.isEmpty()) return scope;
|
||||||
return new FilteringScope(scope, new Predicate<DeclarationDescriptor>() {
|
return new FilteringScope(scope, new Function1<DeclarationDescriptor, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(DeclarationDescriptor descriptor) {
|
public Boolean invoke(DeclarationDescriptor descriptor) {
|
||||||
for (ClassDescriptor kotlinAnalog : kotlinAnalogsForClassesInside) {
|
for (ClassDescriptor kotlinAnalog : kotlinAnalogsForClassesInside) {
|
||||||
if (kotlinAnalog.getName().equals(descriptor.getName())) {
|
if (kotlinAnalog.getName().equals(descriptor.getName())) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls;
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||||
|
import kotlin.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -31,9 +31,10 @@ import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.context.*;
|
import org.jetbrains.jet.lang.resolve.calls.context.*;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.inference.*;
|
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
|
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask;
|
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TaskPrioritizer;
|
import org.jetbrains.jet.lang.resolve.calls.tasks.TaskPrioritizer;
|
||||||
@@ -45,7 +46,10 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
|||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT;
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION;
|
||||||
@@ -317,13 +321,13 @@ public class CandidateResolver {
|
|||||||
|
|
||||||
// Restore type variables before alpha-conversion
|
// Restore type variables before alpha-conversion
|
||||||
ConstraintSystem constraintSystemWithRightTypeParameters = constraintSystem.substituteTypeVariables(
|
ConstraintSystem constraintSystemWithRightTypeParameters = constraintSystem.substituteTypeVariables(
|
||||||
new Function<TypeParameterDescriptor, TypeParameterDescriptor>() {
|
new Function1<TypeParameterDescriptor, TypeParameterDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
public TypeParameterDescriptor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) {
|
public TypeParameterDescriptor invoke(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
assert typeParameterDescriptor != null;
|
|
||||||
return candidate.getTypeParameters().get(typeParameterDescriptor.getIndex());
|
return candidate.getTypeParameters().get(typeParameterDescriptor.getIndex());
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
candidateCall.setConstraintSystem(constraintSystemWithRightTypeParameters);
|
candidateCall.setConstraintSystem(constraintSystemWithRightTypeParameters);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import kotlin.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -328,9 +328,9 @@ public class DescriptorUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static JetScope getStaticNestedClassesScope(@NotNull ClassDescriptor descriptor) {
|
public static JetScope getStaticNestedClassesScope(@NotNull ClassDescriptor descriptor) {
|
||||||
JetScope innerClassesScope = descriptor.getUnsubstitutedInnerClassesScope();
|
JetScope innerClassesScope = descriptor.getUnsubstitutedInnerClassesScope();
|
||||||
return new FilteringScope(innerClassesScope, new Predicate<DeclarationDescriptor>() {
|
return new FilteringScope(innerClassesScope, new Function1<DeclarationDescriptor, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
public Boolean invoke(DeclarationDescriptor descriptor) {
|
||||||
return descriptor instanceof ClassDescriptor && !((ClassDescriptor) descriptor).isInner();
|
return descriptor instanceof ClassDescriptor && !((ClassDescriptor) descriptor).isInner();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,12 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Collections2;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
import kotlin.jvm.KotlinSignature;
|
import kotlin.jvm.KotlinSignature;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -378,13 +377,11 @@ public class OverridingUtil {
|
|||||||
@NotNull final ClassDescriptor current,
|
@NotNull final ClassDescriptor current,
|
||||||
@NotNull Collection<CallableMemberDescriptor> toFilter
|
@NotNull Collection<CallableMemberDescriptor> toFilter
|
||||||
) {
|
) {
|
||||||
return Collections2.filter(toFilter, new Predicate<CallableMemberDescriptor>() {
|
return KotlinPackage.filter(toFilter, new Function1<CallableMemberDescriptor, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable CallableMemberDescriptor descriptor) {
|
public Boolean invoke(CallableMemberDescriptor descriptor) {
|
||||||
//nested class could capture private member, so check for private visibility added
|
//nested class could capture private member, so check for private visibility added
|
||||||
return descriptor != null &&
|
return descriptor.getVisibility() != Visibilities.PRIVATE && Visibilities.isVisible(descriptor, current);
|
||||||
descriptor.getVisibility() != Visibilities.PRIVATE &&
|
|
||||||
Visibilities.isVisible(descriptor, current);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -18,8 +18,8 @@ package org.jetbrains.jet.lang.resolve.calls.inference;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.intellij.openapi.util.Condition;
|
import kotlin.Function1;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -65,9 +65,9 @@ public class ConstraintPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasConstraint(@NotNull Collection<ConstraintPosition> positions, final boolean strong) {
|
private static boolean hasConstraint(@NotNull Collection<ConstraintPosition> positions, final boolean strong) {
|
||||||
return ContainerUtil.exists(positions, new Condition<ConstraintPosition>() {
|
return KotlinPackage.any(positions, new Function1<ConstraintPosition, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(ConstraintPosition constraintPosition) {
|
public Boolean invoke(ConstraintPosition constraintPosition) {
|
||||||
return constraintPosition.isStrong() == strong;
|
return constraintPosition.isStrong() == strong;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+40
-37
@@ -16,15 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Functions;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.util.Condition;
|
|
||||||
import com.intellij.openapi.util.Conditions;
|
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||||
@@ -33,6 +29,7 @@ import org.jetbrains.jet.lang.types.*;
|
|||||||
import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure;
|
import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure;
|
||||||
import org.jetbrains.jet.lang.types.checker.TypingConstraints;
|
import org.jetbrains.jet.lang.types.checker.TypingConstraints;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
import org.jetbrains.jet.utils.UtilsPackage;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -202,52 +199,58 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem copy() {
|
public ConstraintSystem copy() {
|
||||||
return createNewConstraintSystemFromThis(Functions.<TypeParameterDescriptor>identity(),
|
return createNewConstraintSystemFromThis(
|
||||||
new Function<TypeBoundsImpl, TypeBoundsImpl>() {
|
UtilsPackage.<TypeParameterDescriptor>identity(),
|
||||||
@Override
|
new Function1<TypeBoundsImpl, TypeBoundsImpl>() {
|
||||||
public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) {
|
@Override
|
||||||
return typeBounds.copy();
|
public TypeBoundsImpl invoke(TypeBoundsImpl typeBounds) {
|
||||||
}
|
return typeBounds.copy();
|
||||||
},
|
}
|
||||||
Conditions.<ConstraintPosition>alwaysTrue());
|
},
|
||||||
|
UtilsPackage.<ConstraintPosition>alwaysTrue()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem substituteTypeVariables(@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
public ConstraintSystem substituteTypeVariables(@NotNull Function1<TypeParameterDescriptor, TypeParameterDescriptor> typeVariablesMap) {
|
||||||
return createNewConstraintSystemFromThis(typeVariablesMap,
|
return createNewConstraintSystemFromThis(
|
||||||
// type bounds are proper types and don't contain other variables
|
typeVariablesMap,
|
||||||
Functions.<TypeBoundsImpl>identity(),
|
// type bounds are proper types and don't contain other variables
|
||||||
Conditions.<ConstraintPosition>alwaysTrue());
|
UtilsPackage.<TypeBoundsImpl>identity(),
|
||||||
|
UtilsPackage.<ConstraintPosition>alwaysTrue()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem filterConstraintsOut(@NotNull ConstraintPosition... excludePositions) {
|
public ConstraintSystem filterConstraintsOut(@NotNull ConstraintPosition... excludePositions) {
|
||||||
final Set<ConstraintPosition> positions = Sets.newHashSet(excludePositions);
|
final Set<ConstraintPosition> positions = Sets.newHashSet(excludePositions);
|
||||||
return filterConstraints(new Condition<ConstraintPosition>() {
|
return filterConstraints(new Function1<ConstraintPosition, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(ConstraintPosition constraintPosition) {
|
public Boolean invoke(ConstraintPosition constraintPosition) {
|
||||||
return !positions.contains(constraintPosition);
|
return !positions.contains(constraintPosition);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem filterConstraints(@NotNull final Condition<ConstraintPosition> condition) {
|
private ConstraintSystem filterConstraints(@NotNull final Function1<ConstraintPosition, Boolean> condition) {
|
||||||
return createNewConstraintSystemFromThis(Functions.<TypeParameterDescriptor>identity(),
|
return createNewConstraintSystemFromThis(
|
||||||
new Function<TypeBoundsImpl, TypeBoundsImpl>() {
|
UtilsPackage.<TypeParameterDescriptor>identity(),
|
||||||
@Override
|
new Function1<TypeBoundsImpl, TypeBoundsImpl>() {
|
||||||
public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) {
|
@Override
|
||||||
return typeBounds.filter(condition);
|
public TypeBoundsImpl invoke(TypeBoundsImpl typeBounds) {
|
||||||
}
|
return typeBounds.filter(condition);
|
||||||
},
|
}
|
||||||
condition);
|
},
|
||||||
|
condition
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstraintSystem getSystemWithoutWeakConstraints() {
|
public ConstraintSystem getSystemWithoutWeakConstraints() {
|
||||||
return filterConstraints(new Condition<ConstraintPosition>() {
|
return filterConstraints(new Function1<ConstraintPosition, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(ConstraintPosition constraintPosition) {
|
public Boolean invoke(ConstraintPosition constraintPosition) {
|
||||||
// 'isStrong' for compound means 'has some strong constraints'
|
// 'isStrong' for compound means 'has some strong constraints'
|
||||||
// but for testing absence of weak constraints we need 'has only strong constraints' here
|
// but for testing absence of weak constraints we need 'has only strong constraints' here
|
||||||
if (constraintPosition instanceof ConstraintPosition.CompoundConstraintPosition) {
|
if (constraintPosition instanceof ConstraintPosition.CompoundConstraintPosition) {
|
||||||
@@ -262,20 +265,20 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ConstraintSystem createNewConstraintSystemFromThis(
|
private ConstraintSystem createNewConstraintSystemFromThis(
|
||||||
@NotNull Function<TypeParameterDescriptor, TypeParameterDescriptor> substituteTypeVariable,
|
@NotNull Function1<TypeParameterDescriptor, TypeParameterDescriptor> substituteTypeVariable,
|
||||||
@NotNull Function<TypeBoundsImpl, TypeBoundsImpl> replaceTypeBounds,
|
@NotNull Function1<TypeBoundsImpl, TypeBoundsImpl> replaceTypeBounds,
|
||||||
@NotNull Condition<ConstraintPosition> filterConstraintPosition
|
@NotNull Function1<ConstraintPosition, Boolean> filterConstraintPosition
|
||||||
) {
|
) {
|
||||||
ConstraintSystemImpl newSystem = new ConstraintSystemImpl();
|
ConstraintSystemImpl newSystem = new ConstraintSystemImpl();
|
||||||
for (Map.Entry<TypeParameterDescriptor, TypeBoundsImpl> entry : typeParameterBounds.entrySet()) {
|
for (Map.Entry<TypeParameterDescriptor, TypeBoundsImpl> entry : typeParameterBounds.entrySet()) {
|
||||||
TypeParameterDescriptor typeParameter = entry.getKey();
|
TypeParameterDescriptor typeParameter = entry.getKey();
|
||||||
TypeBoundsImpl typeBounds = entry.getValue();
|
TypeBoundsImpl typeBounds = entry.getValue();
|
||||||
|
|
||||||
TypeParameterDescriptor newTypeParameter = substituteTypeVariable.apply(typeParameter);
|
TypeParameterDescriptor newTypeParameter = substituteTypeVariable.invoke(typeParameter);
|
||||||
assert newTypeParameter != null;
|
assert newTypeParameter != null;
|
||||||
newSystem.typeParameterBounds.put(newTypeParameter, replaceTypeBounds.apply(typeBounds));
|
newSystem.typeParameterBounds.put(newTypeParameter, replaceTypeBounds.invoke(typeBounds));
|
||||||
}
|
}
|
||||||
newSystem.errorConstraintPositions.addAll(ContainerUtil.filter(errorConstraintPositions, filterConstraintPosition));
|
newSystem.errorConstraintPositions.addAll(KotlinPackage.filter(errorConstraintPositions, filterConstraintPosition));
|
||||||
//todo if 'filterConstraintPosition' is not trivial, it's incorrect to just copy 'hasErrorInConstrainingTypes'
|
//todo if 'filterConstraintPosition' is not trivial, it's incorrect to just copy 'hasErrorInConstrainingTypes'
|
||||||
newSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes;
|
newSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes;
|
||||||
return newSystem;
|
return newSystem;
|
||||||
|
|||||||
+8
-7
@@ -18,8 +18,9 @@ package org.jetbrains.jet.lang.resolve.calls.inference;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.util.Condition;
|
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
|
import kotlin.Function1;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||||
@@ -113,12 +114,12 @@ public class TypeBoundsImpl implements TypeBounds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TypeBoundsImpl filter(@NotNull final Condition<ConstraintPosition> condition) {
|
public TypeBoundsImpl filter(@NotNull final Function1<ConstraintPosition, Boolean> condition) {
|
||||||
TypeBoundsImpl result = new TypeBoundsImpl(typeVariable, varianceOfPosition);
|
TypeBoundsImpl result = new TypeBoundsImpl(typeVariable, varianceOfPosition);
|
||||||
result.bounds.addAll(ContainerUtil.filter(bounds, new Condition<Bound>() {
|
result.bounds.addAll(KotlinPackage.filter(bounds, new Function1<Bound, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(Bound bound) {
|
public Boolean invoke(Bound bound) {
|
||||||
return condition.value(bound.position);
|
return condition.invoke(bound.position);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
return result;
|
return result;
|
||||||
@@ -149,9 +150,9 @@ public class TypeBoundsImpl implements TypeBounds {
|
|||||||
if (bounds.isEmpty()) {
|
if (bounds.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
boolean hasStrongBound = ContainerUtil.exists(bounds, new Condition<Bound>() {
|
boolean hasStrongBound = KotlinPackage.any(bounds, new Function1<Bound, Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean value(Bound bound) {
|
public Boolean invoke(Bound bound) {
|
||||||
return bound.position.isStrong();
|
return bound.position.isStrong();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.scopes;
|
package org.jetbrains.jet.lang.resolve.scopes;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import kotlin.Function1;
|
||||||
import com.google.common.collect.Collections2;
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
@@ -29,10 +29,10 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FilteringScope implements JetScope {
|
public class FilteringScope implements JetScope {
|
||||||
@NotNull private final JetScope workerScope;
|
private final JetScope workerScope;
|
||||||
@NotNull private final Predicate<DeclarationDescriptor> predicate;
|
private final Function1<DeclarationDescriptor, Boolean> predicate;
|
||||||
|
|
||||||
public FilteringScope(@NotNull JetScope workerScope, @NotNull Predicate<DeclarationDescriptor> predicate) {
|
public FilteringScope(@NotNull JetScope workerScope, @NotNull Function1<DeclarationDescriptor, Boolean> predicate) {
|
||||||
this.workerScope = workerScope;
|
this.workerScope = workerScope;
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public class FilteringScope implements JetScope {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||||
return Collections2.filter(workerScope.getFunctions(name), predicate);
|
return KotlinPackage.filter(workerScope.getFunctions(name), predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -51,7 +51,7 @@ public class FilteringScope implements JetScope {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private <D extends DeclarationDescriptor> D filterDescriptor(@Nullable D descriptor) {
|
private <D extends DeclarationDescriptor> D filterDescriptor(@Nullable D descriptor) {
|
||||||
return descriptor != null && predicate.apply(descriptor) ? descriptor : null;
|
return descriptor != null && predicate.invoke(descriptor) ? descriptor : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -68,7 +68,7 @@ public class FilteringScope implements JetScope {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||||
return Collections2.filter(workerScope.getProperties(name), predicate);
|
return KotlinPackage.filter(workerScope.getProperties(name), predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,7 +79,7 @@ public class FilteringScope implements JetScope {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
return Collections2.filter(workerScope.getAllDescriptors(), predicate);
|
return KotlinPackage.filter(workerScope.getAllDescriptors(), predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -91,13 +91,13 @@ public class FilteringScope implements JetScope {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
|
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
|
||||||
return Collections2.filter(workerScope.getDeclarationsByLabel(labelName), predicate);
|
return KotlinPackage.filter(workerScope.getDeclarationsByLabel(labelName), predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
public Collection<DeclarationDescriptor> getOwnDeclaredDescriptors() {
|
||||||
return Collections2.filter(workerScope.getOwnDeclaredDescriptors(), predicate);
|
return KotlinPackage.filter(workerScope.getOwnDeclaredDescriptors(), predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOnly
|
@TestOnly
|
||||||
|
|||||||
+6
-8
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.scopes;
|
package org.jetbrains.jet.lang.resolve.scopes;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import kotlin.KotlinPackage;
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.Collections2;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||||
@@ -31,8 +29,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
|
public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
|
||||||
private static final Predicate<Object> IS_CLASS = Predicates.instanceOf(ClassDescriptor.class);
|
|
||||||
|
|
||||||
private final JetScope actualScope;
|
private final JetScope actualScope;
|
||||||
|
|
||||||
public InnerClassesScopeWrapper(@NotNull JetScope actualScope) {
|
public InnerClassesScopeWrapper(@NotNull JetScope actualScope) {
|
||||||
@@ -48,19 +44,21 @@ public class InnerClassesScopeWrapper extends AbstractScopeAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
public ClassifierDescriptor getClassifier(@NotNull Name name) {
|
||||||
ClassifierDescriptor classifier = actualScope.getClassifier(name);
|
ClassifierDescriptor classifier = actualScope.getClassifier(name);
|
||||||
return IS_CLASS.apply(classifier) ? classifier : null;
|
return classifier instanceof ClassDescriptor ? classifier : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
|
public Collection<DeclarationDescriptor> getDeclarationsByLabel(@NotNull Name labelName) {
|
||||||
return Collections2.filter(actualScope.getDeclarationsByLabel(labelName), IS_CLASS);
|
return (Collection) KotlinPackage.filterIsInstance(actualScope.getDeclarationsByLabel(labelName), ClassDescriptor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
return Collections2.filter(actualScope.getAllDescriptors(), IS_CLASS);
|
return (Collection) KotlinPackage.filterIsInstance(actualScope.getAllDescriptors(), ClassDescriptor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -16,14 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.types;
|
package org.jetbrains.jet.lang.types;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Collections2;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.util.Processor;
|
|
||||||
import kotlin.Function1;
|
import kotlin.Function1;
|
||||||
import kotlin.KotlinPackage;
|
import kotlin.KotlinPackage;
|
||||||
|
import kotlin.Unit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -241,16 +239,16 @@ public class TypeUtils {
|
|||||||
private static boolean unify(JetType withParameters, JetType expected) {
|
private static boolean unify(JetType withParameters, JetType expected) {
|
||||||
// T -> how T is used
|
// T -> how T is used
|
||||||
final Map<TypeParameterDescriptor, Variance> parameters = Maps.newHashMap();
|
final Map<TypeParameterDescriptor, Variance> parameters = Maps.newHashMap();
|
||||||
Processor<TypeParameterUsage> processor = new Processor<TypeParameterUsage>() {
|
Function1<TypeParameterUsage, Unit> processor = new Function1<TypeParameterUsage, Unit>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean process(TypeParameterUsage parameterUsage) {
|
public Unit invoke(TypeParameterUsage parameterUsage) {
|
||||||
Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor);
|
Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor);
|
||||||
if (howTheTypeIsUsedBefore == null) {
|
if (howTheTypeIsUsedBefore == null) {
|
||||||
howTheTypeIsUsedBefore = Variance.INVARIANT;
|
howTheTypeIsUsedBefore = Variance.INVARIANT;
|
||||||
}
|
}
|
||||||
parameters.put(parameterUsage.typeParameterDescriptor,
|
parameters.put(parameterUsage.typeParameterDescriptor,
|
||||||
parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore));
|
parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore));
|
||||||
return true;
|
return Unit.INSTANCE$;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
processAllTypeParameters(withParameters, Variance.INVARIANT, processor);
|
processAllTypeParameters(withParameters, Variance.INVARIANT, processor);
|
||||||
@@ -262,10 +260,10 @@ public class TypeUtils {
|
|||||||
return constraintSystem.getStatus().isSuccessful();
|
return constraintSystem.getStatus().isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processAllTypeParameters(JetType type, Variance howThiTypeIsUsed, Processor<TypeParameterUsage> result) {
|
private static void processAllTypeParameters(JetType type, Variance howThisTypeIsUsed, Function1<TypeParameterUsage, Unit> result) {
|
||||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||||
if (descriptor instanceof TypeParameterDescriptor) {
|
if (descriptor instanceof TypeParameterDescriptor) {
|
||||||
result.process(new TypeParameterUsage((TypeParameterDescriptor)descriptor, howThiTypeIsUsed));
|
result.invoke(new TypeParameterUsage((TypeParameterDescriptor) descriptor, howThisTypeIsUsed));
|
||||||
}
|
}
|
||||||
for (TypeProjection projection : type.getArguments()) {
|
for (TypeProjection projection : type.getArguments()) {
|
||||||
processAllTypeParameters(projection.getType(), projection.getProjectionKind(), result);
|
processAllTypeParameters(projection.getType(), projection.getProjectionKind(), result);
|
||||||
@@ -490,14 +488,15 @@ public class TypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dependsOnTypeParameters(@NotNull JetType type, @NotNull Collection<TypeParameterDescriptor> typeParameters) {
|
public static boolean dependsOnTypeParameters(@NotNull JetType type, @NotNull Collection<TypeParameterDescriptor> typeParameters) {
|
||||||
return dependsOnTypeConstructors(type, Collections2
|
return dependsOnTypeConstructors(type, KotlinPackage.map(
|
||||||
.transform(typeParameters, new Function<TypeParameterDescriptor, TypeConstructor>() {
|
typeParameters,
|
||||||
|
new Function1<TypeParameterDescriptor, TypeConstructor>() {
|
||||||
@Override
|
@Override
|
||||||
public TypeConstructor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) {
|
public TypeConstructor invoke(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
|
||||||
assert typeParameterDescriptor != null;
|
|
||||||
return typeParameterDescriptor.getTypeConstructor();
|
return typeParameterDescriptor.getTypeConstructor();
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean dependsOnTypeConstructors(@NotNull JetType type, @NotNull Collection<TypeConstructor> typeParameterConstructors) {
|
public static boolean dependsOnTypeConstructors(@NotNull JetType type, @NotNull Collection<TypeConstructor> typeParameterConstructors) {
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ package org.jetbrains.jet.renderer;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.Function;
|
import kotlin.Function1;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||||
@@ -435,17 +436,15 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visitArrayValue(ArrayValue value, Void data) {
|
public String visitArrayValue(ArrayValue value, Void data) {
|
||||||
return "{" +
|
List<CompileTimeConstant<?>> elements = value.getValue();
|
||||||
StringUtil.join(
|
if (elements.isEmpty()) return "{}";
|
||||||
value.getValue(),
|
List<String> renderedElements = KotlinPackage.map(elements, new Function1<CompileTimeConstant<?>, String>() {
|
||||||
new Function<CompileTimeConstant<?>, String>() {
|
@Override
|
||||||
@Override
|
public String invoke(CompileTimeConstant<?> constant) {
|
||||||
public String fun(CompileTimeConstant<?> constant) {
|
return renderConstant(constant);
|
||||||
return renderConstant(constant);
|
}
|
||||||
}
|
});
|
||||||
},
|
return "{" + StringUtil.join(renderedElements, ", ") + "}";
|
||||||
", ") +
|
|
||||||
"}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.jet.utils
|
||||||
|
|
||||||
|
private val IDENTITY: Function1<Any?, Any?> = { it }
|
||||||
|
|
||||||
|
suppress("UNCHECKED_CAST")
|
||||||
|
public fun <T> identity(): Function1<T, T> = IDENTITY as Function1<T, T>
|
||||||
|
|
||||||
|
|
||||||
|
private val ALWAYS_TRUE: Function1<Any?, Boolean> = { true }
|
||||||
|
|
||||||
|
public fun <T> alwaysTrue(): Function1<T, Boolean> = ALWAYS_TRUE
|
||||||
Reference in New Issue
Block a user