From df554e7c53744d01a9e4f0050f194987d7bf6130 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 14 Aug 2014 12:34:43 +0400 Subject: [PATCH] Remove dependency of "descriptors" on Function/Condition/Processor --- .../jetbrains/jet/lang/resolve/Importer.java | 9 +-- .../lang/resolve/calls/CandidateResolver.java | 20 +++-- .../jet/lang/resolve/DescriptorUtils.java | 6 +- .../jet/lang/resolve/OverridingUtil.java | 11 +-- .../calls/inference/ConstraintPosition.java | 8 +- .../calls/inference/ConstraintSystemImpl.java | 77 ++++++++++--------- .../calls/inference/TypeBoundsImpl.java | 15 ++-- .../lang/resolve/scopes/FilteringScope.java | 22 +++--- .../scopes/InnerClassesScopeWrapper.java | 14 ++-- .../jetbrains/jet/lang/types/TypeUtils.java | 25 +++--- .../jet/renderer/DescriptorRendererImpl.java | 23 +++--- .../src/org/jetbrains/jet/utils/functions.kt | 27 +++++++ 12 files changed, 142 insertions(+), 115 deletions(-) create mode 100644 core/util.runtime/src/org/jetbrains/jet/utils/functions.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/Importer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/Importer.java index c04e7efd6cc..5139293fb84 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/Importer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/Importer.java @@ -16,9 +16,9 @@ package org.jetbrains.jet.lang.resolve; -import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.intellij.openapi.util.Pair; +import kotlin.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.PlatformToKotlinClassMap; @@ -70,12 +70,11 @@ public interface Importer { @NotNull DeclarationDescriptor descriptor, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap ) { - final Collection kotlinAnalogsForClassesInside = platformToKotlinClassMap.mapPlatformClassesInside( - descriptor); + final Collection kotlinAnalogsForClassesInside = platformToKotlinClassMap.mapPlatformClassesInside(descriptor); if (kotlinAnalogsForClassesInside.isEmpty()) return scope; - return new FilteringScope(scope, new Predicate() { + return new FilteringScope(scope, new Function1() { @Override - public boolean apply(DeclarationDescriptor descriptor) { + public Boolean invoke(DeclarationDescriptor descriptor) { for (ClassDescriptor kotlinAnalog : kotlinAnalogsForClassesInside) { if (kotlinAnalog.getName().equals(descriptor.getName())) { return false; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index 1768f1be66c..9fa329f038a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -16,11 +16,11 @@ package org.jetbrains.jet.lang.resolve.calls; -import com.google.common.base.Function; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.intellij.openapi.progress.ProgressIndicatorProvider; +import kotlin.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; 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.DataFlowValueFactory; 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.results.OverloadResolutionResultsImpl; 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.TaskPrioritizer; @@ -45,7 +46,10 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; 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.SUPER_IS_NOT_AN_EXPRESSION; @@ -317,13 +321,13 @@ public class CandidateResolver { // Restore type variables before alpha-conversion ConstraintSystem constraintSystemWithRightTypeParameters = constraintSystem.substituteTypeVariables( - new Function() { + new Function1() { @Override - public TypeParameterDescriptor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) { - assert typeParameterDescriptor != null; + public TypeParameterDescriptor invoke(@NotNull TypeParameterDescriptor typeParameterDescriptor) { return candidate.getTypeParameters().get(typeParameterDescriptor.getIndex()); } - }); + } + ); candidateCall.setConstraintSystem(constraintSystemWithRightTypeParameters); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 7579d9f41af..10ed897673d 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -16,7 +16,7 @@ package org.jetbrains.jet.lang.resolve; -import com.google.common.base.Predicate; +import kotlin.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; @@ -328,9 +328,9 @@ public class DescriptorUtils { @NotNull public static JetScope getStaticNestedClassesScope(@NotNull ClassDescriptor descriptor) { JetScope innerClassesScope = descriptor.getUnsubstitutedInnerClassesScope(); - return new FilteringScope(innerClassesScope, new Predicate() { + return new FilteringScope(innerClassesScope, new Function1() { @Override - public boolean apply(@Nullable DeclarationDescriptor descriptor) { + public Boolean invoke(DeclarationDescriptor descriptor) { return descriptor instanceof ClassDescriptor && !((ClassDescriptor) descriptor).isInner(); } }); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java index 09c3abc67a9..1d8f8a87093 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/OverridingUtil.java @@ -16,12 +16,11 @@ 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.Sets; import com.intellij.util.containers.ContainerUtil; import kotlin.Function1; +import kotlin.KotlinPackage; import kotlin.Unit; import kotlin.jvm.KotlinSignature; import org.jetbrains.annotations.NotNull; @@ -378,13 +377,11 @@ public class OverridingUtil { @NotNull final ClassDescriptor current, @NotNull Collection toFilter ) { - return Collections2.filter(toFilter, new Predicate() { + return KotlinPackage.filter(toFilter, new Function1() { @Override - public boolean apply(@Nullable CallableMemberDescriptor descriptor) { + public Boolean invoke(CallableMemberDescriptor descriptor) { //nested class could capture private member, so check for private visibility added - return descriptor != null && - descriptor.getVisibility() != Visibilities.PRIVATE && - Visibilities.isVisible(descriptor, current); + return descriptor.getVisibility() != Visibilities.PRIVATE && Visibilities.isVisible(descriptor, current); } }); } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintPosition.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintPosition.java index 86aec6c47b9..6f6c64dc201 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintPosition.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintPosition.java @@ -18,8 +18,8 @@ package org.jetbrains.jet.lang.resolve.calls.inference; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.intellij.openapi.util.Condition; -import com.intellij.util.containers.ContainerUtil; +import kotlin.Function1; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -65,9 +65,9 @@ public class ConstraintPosition { } private static boolean hasConstraint(@NotNull Collection positions, final boolean strong) { - return ContainerUtil.exists(positions, new Condition() { + return KotlinPackage.any(positions, new Function1() { @Override - public boolean value(ConstraintPosition constraintPosition) { + public Boolean invoke(ConstraintPosition constraintPosition) { return constraintPosition.isStrong() == strong; } }); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index 74d5a208bc6..3503cf254ad 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -16,15 +16,11 @@ 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.Maps; 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.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; 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.TypingConstraints; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; +import org.jetbrains.jet.utils.UtilsPackage; import java.util.Collection; import java.util.List; @@ -202,52 +199,58 @@ public class ConstraintSystemImpl implements ConstraintSystem { @Override @NotNull public ConstraintSystem copy() { - return createNewConstraintSystemFromThis(Functions.identity(), - new Function() { - @Override - public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) { - return typeBounds.copy(); - } - }, - Conditions.alwaysTrue()); + return createNewConstraintSystemFromThis( + UtilsPackage.identity(), + new Function1() { + @Override + public TypeBoundsImpl invoke(TypeBoundsImpl typeBounds) { + return typeBounds.copy(); + } + }, + UtilsPackage.alwaysTrue() + ); } @NotNull - public ConstraintSystem substituteTypeVariables(@NotNull Function typeVariablesMap) { - return createNewConstraintSystemFromThis(typeVariablesMap, - // type bounds are proper types and don't contain other variables - Functions.identity(), - Conditions.alwaysTrue()); + public ConstraintSystem substituteTypeVariables(@NotNull Function1 typeVariablesMap) { + return createNewConstraintSystemFromThis( + typeVariablesMap, + // type bounds are proper types and don't contain other variables + UtilsPackage.identity(), + UtilsPackage.alwaysTrue() + ); } @NotNull public ConstraintSystem filterConstraintsOut(@NotNull ConstraintPosition... excludePositions) { final Set positions = Sets.newHashSet(excludePositions); - return filterConstraints(new Condition() { + return filterConstraints(new Function1() { @Override - public boolean value(ConstraintPosition constraintPosition) { + public Boolean invoke(ConstraintPosition constraintPosition) { return !positions.contains(constraintPosition); } }); } @NotNull - public ConstraintSystem filterConstraints(@NotNull final Condition condition) { - return createNewConstraintSystemFromThis(Functions.identity(), - new Function() { - @Override - public TypeBoundsImpl apply(TypeBoundsImpl typeBounds) { - return typeBounds.filter(condition); - } - }, - condition); + private ConstraintSystem filterConstraints(@NotNull final Function1 condition) { + return createNewConstraintSystemFromThis( + UtilsPackage.identity(), + new Function1() { + @Override + public TypeBoundsImpl invoke(TypeBoundsImpl typeBounds) { + return typeBounds.filter(condition); + } + }, + condition + ); } @NotNull public ConstraintSystem getSystemWithoutWeakConstraints() { - return filterConstraints(new Condition() { + return filterConstraints(new Function1() { @Override - public boolean value(ConstraintPosition constraintPosition) { + public Boolean invoke(ConstraintPosition constraintPosition) { // 'isStrong' for compound means 'has some strong constraints' // but for testing absence of weak constraints we need 'has only strong constraints' here if (constraintPosition instanceof ConstraintPosition.CompoundConstraintPosition) { @@ -262,20 +265,20 @@ public class ConstraintSystemImpl implements ConstraintSystem { @NotNull private ConstraintSystem createNewConstraintSystemFromThis( - @NotNull Function substituteTypeVariable, - @NotNull Function replaceTypeBounds, - @NotNull Condition filterConstraintPosition + @NotNull Function1 substituteTypeVariable, + @NotNull Function1 replaceTypeBounds, + @NotNull Function1 filterConstraintPosition ) { ConstraintSystemImpl newSystem = new ConstraintSystemImpl(); for (Map.Entry entry : typeParameterBounds.entrySet()) { TypeParameterDescriptor typeParameter = entry.getKey(); TypeBoundsImpl typeBounds = entry.getValue(); - TypeParameterDescriptor newTypeParameter = substituteTypeVariable.apply(typeParameter); + TypeParameterDescriptor newTypeParameter = substituteTypeVariable.invoke(typeParameter); 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' newSystem.hasErrorInConstrainingTypes = hasErrorInConstrainingTypes; return newSystem; diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeBoundsImpl.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeBoundsImpl.java index edc9d573c28..9bdddc97fc8 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeBoundsImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/calls/inference/TypeBoundsImpl.java @@ -18,8 +18,9 @@ package org.jetbrains.jet.lang.resolve.calls.inference; import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.intellij.openapi.util.Condition; import com.intellij.util.containers.ContainerUtil; +import kotlin.Function1; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; @@ -113,12 +114,12 @@ public class TypeBoundsImpl implements TypeBounds { } @NotNull - public TypeBoundsImpl filter(@NotNull final Condition condition) { + public TypeBoundsImpl filter(@NotNull final Function1 condition) { TypeBoundsImpl result = new TypeBoundsImpl(typeVariable, varianceOfPosition); - result.bounds.addAll(ContainerUtil.filter(bounds, new Condition() { + result.bounds.addAll(KotlinPackage.filter(bounds, new Function1() { @Override - public boolean value(Bound bound) { - return condition.value(bound.position); + public Boolean invoke(Bound bound) { + return condition.invoke(bound.position); } })); return result; @@ -149,9 +150,9 @@ public class TypeBoundsImpl implements TypeBounds { if (bounds.isEmpty()) { return Collections.emptyList(); } - boolean hasStrongBound = ContainerUtil.exists(bounds, new Condition() { + boolean hasStrongBound = KotlinPackage.any(bounds, new Function1() { @Override - public boolean value(Bound bound) { + public Boolean invoke(Bound bound) { return bound.position.isStrong(); } }); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/FilteringScope.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/FilteringScope.java index 4e00f2a2483..a7fa99430e4 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/FilteringScope.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/FilteringScope.java @@ -16,8 +16,8 @@ package org.jetbrains.jet.lang.resolve.scopes; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; +import kotlin.Function1; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -29,10 +29,10 @@ import java.util.Collection; import java.util.List; public class FilteringScope implements JetScope { - @NotNull private final JetScope workerScope; - @NotNull private final Predicate predicate; + private final JetScope workerScope; + private final Function1 predicate; - public FilteringScope(@NotNull JetScope workerScope, @NotNull Predicate predicate) { + public FilteringScope(@NotNull JetScope workerScope, @NotNull Function1 predicate) { this.workerScope = workerScope; this.predicate = predicate; } @@ -40,7 +40,7 @@ public class FilteringScope implements JetScope { @NotNull @Override public Collection getFunctions(@NotNull Name name) { - return Collections2.filter(workerScope.getFunctions(name), predicate); + return KotlinPackage.filter(workerScope.getFunctions(name), predicate); } @NotNull @@ -51,7 +51,7 @@ public class FilteringScope implements JetScope { @Nullable private D filterDescriptor(@Nullable D descriptor) { - return descriptor != null && predicate.apply(descriptor) ? descriptor : null; + return descriptor != null && predicate.invoke(descriptor) ? descriptor : null; } @Nullable @@ -68,7 +68,7 @@ public class FilteringScope implements JetScope { @NotNull @Override public Collection getProperties(@NotNull Name name) { - return Collections2.filter(workerScope.getProperties(name), predicate); + return KotlinPackage.filter(workerScope.getProperties(name), predicate); } @Override @@ -79,7 +79,7 @@ public class FilteringScope implements JetScope { @NotNull @Override public Collection getAllDescriptors() { - return Collections2.filter(workerScope.getAllDescriptors(), predicate); + return KotlinPackage.filter(workerScope.getAllDescriptors(), predicate); } @NotNull @@ -91,13 +91,13 @@ public class FilteringScope implements JetScope { @NotNull @Override public Collection getDeclarationsByLabel(@NotNull Name labelName) { - return Collections2.filter(workerScope.getDeclarationsByLabel(labelName), predicate); + return KotlinPackage.filter(workerScope.getDeclarationsByLabel(labelName), predicate); } @NotNull @Override public Collection getOwnDeclaredDescriptors() { - return Collections2.filter(workerScope.getOwnDeclaredDescriptors(), predicate); + return KotlinPackage.filter(workerScope.getOwnDeclaredDescriptors(), predicate); } @TestOnly diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/InnerClassesScopeWrapper.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/InnerClassesScopeWrapper.java index b8b42d731bb..90feff3b6a4 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/InnerClassesScopeWrapper.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/scopes/InnerClassesScopeWrapper.java @@ -16,9 +16,7 @@ package org.jetbrains.jet.lang.resolve.scopes; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; @@ -31,8 +29,6 @@ import java.util.Collections; import java.util.List; public class InnerClassesScopeWrapper extends AbstractScopeAdapter { - private static final Predicate IS_CLASS = Predicates.instanceOf(ClassDescriptor.class); - private final JetScope actualScope; public InnerClassesScopeWrapper(@NotNull JetScope actualScope) { @@ -48,19 +44,21 @@ public class InnerClassesScopeWrapper extends AbstractScopeAdapter { @Override public ClassifierDescriptor getClassifier(@NotNull Name name) { ClassifierDescriptor classifier = actualScope.getClassifier(name); - return IS_CLASS.apply(classifier) ? classifier : null; + return classifier instanceof ClassDescriptor ? classifier : null; } @NotNull @Override + @SuppressWarnings("unchecked") public Collection getDeclarationsByLabel(@NotNull Name labelName) { - return Collections2.filter(actualScope.getDeclarationsByLabel(labelName), IS_CLASS); + return (Collection) KotlinPackage.filterIsInstance(actualScope.getDeclarationsByLabel(labelName), ClassDescriptor.class); } @NotNull @Override + @SuppressWarnings("unchecked") public Collection getAllDescriptors() { - return Collections2.filter(actualScope.getAllDescriptors(), IS_CLASS); + return (Collection) KotlinPackage.filterIsInstance(actualScope.getAllDescriptors(), ClassDescriptor.class); } @NotNull diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java index ea62956e631..41425cec654 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -16,14 +16,12 @@ 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.Maps; import com.google.common.collect.Sets; -import com.intellij.util.Processor; import kotlin.Function1; import kotlin.KotlinPackage; +import kotlin.Unit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; @@ -241,16 +239,16 @@ public class TypeUtils { private static boolean unify(JetType withParameters, JetType expected) { // T -> how T is used final Map parameters = Maps.newHashMap(); - Processor processor = new Processor() { + Function1 processor = new Function1() { @Override - public boolean process(TypeParameterUsage parameterUsage) { + public Unit invoke(TypeParameterUsage parameterUsage) { Variance howTheTypeIsUsedBefore = parameters.get(parameterUsage.typeParameterDescriptor); if (howTheTypeIsUsedBefore == null) { howTheTypeIsUsedBefore = Variance.INVARIANT; } parameters.put(parameterUsage.typeParameterDescriptor, parameterUsage.howTheTypeParameterIsUsed.superpose(howTheTypeIsUsedBefore)); - return true; + return Unit.INSTANCE$; } }; processAllTypeParameters(withParameters, Variance.INVARIANT, processor); @@ -262,10 +260,10 @@ public class TypeUtils { return constraintSystem.getStatus().isSuccessful(); } - private static void processAllTypeParameters(JetType type, Variance howThiTypeIsUsed, Processor result) { + private static void processAllTypeParameters(JetType type, Variance howThisTypeIsUsed, Function1 result) { ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); if (descriptor instanceof TypeParameterDescriptor) { - result.process(new TypeParameterUsage((TypeParameterDescriptor)descriptor, howThiTypeIsUsed)); + result.invoke(new TypeParameterUsage((TypeParameterDescriptor) descriptor, howThisTypeIsUsed)); } for (TypeProjection projection : type.getArguments()) { processAllTypeParameters(projection.getType(), projection.getProjectionKind(), result); @@ -490,14 +488,15 @@ public class TypeUtils { } public static boolean dependsOnTypeParameters(@NotNull JetType type, @NotNull Collection typeParameters) { - return dependsOnTypeConstructors(type, Collections2 - .transform(typeParameters, new Function() { + return dependsOnTypeConstructors(type, KotlinPackage.map( + typeParameters, + new Function1() { @Override - public TypeConstructor apply(@Nullable TypeParameterDescriptor typeParameterDescriptor) { - assert typeParameterDescriptor != null; + public TypeConstructor invoke(@NotNull TypeParameterDescriptor typeParameterDescriptor) { return typeParameterDescriptor.getTypeConstructor(); } - })); + } + )); } public static boolean dependsOnTypeConstructors(@NotNull JetType type, @NotNull Collection typeParameterConstructors) { diff --git a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java index 6d9e0c3e176..191cf12bfe2 100644 --- a/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java +++ b/core/descriptors/src/org/jetbrains/jet/renderer/DescriptorRendererImpl.java @@ -19,7 +19,8 @@ package org.jetbrains.jet.renderer; import com.google.common.collect.Lists; import com.google.common.collect.Sets; 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.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.Annotated; @@ -435,17 +436,15 @@ public class DescriptorRendererImpl implements DescriptorRenderer { @Override public String visitArrayValue(ArrayValue value, Void data) { - return "{" + - StringUtil.join( - value.getValue(), - new Function, String>() { - @Override - public String fun(CompileTimeConstant constant) { - return renderConstant(constant); - } - }, - ", ") + - "}"; + List> elements = value.getValue(); + if (elements.isEmpty()) return "{}"; + List renderedElements = KotlinPackage.map(elements, new Function1, String>() { + @Override + public String invoke(CompileTimeConstant constant) { + return renderConstant(constant); + } + }); + return "{" + StringUtil.join(renderedElements, ", ") + "}"; } @Override diff --git a/core/util.runtime/src/org/jetbrains/jet/utils/functions.kt b/core/util.runtime/src/org/jetbrains/jet/utils/functions.kt new file mode 100644 index 00000000000..5bf525dc333 --- /dev/null +++ b/core/util.runtime/src/org/jetbrains/jet/utils/functions.kt @@ -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 = { it } + +suppress("UNCHECKED_CAST") +public fun identity(): Function1 = IDENTITY as Function1 + + +private val ALWAYS_TRUE: Function1 = { true } + +public fun alwaysTrue(): Function1 = ALWAYS_TRUE