replace some newArrayList() usages with immutable List/other methods

GitOrigin-RevId: 4f4c82378a960ba5be96e31cd19893f423fb6d33
This commit is contained in:
Alexey Kudravtsev
2023-01-24 17:12:20 +00:00
committed by intellij-monorepo-bot
parent 6ca9261998
commit 69278e8142
21 changed files with 48 additions and 52 deletions
@@ -18,7 +18,7 @@ public class CycleFinder<Node> {
}
@NotNull
public Set<List<Node>> getNodeCycles(final Node node) {
public Set<List<Node>> getNodeCycles(@NotNull Node node) {
final Set<List<Node>> result = new HashSet<>();
final Graph<Node> graphWithoutNode = new Graph<Node>() {
@@ -52,7 +52,7 @@ public class CycleFinder<Node> {
final Set<Node> retainNodes = new HashSet<>(inNodes);
retainNodes.retainAll(outNodes);
for (Node node1 : retainNodes) {
result.add(ContainerUtil.newArrayList(node1, node));
result.add(Arrays.asList(node1, node));
}
inNodes.removeAll(retainNodes);
outNodes.removeAll(retainNodes);
@@ -3,10 +3,11 @@ package com.intellij.openapi.extensions.impl;
import com.intellij.openapi.extensions.LoadingOrder;
import com.intellij.openapi.extensions.SortingException;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -18,7 +19,7 @@ public class LoadingOrderTest {
public void testSimpleSorting() {
assertSequence(
"1 Any Any 2",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.ANY, null, "Any"),
createElement(LoadingOrder.FIRST, null, "1"),
createElement(LoadingOrder.LAST, null, "2"),
@@ -31,7 +32,7 @@ public class LoadingOrderTest {
public void testStability() {
assertSequence(
"1 2 3 4",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.ANY, null, "1"),
createElement(LoadingOrder.ANY, null, "2"),
createElement(LoadingOrder.ANY, null, "3"),
@@ -47,7 +48,7 @@ public class LoadingOrderTest {
assertSequence(
"0 1 2 3 4 5",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.before(idTwo), idOne, "2"),
createElement(LoadingOrder.FIRST, null, "0"),
createElement(LoadingOrder.LAST, null, "5"),
@@ -64,7 +65,7 @@ public class LoadingOrderTest {
assertSequence(
"1 2 3 4 5 6",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.before(idOne), null, "2"),
createElement(LoadingOrder.after(idOne), null, "4"),
createElement(LoadingOrder.FIRST, null, "1"),
@@ -79,7 +80,7 @@ public class LoadingOrderTest {
public void testComplexSortingBeforeLast() {
assertSequence(
"3 4 2 1",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.LAST, "1", "1"),
createElement(LoadingOrder.readOrder("last,before 1"), null, "2"),
createElement(LoadingOrder.ANY, null, "3"),
@@ -91,7 +92,7 @@ public class LoadingOrderTest {
@Test
public void testFailingSortingBeforeFirst() {
checkSortingFailure(
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.ANY, null, "good"),
createElement(LoadingOrder.FIRST, "first", "bad"),
createElement(LoadingOrder.LAST, null, "good"),
@@ -105,7 +106,7 @@ public class LoadingOrderTest {
public void testFailingSortingFirst() {
assertSequence(
"1 1 2 3",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.ANY, null, "2"),
createElement(LoadingOrder.FIRST, "first", "1"),
createElement(LoadingOrder.LAST, null, "3"),
@@ -116,7 +117,7 @@ public class LoadingOrderTest {
@Test
public void testFailingSortingAfterLast() {
checkSortingFailure(
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.after("last"), null, "bad"),
createElement(LoadingOrder.FIRST, null, "good"),
createElement(LoadingOrder.LAST, "last", "bad"),
@@ -129,7 +130,7 @@ public class LoadingOrderTest {
public void testFailingSortingLast() {
assertSequence(
"1 2 3 3",
ContainerUtil.newArrayList(
Arrays.asList(
createElement(LoadingOrder.LAST, null, "3"),
createElement(LoadingOrder.FIRST, null, "1"),
createElement(LoadingOrder.LAST, "last", "3"),
@@ -140,11 +141,9 @@ public class LoadingOrderTest {
@Test
public void testFailingSortingComplex() {
checkSortingFailure(ContainerUtil.newArrayList(
createElement(LoadingOrder.after("2"), "1", "bad"),
createElement(LoadingOrder.after("3"), "2", "bad"),
createElement(LoadingOrder.after("1"), "3", "bad")
)
checkSortingFailure(new ArrayList<>(Arrays.asList(createElement(LoadingOrder.after("2"), "1", "bad"),
createElement(LoadingOrder.after("3"), "2", "bad"),
createElement(LoadingOrder.after("1"), "3", "bad")))
);
}
@@ -151,7 +151,7 @@ public final class FileTypeUsageCounterCollector extends CounterUsagesCollector
@NotNull VirtualFile file,
boolean withWritable) {
FileType fileType = file.getFileType();
List<EventPair<?>> data = ContainerUtil.newArrayList(
List<EventPair<?>> data = List.of(
EventFields.PluginInfoFromInstance.with(fileType),
EventFields.FileType.with(fileType),
EventFields.AnonymizedPath.with(file.getPath()),
@@ -159,7 +159,7 @@ public final class FileTypeUsageCounterCollector extends CounterUsagesCollector
);
if (withWritable) {
data.add(IS_WRITABLE.with(file.isWritable()));
data = ContainerUtil.append(data, IS_WRITABLE.with(file.isWritable()));
}
return data;
}
@@ -279,7 +279,7 @@ public final class ActionsTreeUtil {
ActionManager actionManager = ActionManager.getInstance();
String groupId = actionManager.getId(actionGroup);
Group group = new Group(groupName, groupId, actionGroup.getTemplatePresentation().getIcon());
List<AnAction> children = ContainerUtil.newArrayList(getActions(actionGroup, actionManager));
List<AnAction> children = new ArrayList<>(Arrays.asList(getActions(actionGroup, actionManager)));
for (ActionUrl actionUrl : actionUrls) {
Object component = actionUrl.getComponent();
@@ -256,8 +256,8 @@ public final class SwingHelper {
Object itemToSelect = comboBox.getSelectedItem();
boolean preserveSelection = true;
//noinspection SuspiciousMethodCalls
if (!newItems.contains(itemToSelect)) {
if (newItems.contains(newSelectedItemIfSelectionCannotBePreserved)) {
if (itemToSelect == null || !newItems.contains(itemToSelect)) {
if (newSelectedItemIfSelectionCannotBePreserved != null && newItems.contains(newSelectedItemIfSelectionCannotBePreserved)) {
itemToSelect = newSelectedItemIfSelectionCannotBePreserved;
}
else {
@@ -361,7 +361,9 @@ public final class AdvancedEnhancer extends AbstractClassGenerator
@NotNull
private List<Object> createKey() {
List<Object> tuple = ContainerUtil.newArrayList(Arrays.asList(callbackTypes), (useFactory ? 1 : 0) + (interceptDuringConstruction ? 2 : 0));
List<Object> tuple = new ArrayList<>();
tuple.add(Arrays.asList(callbackTypes));
tuple.add((useFactory ? 1 : 0) + (interceptDuringConstruction ? 2 : 0));
if (superclass != null) tuple.add(superclass.getName());
if (interfaces != null) {
tuple.addAll(ContainerUtil.map(interfaces, Class::getName));
@@ -193,13 +193,13 @@ public class StructureFilterPopupComponent
structureActions.add(new SelectFromHistoryAction(filter));
}
List<AnAction> actionsList = ContainerUtil.newArrayList(new EditPathsAction(), new SelectPathsInTreeAction(),
new Separator(VcsLogBundle.messagePointer("vcs.log.filter.recent")),
new DefaultActionGroup(structureActions));
List<AnAction> actionsList = new ArrayList<>(Arrays.asList(new EditPathsAction(), new SelectPathsInTreeAction(),
new Separator(VcsLogBundle.messagePointer("vcs.log.filter.recent")),
new DefaultActionGroup(structureActions)));
int position = roots.size() > 15 ? actionsList.size() : actionsList.size() - 2;
actionsList.addAll(position, List.of(new Separator(VcsLogBundle.messagePointer("vcs.log.filter.roots")),
new DefaultActionGroup(rootActions)));
new DefaultActionGroup(rootActions)));
return new DefaultActionGroup(actionsList);
}
@@ -339,8 +339,8 @@ public final class GitBranchIncomingOutgoingManager implements GitRepositoryChan
}
VcsFileUtil.chunkArguments(branchRefNames).forEach(refs -> {
List<String> params = ContainerUtil.newArrayList("--heads", remote.getName()); //NON-NLS
params.addAll(refs);
List<String> params = ContainerUtil.concat(List.of("--heads", remote.getName()), //NON-NLS
refs);
GitCommandResult lsRemoteResult =
Git.getInstance().runCommand(() -> createLsRemoteHandler(repository, remote, params, authenticationMode));
if (lsRemoteResult.success()) {
@@ -3,7 +3,6 @@ package git4idea.commands;
import com.intellij.externalProcessAuthHelper.ScriptGeneratorImpl;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
import externalApp.ExternalApp;
import externalApp.nativessh.NativeSshAskPassAppHandler;
import git4idea.config.GitExecutable;
@@ -37,7 +36,7 @@ public class GitScriptGenerator extends ScriptGeneratorImpl {
if (myExecutable instanceof GitExecutable.Wsl) {
// pass ENV variables from git to java command
StringBuilder sb = new StringBuilder();
List<String> envs = ContainerUtil.newArrayList(
List<String> envs = List.of(
NativeSshAskPassAppHandler.IJ_SSH_ASK_PASS_HANDLER_ENV,
NativeSshAskPassAppHandler.IJ_SSH_ASK_PASS_PORT_ENV,
GitAskPassAppHandler.IJ_ASK_PASS_HANDLER_ENV,
@@ -72,7 +72,7 @@ public final class GitLogUtil {
}
GitLineHandler handler = createGitHandler(project, root, configParameters, false);
List<GitLogParser.GitLogOption> options = ContainerUtil.newArrayList(HASH, PARENTS, COMMIT_TIME);
List<GitLogParser.GitLogOption> options = new ArrayList<>(Arrays.asList(HASH, PARENTS, COMMIT_TIME));
if (userConsumer != null) {
options.add(AUTHOR_NAME);
options.add(AUTHOR_EMAIL);
@@ -221,7 +221,7 @@ public class GitRefManager implements VcsLogRefManager {
VcsRef trackedRef = ContainerUtil.find(remoteBranches, ref -> ref.getName().equals(trackInfo.getRemoteBranch().getName()));
if (trackedRef != null) {
return new SimpleRefGroup(trackInfo.getRemote().getName() + REMOTE_TABLE_SEPARATOR + localRef.getName(),
ContainerUtil.newArrayList(localRef, trackedRef));
new ArrayList<>(Arrays.asList(localRef, trackedRef)));
}
}
@@ -230,7 +230,7 @@ public class GitRefManager implements VcsLogRefManager {
for (VcsRef candidate : trackingCandidates) {
if (candidate.getName().equals(remote.getName() + SEPARATOR + localRef.getName())) {
return new SimpleRefGroup(remote.getName() + REMOTE_TABLE_SEPARATOR + localRef.getName(),
ContainerUtil.newArrayList(localRef, candidate));
new ArrayList<>(Arrays.asList(localRef, candidate)));
}
}
}
@@ -479,7 +479,7 @@ public class GitPushTargetPanel extends PushTargetPanel<GitPushTarget> {
@NotNull
@Override
protected List<Component> getOrderedComponents() {
return ContainerUtil.newArrayList(myTargetEditor.getFocusTarget(), myRemoteRenderer);
return List.of(myTargetEditor.getFocusTarget(), myRemoteRenderer);
}
@Override
@@ -9,7 +9,6 @@ import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.DataInputOutputUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -35,7 +34,7 @@ public final class GrStubUtils {
public static final int GR_STUB_VERSION = 3;
public static void writeStringArray(@NotNull StubOutputStream dataStream, String @NotNull [] array) throws IOException {
writeSeq(dataStream, ContainerUtil.newArrayList(array), dataStream::writeName);
writeSeq(dataStream, Arrays.asList(array), dataStream::writeName);
}
public static String @NotNull [] readStringArray(@NotNull StubInputStream dataStream) throws IOException {
@@ -52,7 +52,7 @@ public class MapEntryOrKeyValueHintProcessor extends SignatureHintProcessor {
PsiType[] keyValueSignature = index ? new PsiType[]{key, value, PsiType.INT} : new PsiType[]{key, value};
PsiType[] mapEntrySignature = index ? new PsiType[]{mapEntryType, PsiType.INT} : new PsiType[]{mapEntryType};
return ContainerUtil.newArrayList(keyValueSignature, mapEntrySignature);
return List.of(keyValueSignature, mapEntrySignature);
}
private static int extractArgNum(String[] options) {
@@ -113,11 +113,11 @@ final class ForkedGroovyc implements GroovycFlavor {
}
private List<String> getProgramParams(File tempFile, JpsGroovySettings settings, boolean forStubs) {
List<String> programParams = ContainerUtil.newArrayList(myOptimizeClassLoading ? GroovyRtConstants.OPTIMIZE : "do_not_optimize",
List<String> programParams = List.of(myOptimizeClassLoading ? GroovyRtConstants.OPTIMIZE : "do_not_optimize",
forStubs ? "stubs" : "groovyc",
tempFile.getPath());
if (settings.invokeDynamic) {
programParams.add("--indy");
programParams = ContainerUtil.append(programParams, "--indy");
}
return programParams;
}
@@ -55,9 +55,8 @@ public class HgRebaseCommand {
@Nullable
private HgCommandResult performRebase(@NonNls String @NotNull ... args) {
try (AccessToken ignore = DvcsUtil.workingTreeChangeStarted(project, HgBundle.message("activity.name.rebase"))) {
final List<String> list = ContainerUtil.newArrayList(args);
list.add("--config");
list.add("extensions.rebase=");
final List<String> list = ContainerUtil.concat(List.of(args),
List.of("--config", "extensions.rebase="));
HgCommandResult result =
new HgCommandExecutor(project)
.executeInCurrentThread(repo.getRoot(), "rebase", list);
@@ -17,7 +17,6 @@ package org.zmlx.hg4idea.command.mq;
import com.intellij.openapi.progress.util.BackgroundTaskUtil;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.zmlx.hg4idea.HgBundle;
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
@@ -45,7 +44,7 @@ public class HgQImportCommand {
public void executeInCurrentThread(@NotNull final String startRevisionNumber) {
final Project project = myRepository.getProject();
String lastRevisionName = myRepository.getMQAppliedPatches().isEmpty() ? "tip" : "qparent";
List<String> arguments = ContainerUtil.newArrayList("--rev", startRevisionNumber + ":" + lastRevisionName);
List<String> arguments = List.of("--rev", startRevisionNumber + ":" + lastRevisionName);
HgCommandResult result = new HgCommandExecutor(project).executeInCurrentThread(myRepository.getRoot(), "qimport", arguments);
if (HgErrorUtil.hasErrorsInCommandExecution(result)) {
new HgCommandResultNotifier(project)
@@ -118,7 +118,7 @@ public abstract class HgBaseLogParser<CommitT> implements Function<String, Commi
if (!includeFiles) {
return ArrayUtilRt.toStringArray(templates);
}
List<String> fileTemplates = ContainerUtil.newArrayList("file_adds", "file_mods", "file_dels", "file_copies");
List<String> fileTemplates = List.of("file_adds", "file_mods", "file_dels", "file_copies");
templates.addAll(wrapIn(fileTemplates, currentVersion));
return ArrayUtilRt.toStringArray(templates);
}
@@ -10,7 +10,6 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.tasks.Task;
import com.intellij.tasks.impl.TaskUtil;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xmlb.annotations.XCollection;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
@@ -61,7 +60,7 @@ public abstract class SelectorBasedResponseHandler extends ResponseHandler {
protected SelectorBasedResponseHandler(GenericRepository repository) {
super(repository);
// standard selectors
setSelectors(ContainerUtil.newArrayList(
setSelectors(List.of(
// matched against list of tasks at whole downloaded from "taskListUrl"
new Selector(TASKS),
@@ -91,7 +90,7 @@ public abstract class SelectorBasedResponseHandler extends ResponseHandler {
return new ArrayList<>(mySelectors.values());
}
public void setSelectors(@NotNull List<Selector> selectors) {
public void setSelectors(@NotNull List<? extends Selector> selectors) {
mySelectors.clear();
for (Selector selector : selectors) {
mySelectors.put(selector.getName(), selector);
@@ -532,7 +532,7 @@ public final class PyPsiUtils {
public static void sequenceToList(List<? super PyExpression> result, PyExpression value) {
value = flattenParens(value);
if (value instanceof PySequenceExpression) {
result.addAll(ContainerUtil.newArrayList(((PySequenceExpression)value).getElements()));
ContainerUtil.addAll(result, ((PySequenceExpression)value).getElements());
}
else {
result.add(value);
@@ -137,8 +137,8 @@ public class PyClassTypeImpl extends UserDataHolderBase implements PyClassType {
boolean inherited) {
return RecursionManager.doPreventingRecursion(
resolveContext.allowProperties()
? ContainerUtil.newArrayList(this, name, location, direction, resolveContext)
: ContainerUtil.newArrayList(this, name, location, resolveContext),
? Arrays.asList(this, name, location, direction, resolveContext)
: Arrays.asList(this, name, location, resolveContext),
false,
() -> doResolveMember(name, location, direction, resolveContext, inherited)
);