diff options
author | Bruno Andrade <bruno@artsman.dev> | 2021-07-14 07:10:09 -0300 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-07-29 20:04:50 +0000 |
commit | 8eae78c9476d0d5dab0c6f51b2e72267916b2574 (patch) | |
tree | 722065a4aab58f7f3b83a8f28dc15d0988f5990b /server/sonar-webserver-webapi/src | |
parent | f827bdec3dd63f407ccba44fc5a8462528e0717f (diff) | |
download | sonarqube-8eae78c9476d0d5dab0c6f51b2e72267916b2574.tar.gz sonarqube-8eae78c9476d0d5dab0c6f51b2e72267916b2574.zip |
Code smell fix: Replacing ImmutableList from List
Diffstat (limited to 'server/sonar-webserver-webapi/src')
10 files changed, 22 insertions, 38 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 855d248205b..d5c8e3aaa90 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -72,7 +72,6 @@ import org.sonarqube.ws.Components.SearchProjectsWsResponse; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.collect.ImmutableList.of; import static com.google.common.collect.Sets.newHashSet; import static java.util.Collections.emptyMap; import static java.util.Objects.requireNonNull; @@ -95,7 +94,6 @@ import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUA import static org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS; public class SearchProjectsAction implements ComponentsWsAction { - public static final int MAX_PAGE_SIZE = 500; public static final int DEFAULT_PAGE_SIZE = 100; private static final String ALL = "_all"; @@ -368,7 +366,7 @@ public class SearchProjectsAction implements ComponentsWsAction { if (httpRequest.hasParam(FIELDS)) { List<String> paramsAsString = httpRequest.mandatoryParamAsStrings(FIELDS); if (paramsAsString.contains(ALL)) { - request.setAdditionalFields(of(ANALYSIS_DATE, LEAK_PERIOD_DATE)); + request.setAdditionalFields(List.of(ANALYSIS_DATE, LEAK_PERIOD_DATE)); } else { request.setAdditionalFields(paramsAsString); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java index 0fb20222fe8..63fcd54367c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/hotspot/ws/SearchAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.hotspot.ws; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.Collection; @@ -109,7 +108,7 @@ public class SearchAction implements HotspotsWsAction { private static final String PARAM_CWE = "cwe"; private static final String PARAM_FILES = "files"; - private static final List<String> STATUSES = ImmutableList.of(STATUS_TO_REVIEW, STATUS_REVIEWED); + private static final List<String> STATUSES = List.of(STATUS_TO_REVIEW, STATUS_REVIEWED); private final DbClient dbClient; private final UserSession userSession; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java index a46a82e7920..c2a6b868d37 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/IssueChangeWSSupport.java @@ -20,7 +20,6 @@ package org.sonar.server.issue; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.common.collect.Ordering; @@ -105,8 +104,8 @@ public class IssueChangeWSSupport { Set<UserDto> preloadedUsers, Set<ComponentDto> preloadedComponents) { Set<String> issueKeys = dtos.stream().map(IssueDto::getKey).collect(toSet()); - List<IssueChangeDto> changes = ImmutableList.of(); - List<IssueChangeDto> comments = ImmutableList.of(); + List<IssueChangeDto> changes = List.of(); + List<IssueChangeDto> comments = List.of(); switch (load) { case CHANGE_LOG: changes = dbClient.issueChangeDao().selectByTypeAndIssueKeys(dbSession, issueKeys, TYPE_FIELD_CHANGE); @@ -316,18 +315,18 @@ public class IssueChangeWSSupport { public List<FieldDiffs> getChanges(IssueDto dto) { List<FieldDiffs> fieldDiffs = changesByIssueKey.get(dto.getKey()); if (fieldDiffs == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.copyOf(fieldDiffs); + return List.copyOf(fieldDiffs); } @Override public List<IssueChangeDto> getComments(IssueDto dto) { List<IssueChangeDto> comments = commentsByIssueKey.get(dto.getKey()); if (comments == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.copyOf(comments); + return List.copyOf(comments); } @Override diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java index a41aa0c7943..26b5bbc97a2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.issue.ws; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Arrays; @@ -131,12 +130,11 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_TIMEZONE; import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_TYPES; public class SearchAction implements IssuesWsAction { - private static final String LOGIN_MYSELF = "__me__"; private static final Set<String> ISSUE_SCOPES = Arrays.stream(IssueScope.values()).map(Enum::name).collect(Collectors.toSet()); private static final EnumSet<RuleType> ALL_RULE_TYPES_EXCEPT_SECURITY_HOTSPOTS = EnumSet.complementOf(EnumSet.of(RuleType.SECURITY_HOTSPOT)); - static final List<String> SUPPORTED_FACETS = ImmutableList.of( + static final List<String> SUPPORTED_FACETS = List.of( FACET_PROJECTS, PARAM_MODULE_UUIDS, PARAM_FILES, @@ -157,7 +155,8 @@ public class SearchAction implements IssuesWsAction { PARAM_SANS_TOP_25, PARAM_CWE, PARAM_CREATED_AT, - PARAM_SONARSOURCE_SECURITY); + PARAM_SONARSOURCE_SECURITY + ); private static final String INTERNAL_PARAMETER_DISCLAIMER = "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter. "; private static final Set<String> FACETS_REQUIRING_PROJECT = newHashSet(PARAM_MODULE_UUIDS, PARAM_FILES, PARAM_DIRECTORIES); @@ -422,7 +421,7 @@ public class SearchAction implements IssuesWsAction { collectFacets(collector, facets); } SearchResponseData preloadedData = new SearchResponseData(emptyList()); - preloadedData.addRules(ImmutableList.copyOf(query.rules())); + preloadedData.addRules(List.copyOf(query.rules())); SearchResponseData data = searchResponseLoader.load(preloadedData, collector, additionalFields, facets); // FIXME allow long in Paging @@ -588,7 +587,7 @@ public class SearchAction implements IssuesWsAction { List<String> assigneeUuid = userDtos.stream().map(UserDto::getUuid).collect(toList()); if ((assigneeLogins != null) && firstNonNull(assigneeUuid, emptyList()).isEmpty()) { - assigneeUuid = ImmutableList.of("non-existent-uuid"); + assigneeUuid = List.of("non-existent-uuid"); } return assigneeUuid; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java index 8c1d215855c..b7954a53ea1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseData.java @@ -20,7 +20,6 @@ package org.sonar.server.issue.ws; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ListMultimap; import java.util.ArrayList; import java.util.Collection; @@ -44,7 +43,6 @@ import static com.google.common.base.Preconditions.checkNotNull; * All the data required to write response of api/issues/search */ public class SearchResponseData { - private final List<IssueDto> issues; private Long effortTotal = null; @@ -58,7 +56,7 @@ public class SearchResponseData { public SearchResponseData(IssueDto issue) { checkNotNull(issue); - this.issues = ImmutableList.of(issue); + this.issues = List.of(issue); } public SearchResponseData(List<IssueDto> issues) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java index f90ebb93d18..6cac5bdbcea 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/AddGroupAction.java @@ -19,7 +19,7 @@ */ package org.sonar.server.permission.ws; -import com.google.common.collect.ImmutableList; +import java.util.List; import java.util.Optional; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; @@ -41,7 +41,6 @@ import static org.sonar.server.permission.ws.WsParameters.createProjectParameter import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION; public class AddGroupAction implements PermissionsWsAction { - public static final String ACTION = "add_group"; private final DbClient dbClient; @@ -95,9 +94,8 @@ public class AddGroupAction implements PermissionsWsAction { request.mandatoryParam(PARAM_PERMISSION), project.orElse(null), group, permissionService); - permissionUpdater.apply(dbSession, ImmutableList.of(change)); + permissionUpdater.apply(dbSession, List.of(change)); } response.noContent(); } - } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java index cd5888e2e7e..e8b9af6f62b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java @@ -19,8 +19,8 @@ */ package org.sonar.server.rule.ws; -import com.google.common.collect.ImmutableList; import java.util.Date; +import java.util.List; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; @@ -56,7 +56,6 @@ import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_TYPES; @ServerSide public class RuleQueryFactory { - private final DbClient dbClient; public RuleQueryFactory(DbClient dbClient) { @@ -90,7 +89,7 @@ public class RuleQueryFactory { setProfile(dbSession, query, request); setCompareToProfile(dbSession, query, request); QProfileDto profile = query.getQProfile(); - query.setLanguages(profile == null ? request.paramAsStrings(PARAM_LANGUAGES) : ImmutableList.of(profile.getLanguage())); + query.setLanguages(profile == null ? request.paramAsStrings(PARAM_LANGUAGES) : List.of(profile.getLanguage())); query.setActivation(request.paramAsBoolean(PARAM_ACTIVATION)); query.setTags(request.paramAsStrings(PARAM_TAGS)); query.setInheritance(request.paramAsStrings(PARAM_INHERITANCE)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java index e09641b88d2..3ba655bb2ff 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ResetAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.setting.ws; -import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -50,7 +49,6 @@ import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; public class ResetAction implements SettingsWsAction { - private final DbClient dbClient; private final ComponentFinder componentFinder; private final SettingsUpdater settingsUpdater; @@ -114,7 +112,7 @@ public class ResetAction implements SettingsWsAction { resetRequest.getKeys().forEach(key -> { SettingsWsSupport.validateKey(key); SettingData data = new SettingData(key, emptyList(), component.orElse(null)); - ImmutableList.of(validations.scope(), validations.qualifier()) + List.of(validations.scope(), validations.qualifier()) .forEach(validation -> validation.accept(data)); }); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java index a0a346b911c..bfa2f5d524c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java @@ -20,7 +20,6 @@ package org.sonar.server.setting.ws; import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ListMultimap; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; @@ -205,7 +204,7 @@ public class SetAction implements SettingsWsAction { checkValueIsSet(request); String settingKey = request.getKey(); SettingData settingData = new SettingData(settingKey, valuesFromRequest(request), component.orElse(null)); - ImmutableList.of(validations.scope(), validations.qualifier(), validations.valueType()) + List.of(validations.scope(), validations.qualifier(), validations.valueType()) .forEach(validation -> validation.accept(settingData)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java index 1cad70a35b4..e55ee0da620 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/text/MacroInterpreter.java @@ -19,7 +19,6 @@ */ package org.sonar.server.text; -import com.google.common.collect.ImmutableList; import org.sonar.api.server.ServerSide; import org.sonar.api.platform.Server; @@ -27,13 +26,12 @@ import java.util.List; @ServerSide public class MacroInterpreter { - private final List<Macro> macros; public MacroInterpreter(Server server) { - this.macros = ImmutableList.of( + this.macros = List.of( new RuleMacro(server.getContextPath()) - ); + ); } public String interpret(String text) { @@ -43,5 +41,4 @@ public class MacroInterpreter { } return textReplaced; } - } |