mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Stream API call chains simplified
This commit is contained in:
+1
-3
@@ -44,9 +44,7 @@ public final class MethodChainsSearchUtil {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.sorted(Comparator.comparing(MethodChainsSearchUtil::getNonPrimitiveParameterCount))
|
||||
.findFirst().orElse(null);
|
||||
}).min(Comparator.comparing(MethodChainsSearchUtil::getNonPrimitiveParameterCount)).orElse(null);
|
||||
}
|
||||
|
||||
private static int getNonPrimitiveParameterCount(PsiMethod method) {
|
||||
|
||||
+1
-2
@@ -48,8 +48,7 @@ public class ChainCompletionNewVariableLookupElement extends LookupElement {
|
||||
VariableKind variableKind = myField ? VariableKind.FIELD : VariableKind.LOCAL_VARIABLE;
|
||||
myNewVarName = Stream
|
||||
.of(codeStyleManager.suggestVariableName(variableKind, null, null, elementFactory.createType(qualifierClass)).names)
|
||||
.sorted(Comparator.comparing(String::length).reversed())
|
||||
.findFirst()
|
||||
.max(Comparator.comparing(String::length))
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
myQualifierClass = qualifierClass;
|
||||
putUserData(PreferByKindWeigher.INTRODUCED_VARIABLE, Boolean.TRUE);
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
final List<OrderRoot> result = new ArrayList<>();
|
||||
final Library[] libraries = moduleLibrariesModel.getLibraries();
|
||||
for (OrderRoot root : roots) {
|
||||
if (!Arrays.stream(libraries).anyMatch(library -> contains(root.getFile(), library.getFiles(root.getType())))) {
|
||||
if (Arrays.stream(libraries).noneMatch(library -> contains(root.getFile(), library.getFiles(root.getType())))) {
|
||||
result.add(root);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -791,7 +791,7 @@ public class MagicConstantInspection extends AbstractBaseJavaLocalInspectionTool
|
||||
@NotNull PsiFile file,
|
||||
@NotNull PsiElement startElement,
|
||||
@NotNull PsiElement endElement) {
|
||||
boolean allValid = !myMemberValuePointers.stream().map(SmartPsiElementPointer::getElement).anyMatch(p -> p == null || !p.isValid());
|
||||
boolean allValid = myMemberValuePointers.stream().map(SmartPsiElementPointer::getElement).allMatch(p -> p != null && p.isValid());
|
||||
return allValid && super.isAvailable(project, file, startElement, endElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public abstract class VcsLogAction<Repo extends Repository> extends DumbAwareAct
|
||||
|
||||
protected boolean isVisible(@NotNull Project project, @NotNull MultiMap<Repo, Hash> grouped) {
|
||||
RepositoryManager<Repo> manager = getRepositoryManager(project);
|
||||
return grouped.keySet().stream().allMatch(repo -> !manager.isExternal(repo));
|
||||
return grouped.keySet().stream().noneMatch(manager::isExternal);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -22,13 +22,17 @@ package com.intellij.util;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class AlarmTest extends PlatformTestCase {
|
||||
public void testTwoAddsWithZeroDelayMustExecuteSequentially() throws Exception {
|
||||
@@ -103,7 +107,7 @@ public class AlarmTest extends PlatformTestCase {
|
||||
Map<Thread, StackTraceElement[]> before = Thread.getAllStackTraces();
|
||||
AtomicInteger executed = new AtomicInteger();
|
||||
int N = 100000;
|
||||
List<Alarm> alarms = Collections.nCopies(N, "").stream().map(__ -> new Alarm(getTestRootDisposable())).collect(Collectors.toList());
|
||||
List<Alarm> alarms = Stream.generate(() -> new Alarm(getTestRootDisposable())).limit(N).collect(Collectors.toList());
|
||||
alarms.forEach(alarm -> alarm.addRequest(executed::incrementAndGet, 10));
|
||||
|
||||
while (executed.get() != N) {
|
||||
|
||||
+3
-7
@@ -19,15 +19,11 @@ import com.jetbrains.python.psi.impl.PyPsiUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.patterns.PlatformPatterns.psiElement;
|
||||
import static com.intellij.patterns.StandardPatterns.or;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class PyStringFormatCompletionContributor extends CompletionContributor {
|
||||
private static final String DICT_NAME = "dict";
|
||||
@@ -253,7 +249,7 @@ public class PyStringFormatCompletionContributor extends CompletionContributor {
|
||||
final PyExpression callee = callExpression.getCallee();
|
||||
if (callee != null && callee.getName() != null && callee.getName().equals(DICT_NAME)) {
|
||||
final PyExpression[] arguments = callExpression.getArguments();
|
||||
return asList(arguments).stream()
|
||||
return Arrays.stream(arguments)
|
||||
.filter(a -> a instanceof PyKeywordArgument)
|
||||
.map(a -> getKeywordArgument((PyKeywordArgument)a))
|
||||
.filter(e -> e != null)
|
||||
@@ -306,7 +302,7 @@ public class PyStringFormatCompletionContributor extends CompletionContributor {
|
||||
|
||||
@NotNull
|
||||
private static List<LookupElement> getElementsFromDict(@NotNull final PyDictLiteralExpression dict) {
|
||||
return asList(dict.getElements()).stream()
|
||||
return Arrays.stream(dict.getElements())
|
||||
.map(e -> PyUtil.as(e.getKey(), PyStringLiteralExpression.class))
|
||||
.filter(k-> k != null)
|
||||
.map(k -> createLookUpElement(k.getStringValue()))
|
||||
|
||||
@@ -105,9 +105,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
|
||||
return cls.getAncestorClasses(context)
|
||||
.stream()
|
||||
.filter(baseClass -> PyBroadExceptionInspection.equalsException(baseClass, context))
|
||||
.findAny()
|
||||
.isPresent();
|
||||
.anyMatch(baseClass -> PyBroadExceptionInspection.equalsException(baseClass, context));
|
||||
}
|
||||
|
||||
private static boolean hasConstructorCall(@NotNull PyClass cls, @NotNull PyFunction initMethod, @NotNull TypeEvalContext context) {
|
||||
@@ -189,9 +187,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
return cls.getAncestorClasses(context)
|
||||
.stream()
|
||||
.map(PyClass::getName)
|
||||
.filter(firstArg::equals)
|
||||
.findAny()
|
||||
.isPresent();
|
||||
.anyMatch(firstArg::equals);
|
||||
}
|
||||
|
||||
private static boolean isSuperClassCall(@NotNull PyExpression calleeQualifier,
|
||||
@@ -202,9 +198,7 @@ public class PyMissingConstructorInspection extends PyInspection {
|
||||
return callingClass != null &&
|
||||
cls.getAncestorClasses(context)
|
||||
.stream()
|
||||
.filter(callingClass::equals)
|
||||
.findAny()
|
||||
.isPresent();
|
||||
.anyMatch(callingClass::equals);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ public final class PyExtractSuperclassHelper {
|
||||
* If class explicitly extends object we shall move it even in Py3K
|
||||
*/
|
||||
private static boolean isObjectParentDeclaredExplicitly(@NotNull final PyClass clazz) {
|
||||
return Arrays.stream(clazz.getSuperClassExpressions()).filter(o -> PyNames.OBJECT.equals(o.getName())).findFirst().isPresent();
|
||||
return Arrays.stream(clazz.getSuperClassExpressions()).anyMatch(o -> PyNames.OBJECT.equals(o.getName()));
|
||||
}
|
||||
|
||||
private static PyClass placeNewClass(final Project project, PyClass newClass, @NotNull final PyClass clazz, final String targetFile) {
|
||||
@@ -161,7 +161,7 @@ public final class PyExtractSuperclassHelper {
|
||||
psiFile.add(PyElementGenerator.getInstance(project).createFromText(LanguageLevel.PYTHON24, PsiWhiteSpace.class, "\n\n"));
|
||||
}
|
||||
newClass = (PyClass)psiFile.add(newClass);
|
||||
PyClassRefactoringUtil.insertImport(clazz, Collections.singleton((PsiNamedElement)newClass));
|
||||
PyClassRefactoringUtil.insertImport(clazz, Collections.singleton(newClass));
|
||||
return newClass;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class PythonSpellcheckerStrategy extends SpellcheckingStrategy {
|
||||
final List<ASTNode> strNodes = element.getStringNodes();
|
||||
final List<String> prefixes = ContainerUtil.mapNotNull(strNodes, n -> StringUtil.nullize(new StringNodeInfo(n).getPrefix()));
|
||||
|
||||
if (element.textContains('\\') && !prefixes.stream().anyMatch(PyStringLiteralUtil::isRawPrefix)) {
|
||||
if (element.textContains('\\') && prefixes.stream().noneMatch(PyStringLiteralUtil::isRawPrefix)) {
|
||||
for (Pair<TextRange, String> fragment : element.getDecodedFragments()) {
|
||||
final String value = fragment.getSecond();
|
||||
final int startOffset = fragment.getFirst().getStartOffset();
|
||||
|
||||
Reference in New Issue
Block a user