aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api-impl
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-12-04 12:50:58 +0100
committersonartech <sonartech@sonarsource.com>2023-12-04 20:03:22 +0000
commitd62a56ecfd4cf2f183873900fd32cffc4743c7fb (patch)
tree552481ceb8b8cab34f74b59563b58278ffa62f69 /sonar-plugin-api-impl
parentcdda3dbcdd4e4b5f4a2e7471a37fa66877e26aad (diff)
downloadsonarqube-d62a56ecfd4cf2f183873900fd32cffc4743c7fb.tar.gz
sonarqube-d62a56ecfd4cf2f183873900fd32cffc4743c7fb.zip
SONAR-21174 Fix code smells raised after dropping JDK11 support
Diffstat (limited to 'sonar-plugin-api-impl')
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/AndPredicate.java8
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OptimizedFilePredicateAdapter.java4
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OrPredicate.java4
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRules.java2
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java13
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Settings.java2
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java3
-rw-r--r--sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/ValidatingRequest.java5
8 files changed, 17 insertions, 24 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/AndPredicate.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/AndPredicate.java
index 4df4e05a72c..2239f686637 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/AndPredicate.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/AndPredicate.java
@@ -27,8 +27,6 @@ import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;
-import static java.util.stream.Collectors.toList;
-
/**
* @since 4.2
*/
@@ -49,8 +47,8 @@ class AndPredicate extends AbstractFilePredicate implements OperatorPredicate {
continue;
} else if (filePredicate == FalsePredicate.FALSE) {
return FalsePredicate.FALSE;
- } else if (filePredicate instanceof AndPredicate) {
- result.predicates.addAll(((AndPredicate) filePredicate).predicates);
+ } else if (filePredicate instanceof AndPredicate andPredicate) {
+ result.predicates.addAll(andPredicate.predicates);
} else {
result.predicates.add(OptimizedFilePredicateAdapter.create(filePredicate));
}
@@ -97,7 +95,7 @@ class AndPredicate extends AbstractFilePredicate implements OperatorPredicate {
@Override
public List<FilePredicate> operands() {
- return predicates.stream().map(p -> (FilePredicate) p).collect(toList());
+ return predicates.stream().map(p -> (FilePredicate) p).toList();
}
}
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OptimizedFilePredicateAdapter.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OptimizedFilePredicateAdapter.java
index 01da55d7730..6ea67e615a1 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OptimizedFilePredicateAdapter.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OptimizedFilePredicateAdapter.java
@@ -36,8 +36,8 @@ public class OptimizedFilePredicateAdapter extends AbstractFilePredicate {
}
public static OptimizedFilePredicate create(FilePredicate predicate) {
- if (predicate instanceof OptimizedFilePredicate) {
- return (OptimizedFilePredicate) predicate;
+ if (predicate instanceof OptimizedFilePredicate optimizedFilePredicate) {
+ return optimizedFilePredicate;
} else {
return new OptimizedFilePredicateAdapter(predicate);
}
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OrPredicate.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OrPredicate.java
index c9ab3ad5b40..3c3817c33f1 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OrPredicate.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/fs/internal/predicates/OrPredicate.java
@@ -45,8 +45,8 @@ class OrPredicate extends AbstractFilePredicate implements OperatorPredicate {
return TruePredicate.TRUE;
} else if (filePredicate == FalsePredicate.FALSE) {
continue;
- } else if (filePredicate instanceof OrPredicate) {
- result.predicates.addAll(((OrPredicate) filePredicate).predicates);
+ } else if (filePredicate instanceof OrPredicate orPredicate) {
+ result.predicates.addAll(orPredicate.predicates);
} else {
result.predicates.add(filePredicate);
}
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRules.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRules.java
index efac94ac794..60c2722c989 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRules.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRules.java
@@ -79,7 +79,7 @@ public class DefaultActiveRules implements ActiveRules {
@Override
public Collection<ActiveRule> findAll() {
- return activeRulesByRepository.entrySet().stream().flatMap(x -> x.getValue().stream()).collect(Collectors.toList());
+ return activeRulesByRepository.entrySet().stream().flatMap(x -> x.getValue().stream()).toList();
}
@Override
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
index 5218d874c36..cea5d4686c4 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/AbstractDefaultIssue.java
@@ -25,7 +25,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
-import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.internal.DefaultInputDir;
@@ -97,12 +96,10 @@ public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> exten
InputComponent component = location.inputComponent();
Optional<Path> dirOrModulePath = Optional.empty();
- if (component instanceof DefaultInputDir) {
- DefaultInputDir dirComponent = (DefaultInputDir) component;
- dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path()));
- } else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) {
- DefaultInputModule moduleComponent = (DefaultInputModule) component;
- dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir()));
+ if (component instanceof DefaultInputDir defaultInputDir) {
+ dirOrModulePath = Optional.of(project.getBaseDir().relativize(defaultInputDir.path()));
+ } else if (component instanceof DefaultInputModule defaultInputModule && !Objects.equals(project.key(), component.key())) {
+ dirOrModulePath = Optional.of(project.getBaseDir().relativize(defaultInputModule.getBaseDir()));
}
if (dirOrModulePath.isPresent()) {
@@ -122,7 +119,7 @@ public abstract class AbstractDefaultIssue<T extends AbstractDefaultIssue> exten
List<NewMessageFormatting> paddedFormattings = location.messageFormattings().stream()
.map(m -> padMessageFormatting(m, prefixMessage.length()))
- .collect(Collectors.toList());
+ .toList();
fixedLocation.message(fullMessage.toString(), paddedFormattings);
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Settings.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Settings.java
index bedda5549dc..45f084a2a24 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Settings.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Settings.java
@@ -457,7 +457,7 @@ public abstract class Settings extends org.sonar.api.config.Settings {
public List<String> getKeysStartingWith(String prefix) {
return getProperties().keySet().stream()
.filter(key -> StringUtils.startsWith(key, prefix))
- .collect(Collectors.toList());
+ .toList();
}
}
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java
index 6c5df649c61..2e6d7cce1c0 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java
@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.io.IOUtils;
@@ -91,7 +90,7 @@ public class SimpleGetRequest extends Request {
return null;
}
- return Arrays.stream(value.split(",")).map(String::trim).filter(x -> !x.isEmpty()).collect(Collectors.toList());
+ return Arrays.stream(value.split(",")).map(String::trim).filter(x -> !x.isEmpty()).toList();
}
@Override
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/ValidatingRequest.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/ValidatingRequest.java
index af00beb1ef0..7505018c5cf 100644
--- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/ValidatingRequest.java
+++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/ValidatingRequest.java
@@ -23,7 +23,6 @@ import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
-import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.server.ws.LocalConnector;
@@ -132,7 +131,7 @@ public abstract class ValidatingRequest extends Request {
List<String> values = Arrays.stream(value.split(COMMA_SPLITTER))
.map(String::trim)
.filter(s -> !s.isEmpty())
- .collect(Collectors.toList());
+ .toList();
return validateValues(values, definition);
}
@@ -146,7 +145,7 @@ public abstract class ValidatingRequest extends Request {
return values.stream()
.filter(s -> !s.isEmpty())
.map(value -> Enum.valueOf(enumClass, value))
- .collect(Collectors.toList());
+ .toList();
}
@CheckForNull