diff --git a/platforms/core-configuration/model-core/build.gradle.kts b/platforms/core-configuration/model-core/build.gradle.kts index d4ca14230515..6d5b616716f0 100644 --- a/platforms/core-configuration/model-core/build.gradle.kts +++ b/platforms/core-configuration/model-core/build.gradle.kts @@ -23,8 +23,6 @@ errorprone { "StringCaseLocaleUsage", // 13 occurrences "TypeParameterShadowing", // 2 occurrences "UndefinedEquals", // 2 occurrences - "UnnecessaryLambda", // 1 occurrences - "UnnecessaryParentheses", // 1 occurrences "UnnecessaryStringBuilder", // 1 occurrences "UnusedMethod", // 8 occurrences "UnusedTypeParameter", // 1 occurrences diff --git a/platforms/core-configuration/model-core/src/main/java/org/gradle/api/internal/model/NamedObjectInstantiator.java b/platforms/core-configuration/model-core/src/main/java/org/gradle/api/internal/model/NamedObjectInstantiator.java index 0755f987398c..f6129c4d606a 100644 --- a/platforms/core-configuration/model-core/src/main/java/org/gradle/api/internal/model/NamedObjectInstantiator.java +++ b/platforms/core-configuration/model-core/src/main/java/org/gradle/api/internal/model/NamedObjectInstantiator.java @@ -76,7 +76,7 @@ public class NamedObjectInstantiator implements ManagedFactory { private final CrossBuildInMemoryCache, LoadingCache> generatedTypes; private final String implSuffix; private final String factorySuffix; - private final Function, LoadingCache> cacheFactory = type -> CacheBuilder.newBuilder().build(loaderFor(type)); + private final Function, LoadingCache> cacheFactoryFunction = this::cacheFactory; public NamedObjectInstantiator(CrossBuildInMemoryCacheFactory cacheFactory) { implSuffix = ClassGeneratorSuffixRegistry.assign("$Impl"); @@ -98,7 +98,7 @@ public T fromState(Class type, Object state) { public T named(final Class type, final String name) throws ObjectInstantiationException { try { - return type.cast(generatedTypes.get(type, cacheFactory).getUnchecked(name)); + return type.cast(generatedTypes.get(type, cacheFactoryFunction).getUnchecked(name)); } catch (UncheckedExecutionException e) { throw new ObjectInstantiationException(type, e.getCause()); } catch (Exception e) { @@ -282,6 +282,10 @@ private void visitFields(Class type, ValidationProblemCollector collector) { } } + private LoadingCache cacheFactory(Class type) { + return CacheBuilder.newBuilder().build(loaderFor(type)); + } + protected abstract static class ClassGeneratingLoader extends CacheLoader { @Override public abstract Object load(String name); diff --git a/platforms/core-configuration/model-core/src/main/java/org/gradle/model/internal/registry/DefaultModelRegistry.java b/platforms/core-configuration/model-core/src/main/java/org/gradle/model/internal/registry/DefaultModelRegistry.java index af8470b47583..0d224c2092c2 100644 --- a/platforms/core-configuration/model-core/src/main/java/org/gradle/model/internal/registry/DefaultModelRegistry.java +++ b/platforms/core-configuration/model-core/src/main/java/org/gradle/model/internal/registry/DefaultModelRegistry.java @@ -1071,7 +1071,7 @@ public boolean isAchieved() { return false; } for (ModelNodeInternal child : node.getLinks()) { - if (child.isAtLeast(Discovered) && (child.getPromise().canBeViewedAs(typeToBind))) { + if (child.isAtLeast(Discovered) && child.getPromise().canBeViewedAs(typeToBind)) { return true; } } diff --git a/platforms/core-configuration/model-groovy/build.gradle.kts b/platforms/core-configuration/model-groovy/build.gradle.kts index 0704782b83d6..857c7778bb9a 100644 --- a/platforms/core-configuration/model-groovy/build.gradle.kts +++ b/platforms/core-configuration/model-groovy/build.gradle.kts @@ -4,12 +4,6 @@ plugins { description = "Groovy specific adaptations to the model management." -errorprone { - disabledChecks.addAll( - "UnnecessaryParentheses", // 1 occurrences - ) -} - dependencies { api(project(":base-services")) api(project(":model-core")) diff --git a/platforms/core-configuration/model-groovy/src/main/java/org/gradle/model/dsl/internal/transform/RuleVisitor.java b/platforms/core-configuration/model-groovy/src/main/java/org/gradle/model/dsl/internal/transform/RuleVisitor.java index b2d0e7dee4fa..b3c081ccb0d3 100644 --- a/platforms/core-configuration/model-groovy/src/main/java/org/gradle/model/dsl/internal/transform/RuleVisitor.java +++ b/platforms/core-configuration/model-groovy/src/main/java/org/gradle/model/dsl/internal/transform/RuleVisitor.java @@ -169,7 +169,7 @@ public void visitRuleClosure(ClosureExpression expression, Expression invocation VariableExpression parentInputsVariable = inputsVariable; try { inputs = new InputReferences(); - inputsVariable = new VariableExpression("__rule_inputs_var_" + (counter++), POTENTIAL_INPUTS); + inputsVariable = new VariableExpression("__rule_inputs_var_" + counter++, POTENTIAL_INPUTS); inputsVariable.setClosureSharedVariable(true); super.visitClosureExpression(expression); BlockStatement code = (BlockStatement) expression.getCode(); diff --git a/platforms/core-runtime/base-services/build.gradle.kts b/platforms/core-runtime/base-services/build.gradle.kts index 1dc69e6da419..cca2e65b7ea5 100644 --- a/platforms/core-runtime/base-services/build.gradle.kts +++ b/platforms/core-runtime/base-services/build.gradle.kts @@ -42,7 +42,6 @@ errorprone { "ThreadLocalUsage", // 4 occurrences "TypeParameterUnusedInFormals", // 5 occurrences "URLEqualsHashCode", // 1 occurrences - "UnnecessaryParentheses", // 2 occurrences "UnsynchronizedOverridesSynchronized", // 2 occurrences "UnusedMethod", // 2 occurrences "UnusedVariable", // 3 occurrences diff --git a/platforms/core-runtime/base-services/src/main/java/org/gradle/util/internal/GUtil.java b/platforms/core-runtime/base-services/src/main/java/org/gradle/util/internal/GUtil.java index 9d95ebe98c8a..e7e3a290a7ba 100644 --- a/platforms/core-runtime/base-services/src/main/java/org/gradle/util/internal/GUtil.java +++ b/platforms/core-runtime/base-services/src/main/java/org/gradle/util/internal/GUtil.java @@ -87,10 +87,10 @@ public static > T flatten(Collection elements, T addT flatten((Collection) element, addTo, flattenMaps, flattenArrays); } else if ((element instanceof Map) && flattenMaps) { flatten(((Map) element).values(), addTo, flattenMaps, flattenArrays); - } else if ((element.getClass().isArray()) && flattenArrays) { + } else if (element.getClass().isArray() && flattenArrays) { flatten(asList((Object[]) element), addTo, flattenMaps, flattenArrays); } else { - (Cast.>uncheckedNonnullCast(addTo)).add(element); + Cast.>uncheckedNonnullCast(addTo).add(element); } } return addTo; diff --git a/platforms/core-runtime/build-profile/build.gradle.kts b/platforms/core-runtime/build-profile/build.gradle.kts index a6901b5fabf7..e3e97f2bf031 100644 --- a/platforms/core-runtime/build-profile/build.gradle.kts +++ b/platforms/core-runtime/build-profile/build.gradle.kts @@ -8,7 +8,6 @@ errorprone { disabledChecks.addAll( "DateFormatConstant", // 2 occurrences "ThreadLocalUsage", // 1 occurrences - "UnnecessaryParentheses", // 1 occurrences ) } diff --git a/platforms/core-runtime/build-profile/src/main/java/org/gradle/profile/TaskExecution.java b/platforms/core-runtime/build-profile/src/main/java/org/gradle/profile/TaskExecution.java index 2596879acb9f..0a1484e18ead 100644 --- a/platforms/core-runtime/build-profile/src/main/java/org/gradle/profile/TaskExecution.java +++ b/platforms/core-runtime/build-profile/src/main/java/org/gradle/profile/TaskExecution.java @@ -41,7 +41,7 @@ public String getPath() { } public String getStatus() { - return state.getSkipped() ? state.getSkipMessage() : (state.getDidWork()) ? "" : NO_WORK_MESSAGE; + return state.getSkipped() ? state.getSkipMessage() : state.getDidWork() ? "" : NO_WORK_MESSAGE; } public TaskState getState() { diff --git a/platforms/core-runtime/functional/build.gradle.kts b/platforms/core-runtime/functional/build.gradle.kts index 883d0155263f..a86e5df819d3 100644 --- a/platforms/core-runtime/functional/build.gradle.kts +++ b/platforms/core-runtime/functional/build.gradle.kts @@ -5,12 +5,6 @@ plugins { description = "Tools to work with functional code, including data structures" -errorprone { - disabledChecks.addAll( - "UnnecessaryLambda", // 1 occurrences - ) -} - dependencies { api(libs.jsr305) diff --git a/platforms/core-runtime/functional/src/main/java/org/gradle/internal/Combiners.java b/platforms/core-runtime/functional/src/main/java/org/gradle/internal/Combiners.java index 47da8140e3a7..9e449670eddf 100644 --- a/platforms/core-runtime/functional/src/main/java/org/gradle/internal/Combiners.java +++ b/platforms/core-runtime/functional/src/main/java/org/gradle/internal/Combiners.java @@ -24,15 +24,16 @@ * Promote to a more shared subproject if useful. */ public abstract class Combiners { - private static final BinaryOperator NON_COMBINING = (a, b) -> { - throw new IllegalStateException("Not a combinable operation"); - }; /** * We know the stream we are processing is handled sequentially, and hence there is no need for a combiner. */ @SuppressWarnings("unchecked") public static BinaryOperator nonCombining() { - return (BinaryOperator) NON_COMBINING; + return Combiners::unsupportedCombineOperation; + } + + private static T unsupportedCombineOperation(T a, T b) { + throw new IllegalStateException("Not a combinable operation"); } } diff --git a/platforms/core-runtime/logging/build.gradle.kts b/platforms/core-runtime/logging/build.gradle.kts index b23adebf6794..04b53def5f09 100644 --- a/platforms/core-runtime/logging/build.gradle.kts +++ b/platforms/core-runtime/logging/build.gradle.kts @@ -23,7 +23,6 @@ errorprone { "StringSplitter", // 4 occurrences "ThreadLocalUsage", // 1 occurrences "TypeParameterUnusedInFormals", // 1 occurrences - "UnnecessaryParentheses", // 3 occurrences "UnusedMethod", // 3 occurrences "UnusedVariable", // 1 occurrences ) diff --git a/platforms/core-runtime/logging/src/main/java/org/gradle/internal/logging/text/TreeFormatter.java b/platforms/core-runtime/logging/src/main/java/org/gradle/internal/logging/text/TreeFormatter.java index dbd276abee8a..480634eaa09d 100644 --- a/platforms/core-runtime/logging/src/main/java/org/gradle/internal/logging/text/TreeFormatter.java +++ b/platforms/core-runtime/logging/src/main/java/org/gradle/internal/logging/text/TreeFormatter.java @@ -392,7 +392,7 @@ private static class NumberedPrefixer implements Prefixer { @Override public String nextPrefix() { - return " " + (++cur) + ". "; + return " " + ++cur + ". "; } } } diff --git a/platforms/core-runtime/logging/src/main/java/org/gradle/util/GUtil.java b/platforms/core-runtime/logging/src/main/java/org/gradle/util/GUtil.java index ed7fa115eb9a..0064498779da 100644 --- a/platforms/core-runtime/logging/src/main/java/org/gradle/util/GUtil.java +++ b/platforms/core-runtime/logging/src/main/java/org/gradle/util/GUtil.java @@ -112,10 +112,10 @@ public static > T flatten(Collection elements, T addT flatten((Collection) element, addTo, flattenMaps, flattenArrays); } else if ((element instanceof Map) && flattenMaps) { flatten(((Map) element).values(), addTo, flattenMaps, flattenArrays); - } else if ((element.getClass().isArray()) && flattenArrays) { + } else if (element.getClass().isArray() && flattenArrays) { flatten(asList((Object[]) element), addTo, flattenMaps, flattenArrays); } else { - (Cast.>uncheckedNonnullCast(addTo)).add(element); + Cast.>uncheckedNonnullCast(addTo).add(element); } } return addTo; diff --git a/platforms/core-runtime/messaging/build.gradle.kts b/platforms/core-runtime/messaging/build.gradle.kts index ee09bd9401f4..6a96909ce5d0 100644 --- a/platforms/core-runtime/messaging/build.gradle.kts +++ b/platforms/core-runtime/messaging/build.gradle.kts @@ -16,7 +16,6 @@ errorprone { "ReferenceEquality", // 1 occurrences "StringCaseLocaleUsage", // 1 occurrences "ThreadPriorityCheck", // 1 occurrences - "UnnecessaryParentheses", // 2 occurrences "UnrecognisedJavadocTag", // 1 occurrences ) } diff --git a/platforms/ide/ide-plugins/build.gradle.kts b/platforms/ide/ide-plugins/build.gradle.kts index 19656817b9ce..c5291cb850ec 100644 --- a/platforms/ide/ide-plugins/build.gradle.kts +++ b/platforms/ide/ide-plugins/build.gradle.kts @@ -24,7 +24,6 @@ errorprone { disabledChecks.addAll( "MixedMutabilityReturnType", // 2 occurrences "ShortCircuitBoolean", // 2 occurrences - "UnnecessaryParentheses", // 1 occurrences ) } diff --git a/platforms/ide/ide-plugins/src/main/java/org/gradle/plugins/ide/idea/internal/IdeaScalaConfigurer.java b/platforms/ide/ide-plugins/src/main/java/org/gradle/plugins/ide/idea/internal/IdeaScalaConfigurer.java index b4bfabfc7e65..50789530e3aa 100644 --- a/platforms/ide/ide-plugins/src/main/java/org/gradle/plugins/ide/idea/internal/IdeaScalaConfigurer.java +++ b/platforms/ide/ide-plugins/src/main/java/org/gradle/plugins/ide/idea/internal/IdeaScalaConfigurer.java @@ -164,7 +164,7 @@ private void declareUniqueProjectLibraries(Set projectLibraries) String originalName = newLibrary.getName(); int suffix = 1; while (containsLibraryWithSameName(existingLibraries, newLibrary.getName())) { - newLibrary.setName(originalName + "-" + (suffix++)); + newLibrary.setName(originalName + "-" + suffix++); } existingLibraries.add(newLibrary); } diff --git a/platforms/jvm/jacoco/build.gradle.kts b/platforms/jvm/jacoco/build.gradle.kts index 606eb1286c64..71ce73e58d2d 100644 --- a/platforms/jvm/jacoco/build.gradle.kts +++ b/platforms/jvm/jacoco/build.gradle.kts @@ -7,7 +7,6 @@ description = "Plugin and integration with JaCoCo code coverage" errorprone { disabledChecks.addAll( "ReferenceEquality", // 3 occurrences - "UnnecessaryParentheses", // 1 occurrences "UnusedMethod", // 1 occurrences ) } diff --git a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoTaskExtension.java b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoTaskExtension.java index e3b1b84be61b..428623c36947 100644 --- a/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoTaskExtension.java +++ b/platforms/jvm/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoTaskExtension.java @@ -344,7 +344,7 @@ public ArgumentAppender(StringBuilder builder, File workingDirectory) { public void append(String name, @Nullable Object value) { if (value != null && !((value instanceof Collection) && ((Collection) value).isEmpty()) - && !((value instanceof String) && (StringUtils.isEmpty((String) value))) + && !((value instanceof String) && StringUtils.isEmpty((String) value)) && !((value instanceof Integer) && ((Integer) value == 0))) { if (anyArgs) { builder.append(','); diff --git a/platforms/jvm/language-groovy/build.gradle.kts b/platforms/jvm/language-groovy/build.gradle.kts index 1ca888b85795..ecd6acf16492 100644 --- a/platforms/jvm/language-groovy/build.gradle.kts +++ b/platforms/jvm/language-groovy/build.gradle.kts @@ -7,7 +7,6 @@ description = "Adds support for building Groovy projects" errorprone { disabledChecks.addAll( "ModifyCollectionInEnhancedForLoop", // 1 occurrences - "UnnecessaryParentheses", // 1 occurrences "UnusedMethod", // 4 occurrences "UnusedVariable", // 1 occurrences ) diff --git a/platforms/jvm/language-groovy/src/main/java/org/gradle/api/internal/tasks/compile/NormalizingGroovyCompiler.java b/platforms/jvm/language-groovy/src/main/java/org/gradle/api/internal/tasks/compile/NormalizingGroovyCompiler.java index cc124636184e..516a2bbd5904 100644 --- a/platforms/jvm/language-groovy/src/main/java/org/gradle/api/internal/tasks/compile/NormalizingGroovyCompiler.java +++ b/platforms/jvm/language-groovy/src/main/java/org/gradle/api/internal/tasks/compile/NormalizingGroovyCompiler.java @@ -105,7 +105,7 @@ private WorkResult delegateAndHandleErrors(GroovyJavaJointCompileSpec spec) { // in-process Groovy compilation throws a CompilationFailedException from another classloader, hence testing class name equality // TODO:pm Prefer class over class name for equality check once using WorkerExecutor for in-process groovy compilation if ((spec.getCompileOptions().isFailOnError() && spec.getGroovyCompileOptions().isFailOnError()) - || (!CompilationFailedException.class.getName().equals(e.getClass().getName()))) { + || !CompilationFailedException.class.getName().equals(e.getClass().getName())) { throw e; } LOGGER.debug("Ignoring compilation failure."); diff --git a/platforms/jvm/toolchains-jvm-shared/src/main/java/org/gradle/jvm/toolchain/internal/JvmInstallationMetadataMatcher.java b/platforms/jvm/toolchains-jvm-shared/src/main/java/org/gradle/jvm/toolchain/internal/JvmInstallationMetadataMatcher.java index 719ad47302b7..93bdf95b3075 100644 --- a/platforms/jvm/toolchains-jvm-shared/src/main/java/org/gradle/jvm/toolchain/internal/JvmInstallationMetadataMatcher.java +++ b/platforms/jvm/toolchains-jvm-shared/src/main/java/org/gradle/jvm/toolchain/internal/JvmInstallationMetadataMatcher.java @@ -25,7 +25,6 @@ import java.util.function.Predicate; -@SuppressWarnings("UnnecessaryLambda") public class JvmInstallationMetadataMatcher implements Predicate { private final JavaLanguageVersion languageVersion; private final DefaultJvmVendorSpec vendorSpec; @@ -43,7 +42,7 @@ public JvmInstallationMetadataMatcher(JavaToolchainSpec spec) { @Override public boolean test(JvmInstallationMetadata metadata) { - Predicate predicate = languagePredicate().and(vendorPredicate()).and(implementationPredicate()); + Predicate predicate = languagePredicate().and(vendorPredicate()).and(this::implementationTest); return predicate.test(metadata); } @@ -54,18 +53,6 @@ private Predicate languagePredicate() { }; } - private Predicate implementationPredicate() { - return metadata -> { - if (jvmImplementation == JvmImplementation.VENDOR_SPECIFIC) { - return true; - } - - final boolean j9Requested = isJ9ExplicitlyRequested() || isJ9RequestedViaVendor(); - final boolean isJ9Vm = metadata.hasCapability(JvmInstallationMetadata.JavaInstallationCapability.J9_VIRTUAL_MACHINE); - return j9Requested == isJ9Vm; - }; - } - private boolean isJ9ExplicitlyRequested() { return jvmImplementation == JvmImplementation.J9; } @@ -78,4 +65,13 @@ private Predicate vendorPredicate() { return vendorSpec; } + private boolean implementationTest(JvmInstallationMetadata metadata) { + if (jvmImplementation == JvmImplementation.VENDOR_SPECIFIC) { + return true; + } + + final boolean j9Requested = isJ9ExplicitlyRequested() || isJ9RequestedViaVendor(); + final boolean isJ9Vm = metadata.hasCapability(JvmInstallationMetadata.JavaInstallationCapability.J9_VIRTUAL_MACHINE); + return j9Requested == isJ9Vm; + } } diff --git a/platforms/jvm/toolchains-jvm/build.gradle.kts b/platforms/jvm/toolchains-jvm/build.gradle.kts index 70ea90a0fa5c..2276a284ff2f 100644 --- a/platforms/jvm/toolchains-jvm/build.gradle.kts +++ b/platforms/jvm/toolchains-jvm/build.gradle.kts @@ -24,7 +24,6 @@ description = "Adds support for using JVM toolchains in projects" errorprone { disabledChecks.addAll( "StringCaseLocaleUsage", // 2 occurrences - "UnnecessaryLambda", // 2 occurrences ) } diff --git a/platforms/jvm/toolchains-jvm/src/main/java/org/gradle/jvm/toolchain/internal/task/ShowToolchainsTask.java b/platforms/jvm/toolchains-jvm/src/main/java/org/gradle/jvm/toolchain/internal/task/ShowToolchainsTask.java index 8f3ce82e7c9b..0856f8f83b17 100644 --- a/platforms/jvm/toolchains-jvm/src/main/java/org/gradle/jvm/toolchain/internal/task/ShowToolchainsTask.java +++ b/platforms/jvm/toolchains-jvm/src/main/java/org/gradle/jvm/toolchain/internal/task/ShowToolchainsTask.java @@ -31,7 +31,6 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; -import java.util.function.Predicate; import java.util.stream.Collectors; import static org.gradle.api.internal.lambdas.SerializableLambdas.spec; @@ -76,16 +75,16 @@ private void printOptions(StyledTextOutput output) { output.println(); } - private List invalidToolchains(List toolchains) { - return toolchains.stream().filter(t -> !isValidToolchain().test(t)).collect(Collectors.toList()); + private static List invalidToolchains(List toolchains) { + return toolchains.stream().filter(t -> !isValidToolchain(t)).collect(Collectors.toList()); } - private List validToolchains(Collection toolchains) { - return toolchains.stream().filter(isValidToolchain()).sorted(TOOLCHAIN_COMPARATOR).collect(Collectors.toList()); + private static List validToolchains(Collection toolchains) { + return toolchains.stream().filter(ShowToolchainsTask::isValidToolchain).sorted(TOOLCHAIN_COMPARATOR).collect(Collectors.toList()); } - private Predicate isValidToolchain() { - return t -> t.metadata.isValidInstallation(); + private static boolean isValidToolchain(JvmToolchainMetadata t) { + return t.metadata.isValidInstallation(); } private List allReportableToolchains() { diff --git a/platforms/native/platform-native/build.gradle.kts b/platforms/native/platform-native/build.gradle.kts index 466c89b97beb..0eb1fdebf47a 100644 --- a/platforms/native/platform-native/build.gradle.kts +++ b/platforms/native/platform-native/build.gradle.kts @@ -16,7 +16,6 @@ errorprone { "StringCaseLocaleUsage", // 3 occurrences "StringCharset", // 2 occurrences "StringSplitter", // 1 occurrences - "UnnecessaryParentheses", // 1 occurrences "UnnecessaryTypeArgument", // 2 occurrences "UnusedMethod", // 11 occurrences "UnusedTypeParameter", // 1 occurrences diff --git a/platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/gcc/ArStaticLibraryArchiver.java b/platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/gcc/ArStaticLibraryArchiver.java index 4ae5abcf8976..a8611b461bad 100644 --- a/platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/gcc/ArStaticLibraryArchiver.java +++ b/platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/gcc/ArStaticLibraryArchiver.java @@ -53,7 +53,7 @@ private void deletePreviousOutput(StaticLibraryArchiverSpec spec) { if (!spec.getOutputFile().isFile()) { return; } - if (!(spec.getOutputFile().delete())) { + if (!spec.getOutputFile().delete()) { throw new GradleException("Create static archive failed: could not delete previous archive"); } } diff --git a/subprojects/core/build.gradle.kts b/subprojects/core/build.gradle.kts index 179efd435ab8..5ec4382756f9 100644 --- a/subprojects/core/build.gradle.kts +++ b/subprojects/core/build.gradle.kts @@ -68,8 +68,6 @@ errorprone { "TypeParameterShadowing", // 1 occurrences "TypeParameterUnusedInFormals", // 2 occurrences "UndefinedEquals", // 1 occurrences - "UnnecessaryLambda", // 1 occurrences - "UnnecessaryParentheses", // 1 occurrences "UnrecognisedJavadocTag", // 1 occurrences "UnusedMethod", // 18 occurrences "UnusedVariable", // 8 occurrences diff --git a/subprojects/core/src/main/java/org/gradle/api/internal/FilePropertyContainer.java b/subprojects/core/src/main/java/org/gradle/api/internal/FilePropertyContainer.java index a162d8901d50..eba6b2a46aa9 100644 --- a/subprojects/core/src/main/java/org/gradle/api/internal/FilePropertyContainer.java +++ b/subprojects/core/src/main/java/org/gradle/api/internal/FilePropertyContainer.java @@ -50,7 +50,7 @@ public Iterator iterator() { for (T propertySpec : properties) { String propertyName = propertySpec.getPropertyName(); if (propertyName == null) { - propertyName = "$" + (++unnamedPropertyCounter); + propertyName = "$" + ++unnamedPropertyCounter; propertySpec.withPropertyName(propertyName); } } diff --git a/subprojects/core/src/main/java/org/gradle/api/internal/artifacts/dsl/dependencies/DependenciesExtensionModule.java b/subprojects/core/src/main/java/org/gradle/api/internal/artifacts/dsl/dependencies/DependenciesExtensionModule.java index 65ff8977cf86..3d111ce99a7d 100644 --- a/subprojects/core/src/main/java/org/gradle/api/internal/artifacts/dsl/dependencies/DependenciesExtensionModule.java +++ b/subprojects/core/src/main/java/org/gradle/api/internal/artifacts/dsl/dependencies/DependenciesExtensionModule.java @@ -110,7 +110,7 @@ public static ExternalModuleDependency module(Dependencies self, Map map, String key) { - return (map.containsKey(key)) ? map.get(key).toString() : null; + return map.containsKey(key) ? map.get(key).toString() : null; } /** diff --git a/subprojects/core/src/main/java/org/gradle/api/internal/initialization/transform/InstrumentationAnalysisTransform.java b/subprojects/core/src/main/java/org/gradle/api/internal/initialization/transform/InstrumentationAnalysisTransform.java index e1013a0e6882..60132d5e5ee2 100644 --- a/subprojects/core/src/main/java/org/gradle/api/internal/initialization/transform/InstrumentationAnalysisTransform.java +++ b/subprojects/core/src/main/java/org/gradle/api/internal/initialization/transform/InstrumentationAnalysisTransform.java @@ -47,7 +47,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -import java.util.function.Predicate; import java.util.stream.Stream; import static com.google.common.base.Preconditions.checkNotNull; @@ -77,15 +76,18 @@ @DisableCachingByDefault(because = "Not worth caching.") public abstract class InstrumentationAnalysisTransform implements TransformAction { + private static boolean isTypeAccepted(String type) { + return type != null && !type.startsWith("java/lang/"); + } + public interface Parameters extends TransformParameters { @Internal Property getBuildService(); + @Internal Property getContextId(); } - private static final Predicate ACCEPTED_TYPES = type -> type != null && !type.startsWith("java/lang/"); - private final Lazy internalServices = Lazy.unsafe().of(() -> getObjects().newInstance(InjectedInstrumentationServices.class)); @Inject @@ -135,13 +137,13 @@ private void analyzeArtifact(File artifact, Map> superTypesC private static Set collectSuperTypes(ClassReader reader) { return Stream.concat(Stream.of(reader.getSuperName()), Stream.of(reader.getInterfaces())) - .filter(ACCEPTED_TYPES) + .filter(InstrumentationAnalysisTransform::isTypeAccepted) .collect(toImmutableSortedSet(Ordering.natural())); } private static void collectArtifactClassDependencies(String className, ClassReader reader, Set collector) { ClassAnalysisUtils.getClassDependencies(reader, dependencyDescriptor -> { - if (!dependencyDescriptor.equals(className) && ACCEPTED_TYPES.test(dependencyDescriptor)) { + if (!dependencyDescriptor.equals(className) && InstrumentationAnalysisTransform.isTypeAccepted(dependencyDescriptor)) { collector.add(dependencyDescriptor); } }); diff --git a/subprojects/core/src/main/java/org/gradle/api/internal/project/taskfactory/DefaultTaskClassInfoStore.java b/subprojects/core/src/main/java/org/gradle/api/internal/project/taskfactory/DefaultTaskClassInfoStore.java index e9575ddd50a3..4138edb29dc5 100644 --- a/subprojects/core/src/main/java/org/gradle/api/internal/project/taskfactory/DefaultTaskClassInfoStore.java +++ b/subprojects/core/src/main/java/org/gradle/api/internal/project/taskfactory/DefaultTaskClassInfoStore.java @@ -35,12 +35,10 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import java.util.function.Function; @NonNullApi public class DefaultTaskClassInfoStore implements TaskClassInfoStore { private final CrossBuildInMemoryCache, TaskClassInfo> classInfos; - private final Function, TaskClassInfo> taskClassInfoFactory = aClass -> createTaskClassInfo(aClass.asSubclass(Task.class)); public DefaultTaskClassInfoStore(CrossBuildInMemoryCacheFactory cacheFactory) { this.classInfos = cacheFactory.newClassCache(); @@ -48,10 +46,10 @@ public DefaultTaskClassInfoStore(CrossBuildInMemoryCacheFactory cacheFactory) { @Override public TaskClassInfo getTaskClassInfo(Class type) { - return classInfos.get(type, taskClassInfoFactory); + return classInfos.get(type, aClass -> createTaskClassInfo(aClass.asSubclass(Task.class))); } - private TaskClassInfo createTaskClassInfo(Class type) { + private static TaskClassInfo createTaskClassInfo(Class type) { boolean cacheable = type.isAnnotationPresent(CacheableTask.class); Optional reasonNotToTrackState = Optional.ofNullable(type.getAnnotation(UntrackedTask.class)) .map(UntrackedTask::because); diff --git a/subprojects/core/src/main/java/org/gradle/initialization/MixInLegacyTypesClassLoader.java b/subprojects/core/src/main/java/org/gradle/initialization/MixInLegacyTypesClassLoader.java index 211d48d6fc19..a6807bd0c1ea 100644 --- a/subprojects/core/src/main/java/org/gradle/initialization/MixInLegacyTypesClassLoader.java +++ b/subprojects/core/src/main/java/org/gradle/initialization/MixInLegacyTypesClassLoader.java @@ -150,7 +150,7 @@ public FieldVisitor visitField(int access, String name, String desc, String sign if (((access & PUBLIC_STATIC_FINAL) == PUBLIC_STATIC_FINAL) && Type.getDescriptor(String.class).equals(desc)) { missingStaticStringConstantGetters.put("get" + name, name); } - if (((access & Opcodes.ACC_PRIVATE) > 0) && !isStatic(access) && (Type.getDescriptor(boolean.class).equals(desc))) { + if (((access & Opcodes.ACC_PRIVATE) > 0) && !isStatic(access) && Type.getDescriptor(boolean.class).equals(desc)) { booleanFields.add(name); } return super.visitField(access, name, desc, signature, value);