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