Use java.util.function.Predicate instead of Guava

This commit is contained in:
Alexander Udalov
2017-03-31 20:55:28 +03:00
parent f723ad76f7
commit 08b50cab08
19 changed files with 72 additions and 149 deletions
@@ -16,9 +16,10 @@
package org.jetbrains.kotlin.cli.common.messages; package org.jetbrains.kotlin.cli.common.messages;
import com.google.common.base.Predicate;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Predicate;
public class FilteringMessageCollector implements MessageCollector { public class FilteringMessageCollector implements MessageCollector {
private final MessageCollector messageCollector; private final MessageCollector messageCollector;
private final Predicate<CompilerMessageSeverity> decline; private final Predicate<CompilerMessageSeverity> decline;
@@ -37,7 +38,7 @@ public class FilteringMessageCollector implements MessageCollector {
public void report( public void report(
@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location @NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location
) { ) {
if (!decline.apply(severity)) { if (!decline.test(severity)) {
messageCollector.report(severity, message, location); messageCollector.report(severity, message, location);
} }
} }
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.cli.common; package org.jetbrains.kotlin.cli.common;
import com.google.common.base.Predicates;
import com.intellij.openapi.Disposable; import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.SystemInfo;
@@ -41,6 +40,7 @@ import java.io.PrintStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate;
import static org.jetbrains.kotlin.cli.common.ExitCode.*; import static org.jetbrains.kotlin.cli.common.ExitCode.*;
import static org.jetbrains.kotlin.cli.common.environment.UtilKt.setIdeaIoUseFallback; import static org.jetbrains.kotlin.cli.common.environment.UtilKt.setIdeaIoUseFallback;
@@ -139,7 +139,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
printVersionIfNeeded(messageCollector, arguments); printVersionIfNeeded(messageCollector, arguments);
if (arguments.suppressWarnings) { if (arguments.suppressWarnings) {
messageCollector = new FilteringMessageCollector(messageCollector, Predicates.equalTo(CompilerMessageSeverity.WARNING)); messageCollector = new FilteringMessageCollector(messageCollector, Predicate.isEqual(CompilerMessageSeverity.WARNING));
} }
reportUnknownExtraFlags(messageCollector, arguments); reportUnknownExtraFlags(messageCollector, arguments);
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.cli.jvm package org.jetbrains.kotlin.cli.jvm
import com.google.common.base.Predicates.`in`
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
@@ -142,7 +141,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
val destination = arguments.destination val destination = arguments.destination
if (arguments.module != null) { if (arguments.module != null) {
val sanitizedCollector = FilteringMessageCollector(messageCollector, `in`(CompilerMessageSeverity.VERBOSE)) val sanitizedCollector = FilteringMessageCollector(messageCollector, CompilerMessageSeverity.VERBOSE::contains)
val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector) val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector)
if (destination != null) { if (destination != null) {
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.checkers; package org.jetbrains.kotlin.checkers;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.TextRange;
@@ -415,19 +413,14 @@ public class CheckerTestUtil {
} }
public static StringBuffer addDiagnosticMarkersToText( public static StringBuffer addDiagnosticMarkersToText(
@NotNull final PsiFile psiFile, @NotNull PsiFile psiFile,
@NotNull Collection<ActualDiagnostic> diagnostics, @NotNull Collection<ActualDiagnostic> diagnostics,
@NotNull Map<ActualDiagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic, @NotNull Map<ActualDiagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
@NotNull Function<PsiFile, String> getFileText @NotNull Function<PsiFile, String> getFileText
) { ) {
String text = getFileText.fun(psiFile); String text = getFileText.fun(psiFile);
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
diagnostics = Collections2.filter(diagnostics, new Predicate<ActualDiagnostic>() { diagnostics = CollectionsKt.filter(diagnostics, actualDiagnostic -> psiFile.equals(actualDiagnostic.getFile()));
@Override
public boolean apply(ActualDiagnostic actualDiagnostic) {
return psiFile.equals(actualDiagnostic.getFile());
}
});
if (!diagnostics.isEmpty()) { if (!diagnostics.isEmpty()) {
List<DiagnosticDescriptor> diagnosticDescriptors = getSortedDiagnosticDescriptors(diagnostics); List<DiagnosticDescriptor> diagnosticDescriptors = getSortedDiagnosticDescriptors(diagnostics);
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.diagnostics.rendering; package org.jetbrains.kotlin.diagnostics.rendering;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -32,6 +30,7 @@ import org.jetbrains.kotlin.types.KotlinType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
public class TabledDescriptorRenderer { public class TabledDescriptorRenderer {
public interface TableOrTextRenderer {} public interface TableOrTextRenderer {}
@@ -68,8 +67,7 @@ public class TabledDescriptorRenderer {
} }
public TableRenderer functionArgumentTypeList(@Nullable KotlinType receiverType, @NotNull List<KotlinType> argumentTypes) { public TableRenderer functionArgumentTypeList(@Nullable KotlinType receiverType, @NotNull List<KotlinType> argumentTypes) {
return functionArgumentTypeList(receiverType, argumentTypes, position -> false);
return functionArgumentTypeList(receiverType, argumentTypes, Predicates.<ConstraintPosition>alwaysFalse());
} }
public TableRenderer functionArgumentTypeList(@Nullable KotlinType receiverType, public TableRenderer functionArgumentTypeList(@Nullable KotlinType receiverType,
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.psi; package org.jetbrains.kotlin.psi;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiComment; import com.intellij.psi.PsiComment;
@@ -47,6 +46,7 @@ import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate;
public class KtPsiUtil { public class KtPsiUtil {
private KtPsiUtil() { private KtPsiUtil() {
@@ -587,13 +587,6 @@ public class KtPsiUtil {
return null; return null;
} }
public static final Predicate<KtElement> ANY_JET_ELEMENT = new Predicate<KtElement>() {
@Override
public boolean apply(@Nullable KtElement input) {
return true;
}
};
@NotNull @NotNull
public static String getText(@Nullable PsiElement element) { public static String getText(@Nullable PsiElement element) {
return element != null ? element.getText() : ""; return element != null ? element.getText() : "";
@@ -644,17 +637,17 @@ public class KtPsiUtil {
public static KtElement getOutermostDescendantElement( public static KtElement getOutermostDescendantElement(
@Nullable PsiElement root, @Nullable PsiElement root,
boolean first, boolean first,
final @NotNull Predicate<KtElement> predicate @NotNull Predicate<KtElement> predicate
) { ) {
if (!(root instanceof KtElement)) return null; if (!(root instanceof KtElement)) return null;
final List<KtElement> results = Lists.newArrayList(); List<KtElement> results = Lists.newArrayList();
root.accept( root.accept(
new KtVisitorVoid() { new KtVisitorVoid() {
@Override @Override
public void visitKtElement(@NotNull KtElement element) { public void visitKtElement(@NotNull KtElement element) {
if (predicate.apply(element)) { if (predicate.test(element)) {
//noinspection unchecked //noinspection unchecked
results.add(element); results.add(element);
} }
@@ -680,7 +673,7 @@ public class KtPsiUtil {
public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate<PsiElement> elementsToSkip) { public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate<PsiElement> elementsToSkip) {
if (element == null) return null; if (element == null) return null;
for (PsiElement e = element.getPrevSibling(); e != null; e = e.getPrevSibling()) { for (PsiElement e = element.getPrevSibling(); e != null; e = e.getPrevSibling()) {
if (elementsToSkip.apply(e)) continue; if (elementsToSkip.test(e)) continue;
return e; return e;
} }
return null; return null;
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.resolve.lazy; package org.jetbrains.kotlin.resolve.lazy;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.ClassDescriptor; import org.jetbrains.kotlin.descriptors.ClassDescriptor;
@@ -25,7 +23,10 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
import org.jetbrains.kotlin.descriptors.ModuleDescriptor; import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor; import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
import org.jetbrains.kotlin.incremental.components.NoLookupLocation; import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
import org.jetbrains.kotlin.name.*; import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNamesUtilKt;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.psi.KtNamedDeclaration; import org.jetbrains.kotlin.psi.KtNamedDeclaration;
import org.jetbrains.kotlin.psi.KtNamedDeclarationUtil; import org.jetbrains.kotlin.psi.KtNamedDeclarationUtil;
import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.resolve.scopes.MemberScope;
@@ -33,6 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.function.Predicate;
public class ResolveSessionUtils { public class ResolveSessionUtils {
@@ -41,11 +43,11 @@ public class ResolveSessionUtils {
@NotNull @NotNull
public static Collection<ClassDescriptor> getClassDescriptorsByFqName(@NotNull ModuleDescriptor module, @NotNull FqName fqName) { public static Collection<ClassDescriptor> getClassDescriptorsByFqName(@NotNull ModuleDescriptor module, @NotNull FqName fqName) {
return getClassOrObjectDescriptorsByFqName(module, fqName, Predicates.<ClassDescriptor>alwaysTrue()); return getClassOrObjectDescriptorsByFqName(module, fqName, descriptor -> true);
} }
@NotNull @NotNull
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName( private static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
@NotNull ModuleDescriptor module, @NotNull ModuleDescriptor module,
@NotNull FqName fqName, @NotNull FqName fqName,
@NotNull Predicate<ClassDescriptor> filter @NotNull Predicate<ClassDescriptor> filter
@@ -60,7 +62,7 @@ public class ResolveSessionUtils {
if (!packageDescriptor.isEmpty()) { if (!packageDescriptor.isEmpty()) {
FqName relativeClassFqName = FqNamesUtilKt.tail(fqName, packageFqName); FqName relativeClassFqName = FqNamesUtilKt.tail(fqName, packageFqName);
ClassDescriptor classDescriptor = findClassByRelativePath(packageDescriptor.getMemberScope(), relativeClassFqName); ClassDescriptor classDescriptor = findClassByRelativePath(packageDescriptor.getMemberScope(), relativeClassFqName);
if (classDescriptor != null && filter.apply(classDescriptor)) { if (classDescriptor != null && filter.test(classDescriptor)) {
result.add(classDescriptor); result.add(classDescriptor);
} }
} }
@@ -16,11 +16,10 @@
package org.jetbrains.kotlin.resolve.lazy.declarations; package org.jetbrains.kotlin.resolve.lazy.declarations;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function0;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -72,17 +71,12 @@ public class FileBasedDeclarationProviderFactory extends AbstractDeclarationProv
} }
} }
/*package*/ boolean isPackageDeclaredExplicitly(@NotNull FqName packageFqName) { private boolean isPackageDeclaredExplicitly(@NotNull FqName packageFqName) {
return index.invoke().declaredPackages.contains(packageFqName); return index.invoke().declaredPackages.contains(packageFqName);
} }
/*package*/ Collection<FqName> getAllDeclaredSubPackagesOf(@NotNull final FqName parent) { /*package*/ Collection<FqName> getAllDeclaredSubPackagesOf(@NotNull FqName parent) {
return Collections2.filter(index.invoke().declaredPackages, new Predicate<FqName>() { return CollectionsKt.filter(index.invoke().declaredPackages, fqName -> !fqName.isRoot() && fqName.parent().equals(parent));
@Override
public boolean apply(FqName fqName) {
return !fqName.isRoot() && fqName.parent().equals(parent);
}
});
} }
@Nullable @Nullable
@@ -16,9 +16,6 @@
package org.jetbrains.kotlin.resolve.lazy.descriptors; package org.jetbrains.kotlin.resolve.lazy.descriptors;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.PsiNameIdentifierOwner;
import kotlin.collections.CollectionsKt; import kotlin.collections.CollectionsKt;
@@ -73,13 +70,11 @@ import static org.jetbrains.kotlin.resolve.BindingContext.TYPE;
import static org.jetbrains.kotlin.resolve.ModifiersChecker.*; import static org.jetbrains.kotlin.resolve.ModifiersChecker.*;
public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDescriptorWithResolutionScopes, LazyEntity { public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDescriptorWithResolutionScopes, LazyEntity {
private static final Predicate<KotlinType> VALID_SUPERTYPE = new Predicate<KotlinType>() { private static final Function1<KotlinType, Boolean> VALID_SUPERTYPE = type -> {
@Override assert !type.isError() : "Error types must be filtered out in DescriptorResolver";
public boolean apply(KotlinType type) { return TypeUtils.getClassDescriptor(type) != null;
assert !type.isError() : "Error types must be filtered out in DescriptorResolver";
return TypeUtils.getClassDescriptor(type) != null;
}
}; };
private final LazyClassContext c; private final LazyClassContext c;
@Nullable // can be null in KtScript @Nullable // can be null in KtScript
@@ -735,6 +730,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
.resolveSupertypes(getScopeForClassHeaderResolution(), this, classOrObject, .resolveSupertypes(getScopeForClassHeaderResolution(), this, classOrObject,
c.getTrace()); c.getTrace());
return Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)); return new ArrayList<>(CollectionsKt.filter(allSupertypes, VALID_SUPERTYPE));
} }
} }
@@ -16,15 +16,14 @@
package org.jetbrains.kotlin.types package org.jetbrains.kotlin.types
import com.google.common.base.Predicates
import com.google.common.collect.Maps import com.google.common.collect.Maps
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.resolve.DescriptorUtils
object CastDiagnosticsUtil { object CastDiagnosticsUtil {
@@ -150,8 +149,8 @@ object CastDiagnosticsUtil {
if (supertypeWithVariables != null) { if (supertypeWithVariables != null) {
// Now, let's try to unify Collection<T> and Collection<Foo> solution is a map from T to Foo // Now, let's try to unify Collection<T> and Collection<Foo> solution is a map from T to Foo
val solution = TypeUnifier.unify( val solution = TypeUnifier.unify(
TypeProjectionImpl(supertype), TypeProjectionImpl(supertypeWithVariables), TypeProjectionImpl(supertype), TypeProjectionImpl(supertypeWithVariables), variableConstructors::contains
Predicates.`in`(variableConstructors)) )
substitution = Maps.newHashMap(solution.substitution) substitution = Maps.newHashMap(solution.substitution)
} }
else { else {
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.types; package org.jetbrains.kotlin.types;
import com.google.common.base.Predicate;
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 org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -24,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate;
public class TypeUnifier { public class TypeUnifier {
@@ -100,7 +100,7 @@ public class TypeUnifier {
// Foo ~ X => x |-> Foo // Foo ~ X => x |-> Foo
TypeConstructor maybeVariable = withVariables.getConstructor(); TypeConstructor maybeVariable = withVariables.getConstructor();
if (isVariable.apply(maybeVariable)) { if (isVariable.test(maybeVariable)) {
result.put(maybeVariable, new TypeProjectionImpl(knownProjectionKind, known)); result.put(maybeVariable, new TypeProjectionImpl(knownProjectionKind, known));
return; return;
} }
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.checkers package org.jetbrains.kotlin.checkers
import com.google.common.base.Predicate
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
@@ -65,10 +64,10 @@ import org.jetbrains.kotlin.test.util.DescriptorValidator
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE_ALL import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE_ALL
import org.jetbrains.kotlin.utils.keysToMap
import org.junit.Assert import org.junit.Assert
import java.io.File import java.io.File
import java.util.* import java.util.*
import java.util.function.Predicate
abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() { abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
override fun analyzeAndCheck(testDataFile: File, files: List<TestFile>) { override fun analyzeAndCheck(testDataFile: File, files: List<TestFile>) {
@@ -409,7 +408,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
val packagesNames = getTopLevelPackagesFromFileList(getKtFiles(testFiles, false)) val packagesNames = getTopLevelPackagesFromFileList(getKtFiles(testFiles, false))
val stepIntoFilter = Predicate<DeclarationDescriptor> { descriptor -> val stepIntoFilter = Predicate<DeclarationDescriptor> { descriptor ->
val module = DescriptorUtils.getContainingModuleOrNull(descriptor!!) val module = DescriptorUtils.getContainingModuleOrNull(descriptor)
if (module !in modules) return@Predicate false if (module !in modules) return@Predicate false
if (descriptor is PackageViewDescriptor) { if (descriptor is PackageViewDescriptor) {
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.test.util; package org.jetbrains.kotlin.test.util;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -32,6 +30,7 @@ import org.junit.Assert;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
public class DescriptorValidator { public class DescriptorValidator {
@@ -67,7 +66,7 @@ public class DescriptorValidator {
} }
private boolean allowErrorTypes = false; private boolean allowErrorTypes = false;
private Predicate<DeclarationDescriptor> recursiveFilter = Predicates.alwaysTrue(); private Predicate<DeclarationDescriptor> recursiveFilter = descriptor -> true;
protected ValidationVisitor() { protected ValidationVisitor() {
} }
@@ -86,7 +85,7 @@ public class DescriptorValidator {
protected void validateScope(DeclarationDescriptor scopeOwner, @NotNull MemberScope scope, @NotNull DiagnosticCollector collector) { protected void validateScope(DeclarationDescriptor scopeOwner, @NotNull MemberScope scope, @NotNull DiagnosticCollector collector) {
for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(scope)) { for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(scope)) {
if (recursiveFilter.apply(descriptor)) { if (recursiveFilter.test(descriptor)) {
descriptor.accept(new ScopeValidatorVisitor(collector), scope); descriptor.accept(new ScopeValidatorVisitor(collector), scope);
} }
} }
@@ -197,7 +196,7 @@ public class DescriptorValidator {
@Override @Override
public Boolean visitPackageViewDescriptor(PackageViewDescriptor descriptor, DiagnosticCollector collector) { public Boolean visitPackageViewDescriptor(PackageViewDescriptor descriptor, DiagnosticCollector collector) {
if (!recursiveFilter.apply(descriptor)) return false; if (!recursiveFilter.test(descriptor)) return false;
validateScope(descriptor, descriptor.getMemberScope(), collector); validateScope(descriptor, descriptor.getMemberScope(), collector);
return true; return true;
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.test.util; package org.jetbrains.kotlin.test.util;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import kotlin.Unit; import kotlin.Unit;
@@ -44,6 +42,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden; import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden;
@@ -68,24 +67,18 @@ public class RecursiveDescriptorComparator {
); );
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false, false, public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false, false,
Predicates.<DeclarationDescriptor>alwaysTrue(), descriptor -> true, errorTypesForbidden(), DEFAULT_RENDERER);
errorTypesForbidden(), DEFAULT_RENDERER);
public static final Configuration RECURSIVE = new Configuration(false, false, true, false, public static final Configuration RECURSIVE = new Configuration(false, false, true, false,
Predicates.<DeclarationDescriptor>alwaysTrue(), descriptor -> true, errorTypesForbidden(), DEFAULT_RENDERER);
errorTypesForbidden(), DEFAULT_RENDERER);
public static final Configuration RECURSIVE_ALL = new Configuration(true, true, true, false, public static final Configuration RECURSIVE_ALL = new Configuration(true, true, true, false,
Predicates.<DeclarationDescriptor>alwaysTrue(), descriptor -> true, errorTypesForbidden(), DEFAULT_RENDERER);
errorTypesForbidden(), DEFAULT_RENDERER);
public static final Predicate<DeclarationDescriptor> SKIP_BUILT_INS_PACKAGES = new Predicate<DeclarationDescriptor>() { public static final Predicate<DeclarationDescriptor> SKIP_BUILT_INS_PACKAGES = descriptor -> {
@Override if (descriptor instanceof PackageViewDescriptor) {
public boolean apply(DeclarationDescriptor descriptor) { return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(((PackageViewDescriptor) descriptor).getFqName());
if (descriptor instanceof PackageViewDescriptor) {
return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(((PackageViewDescriptor) descriptor).getFqName());
}
return true;
} }
return true;
}; };
private static final ImmutableSet<String> KOTLIN_ANY_METHOD_NAMES = ImmutableSet.of("equals", "hashCode", "toString"); private static final ImmutableSet<String> KOTLIN_ANY_METHOD_NAMES = ImmutableSet.of("equals", "hashCode", "toString");
@@ -216,7 +209,7 @@ public class RecursiveDescriptorComparator {
boolean isFunctionFromAny = subDescriptor.getContainingDeclaration() instanceof ClassDescriptor boolean isFunctionFromAny = subDescriptor.getContainingDeclaration() instanceof ClassDescriptor
&& subDescriptor instanceof FunctionDescriptor && subDescriptor instanceof FunctionDescriptor
&& KOTLIN_ANY_METHOD_NAMES.contains(subDescriptor.getName().asString()); && KOTLIN_ANY_METHOD_NAMES.contains(subDescriptor.getName().asString());
return (isFunctionFromAny && !conf.includeMethodsOfKotlinAny) || !conf.recursiveFilter.apply(subDescriptor); return (isFunctionFromAny && !conf.includeMethodsOfKotlinAny) || !conf.recursiveFilter.test(subDescriptor);
} }
private void appendSubDescriptors( private void appendSubDescriptors(
@@ -16,8 +16,7 @@
package org.jetbrains.kotlin.codegen; package org.jetbrains.kotlin.codegen;
import com.google.common.base.Predicate; import kotlin.collections.CollectionsKt;
import com.google.common.collect.Collections2;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.load.java.JvmAbi; import org.jetbrains.kotlin.load.java.JvmAbi;
@@ -120,15 +119,10 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
doTest(code, classFilePart); doTest(code, classFilePart);
} }
private void doTest(@NotNull String code, @NotNull final String classFilePart) { private void doTest(@NotNull String code, @NotNull String classFilePart) {
loadText("package " + PACKAGE_NAME + "\n\n" + code); loadText("package " + PACKAGE_NAME + "\n\n" + code);
List<OutputFile> output = generateClassesInFile().asList(); List<OutputFile> output = generateClassesInFile().asList();
Collection<OutputFile> files = Collections2.filter(output, new Predicate<OutputFile>() { Collection<OutputFile> files = CollectionsKt.filter(output, file -> file.getRelativePath().contains(classFilePart));
@Override
public boolean apply(OutputFile file) {
return file.getRelativePath().contains(classFilePart);
}
});
assertFalse("No files with \"" + classFilePart + "\" in the name are found: " + output, files.isEmpty()); assertFalse("No files with \"" + classFilePart + "\" in the name are found: " + output, files.isEmpty());
assertTrue("Exactly one file with \"" + classFilePart + "\" in the name should be found: " + files, files.size() == 1); assertTrue("Exactly one file with \"" + classFilePart + "\" in the name should be found: " + files, files.size() == 1);
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.types; package org.jetbrains.kotlin.types;
import com.google.common.base.Predicate;
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 kotlin.Unit; import kotlin.Unit;
@@ -181,16 +180,7 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
} }
private void doTest(String known, String withVariables, @NotNull Map<String, String> expected) { private void doTest(String known, String withVariables, @NotNull Map<String, String> expected) {
TypeUnifier.UnificationResult map = TypeUnifier.unify( TypeUnifier.UnificationResult map = TypeUnifier.unify(makeType(known), makeType(withVariables), variables::contains);
makeType(known),
makeType(withVariables),
new Predicate<TypeConstructor>() {
@Override
public boolean apply(TypeConstructor tc) {
return variables.contains(tc);
}
}
);
assertEquals(expected, toStrings(map)); assertEquals(expected, toStrings(map));
} }
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.highlighter; package org.jetbrains.kotlin.idea.highlighter;
import com.google.common.base.Predicate;
import kotlin.Unit; import kotlin.Unit;
import kotlin.jvm.functions.Function1; import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -41,6 +40,7 @@ import org.jetbrains.kotlin.types.KotlinType;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
import static org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.RECEIVER_POSITION; import static org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.RECEIVER_POSITION;
import static org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.VALUE_PARAMETER_POSITION; import static org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.VALUE_PARAMETER_POSITION;
@@ -136,7 +136,7 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
String receiver = ""; String receiver = "";
if (hasReceiver) { if (hasReceiver) {
boolean error = false; boolean error = false;
if (isErrorPosition.apply(RECEIVER_POSITION.position())) { if (isErrorPosition.test(RECEIVER_POSITION.position())) {
error = true; error = true;
} }
receiver = "receiver: " + RenderersUtilKt.renderStrong(getTypeRenderer().render(receiverType, context), error); receiver = "receiver: " + RenderersUtilKt.renderStrong(getTypeRenderer().render(receiverType, context), error);
@@ -153,7 +153,7 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
for (Iterator<KotlinType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) { for (Iterator<KotlinType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) {
KotlinType argumentType = iterator.next(); KotlinType argumentType = iterator.next();
boolean error = false; boolean error = false;
if (isErrorPosition.apply(VALUE_PARAMETER_POSITION.position(i))) { if (isErrorPosition.test(VALUE_PARAMETER_POSITION.position(i))) {
error = true; error = true;
} }
String renderedArgument = argumentType == null ? "unknown" : getTypeRenderer().render(argumentType, context); String renderedArgument = argumentType == null ? "unknown" : getTypeRenderer().render(argumentType, context);
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.codeInsight.upDownMover; package org.jetbrains.kotlin.idea.codeInsight.upDownMover;
import com.google.common.base.Predicate;
import com.intellij.codeInsight.editorActions.moveUpDown.LineRange; import com.intellij.codeInsight.editorActions.moveUpDown.LineRange;
import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.Editor;
@@ -33,15 +32,11 @@ import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
import java.util.List; import java.util.List;
import java.util.function.Predicate;
public class KotlinExpressionMover extends AbstractKotlinUpDownMover { public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
private static final Predicate<KtElement> IS_CALL_EXPRESSION = new Predicate<KtElement>() { private static final Predicate<KtElement> IS_CALL_EXPRESSION = input -> input instanceof KtCallExpression;
@Override
public boolean apply(@Nullable KtElement input) {
return input instanceof KtCallExpression;
}
};
public KotlinExpressionMover() { public KotlinExpressionMover() {
} }
@@ -70,20 +65,12 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
private final static Class[] FUNCTIONLIKE_ELEMENT_CLASSES = private final static Class[] FUNCTIONLIKE_ELEMENT_CLASSES =
{KtFunction.class, KtPropertyAccessor.class, KtAnonymousInitializer.class}; {KtFunction.class, KtPropertyAccessor.class, KtAnonymousInitializer.class};
private static final Predicate<KtElement> CHECK_BLOCK_LIKE_ELEMENT = new Predicate<KtElement>() { private static final Predicate<KtElement> CHECK_BLOCK_LIKE_ELEMENT =
@Override input -> (input instanceof KtBlockExpression || input instanceof KtClassBody)
public boolean apply(@Nullable KtElement input) { && !PsiTreeUtil.instanceOf(input.getParent(), FUNCTIONLIKE_ELEMENT_CLASSES);
return (input instanceof KtBlockExpression || input instanceof KtClassBody)
&& !PsiTreeUtil.instanceOf(input.getParent(), FUNCTIONLIKE_ELEMENT_CLASSES);
}
};
private static final Predicate<KtElement> CHECK_BLOCK = new Predicate<KtElement>() { private static final Predicate<KtElement> CHECK_BLOCK =
@Override input -> input instanceof KtBlockExpression && !PsiTreeUtil.instanceOf(input.getParent(), FUNCTIONLIKE_ELEMENT_CLASSES);
public boolean apply(@Nullable KtElement input) {
return input instanceof KtBlockExpression && !PsiTreeUtil.instanceOf(input.getParent(), FUNCTIONLIKE_ELEMENT_CLASSES);
}
};
@Nullable @Nullable
private static PsiElement getStandaloneClosingBrace(@NotNull PsiFile file, @NotNull Editor editor) { private static PsiElement getStandaloneClosingBrace(@NotNull PsiFile file, @NotNull Editor editor) {
@@ -16,9 +16,6 @@
package org.jetbrains.kotlin.idea.framework.ui; package org.jetbrains.kotlin.idea.framework.ui;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.intellij.ide.util.projectWizard.ProjectWizardUtil; import com.intellij.ide.util.projectWizard.ProjectWizardUtil;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
@@ -28,6 +25,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PathUtil; import com.intellij.util.PathUtil;
import kotlin.collections.CollectionsKt;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -77,13 +75,8 @@ public class FileUIUtils {
targetFiles.put(file, new File(destinationPath, fileName)); targetFiles.put(file, new File(destinationPath, fileName));
} }
Collection<Map.Entry<File, File>> existentFiles = Collections2.filter(targetFiles.entrySet(), new Predicate<Map.Entry<File, File>>() { Collection<Map.Entry<File, File>> existentFiles =
@Override CollectionsKt.filter(targetFiles.entrySet(), sourceToTarget -> sourceToTarget.getValue().exists());
public boolean apply(@Nullable Map.Entry<File, File> sourceToTarget) {
assert sourceToTarget != null;
return sourceToTarget.getValue().exists();
}
});
if (!existentFiles.isEmpty()) { if (!existentFiles.isEmpty()) {
String message; String message;
@@ -94,13 +87,7 @@ public class FileUIUtils {
conflictingFile.getParentFile().getAbsolutePath()); conflictingFile.getParentFile().getAbsolutePath());
} }
else { else {
Collection<File> conflictFiles = Collections2.transform(existentFiles, new Function<Map.Entry<File, File>, File>() { Collection<File> conflictFiles = CollectionsKt.map(existentFiles, Map.Entry::getValue);
@Override
public File apply(@Nullable Map.Entry<File, File> pair) {
assert pair != null;
return pair.getValue();
}
});
message = String.format("Files already exist:\n%s\nDo you want to overwrite them?", StringUtil.join(conflictFiles, "\n")); message = String.format("Files already exist:\n%s\nDo you want to overwrite them?", StringUtil.join(conflictFiles, "\n"));
} }