diff --git a/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/io/github/ascopes/jct/acceptancetests/serviceloaderjpms/ServiceProcessor.java b/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/io/github/ascopes/jct/acceptancetests/serviceloaderjpms/ServiceProcessor.java index 0f4984151..33b6f36ab 100644 --- a/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/io/github/ascopes/jct/acceptancetests/serviceloaderjpms/ServiceProcessor.java +++ b/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/io/github/ascopes/jct/acceptancetests/serviceloaderjpms/ServiceProcessor.java @@ -41,6 +41,10 @@ */ public class ServiceProcessor extends AbstractProcessor { + public ServiceProcessor() { + // Hope you are happy, javac. I made a constructor for you. + } + @Override public Set getSupportedAnnotationTypes() { return Set.of(Service.class.getName()); diff --git a/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/module-info.java b/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/module-info.java index 0ad21c93a..6d63ecfef 100644 --- a/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/module-info.java +++ b/java-compiler-testing/src/it/serviceloader-jpms/src/main/java/module-info.java @@ -17,7 +17,7 @@ import javax.annotation.processing.Processor; module io.github.ascopes.jct.acceptancetests.serviceloaderjpms { - requires java.compiler; + requires transitive java.compiler; exports io.github.ascopes.jct.acceptancetests.serviceloaderjpms; provides Processor with ServiceProcessor; } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractEnumAssert.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractEnumAssert.java index afab5b256..24b507d00 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractEnumAssert.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/AbstractEnumAssert.java @@ -103,6 +103,7 @@ public final A isAnyOfElements(Collection elements) { * group of acceptable values. */ @SafeVarargs + @SuppressWarnings("varargs") public final A isNoneOf(E... elements) { requireNonNullValues(elements, "elements"); requireAtLeastOne(elements, "elements"); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctAssertions.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctAssertions.java index 431d37908..e5db126f1 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctAssertions.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/assertions/JctAssertions.java @@ -21,7 +21,6 @@ import io.github.ascopes.jct.containers.PackageContainerGroup; import io.github.ascopes.jct.diagnostics.TraceDiagnostic; import io.github.ascopes.jct.filemanagers.PathFileObject; -import io.github.ascopes.jct.utils.UtilityClass; import java.util.List; import javax.tools.Diagnostic; import javax.tools.JavaFileManager.Location; @@ -35,7 +34,7 @@ * @since 0.0.1 */ @SuppressWarnings("unused") -public final class JctAssertions extends UtilityClass { +public final class JctAssertions { private JctAssertions() { // Disallow initialisation. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompilers.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompilers.java index 9b901b564..1777a0059 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompilers.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/JctCompilers.java @@ -16,7 +16,6 @@ package io.github.ascopes.jct.compilers; import io.github.ascopes.jct.compilers.impl.JavacJctCompilerImpl; -import io.github.ascopes.jct.utils.UtilityClass; /** * Helpers to create new compiler instances. @@ -24,7 +23,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class JctCompilers extends UtilityClass { +public final class JctCompilers { private JctCompilers() { // Static-only class. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java index df6f8841c..40288a9eb 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/diagnostics/TracingDiagnosticListener.java @@ -18,7 +18,6 @@ import static java.util.Objects.requireNonNull; import io.github.ascopes.jct.utils.LoomPolyfill; -import io.github.ascopes.jct.utils.VisibleForTestingOnly; import java.time.Instant; import java.util.List; import java.util.Locale; @@ -67,19 +66,7 @@ public TracingDiagnosticListener( ); } - /** - * Only visible for testing. - * - *

Users should NOT use this constructor. It may be changed - * or removed without notice. - * - * @param logger the logger to use. - * @param threadGetter the supplier of the current thread. - * @param logging whether to enable logging. - * @param stackTraces whether to enable stack traces in the logging. - */ - @VisibleForTestingOnly - protected TracingDiagnosticListener( + TracingDiagnosticListener( Logger logger, Supplier threadGetter, boolean logging, diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java index 7f9b1e387..1b7e032a4 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java @@ -411,9 +411,9 @@ Set list( @Override Iterable> listLocationsForModules(Location location) throws IOException; - /// - /// Default helper overrides - /// + /* + * Default helper overrides + */ /** * Get the location holding the {@link StandardLocation#CLASS_OUTPUT class outputs}. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManagers.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManagers.java index 42b49496a..95037c981 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManagers.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManagers.java @@ -17,7 +17,6 @@ import io.github.ascopes.jct.compilers.JctCompiler; import io.github.ascopes.jct.filemanagers.impl.JctFileManagerFactoryImpl; -import io.github.ascopes.jct.utils.UtilityClass; /** * Helpers to create instances of default implementations for file managers. @@ -25,7 +24,7 @@ * @author Ashley Scopes * @since 1.1.0 */ -public final class JctFileManagers extends UtilityClass { +public final class JctFileManagers { private JctFileManagers() { // Static-only class. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java index e0b1a9837..2c05c4e6a 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImpl.java @@ -27,7 +27,6 @@ import io.github.ascopes.jct.filemanagers.config.JctFileManagerLoggingProxyConfigurer; import io.github.ascopes.jct.filemanagers.config.JctFileManagerRequiredLocationsConfigurer; import io.github.ascopes.jct.filemanagers.config.JctFileManagerWorkspaceConfigurer; -import io.github.ascopes.jct.utils.VisibleForTestingOnly; import io.github.ascopes.jct.workspaces.Workspace; /** @@ -54,12 +53,10 @@ public JctFileManagerFactoryImpl(JctCompiler compiler) { } /** - * Get the compiler that was set on this file manager factory. + * Get the associated compiler. * - * @return the compiler - * @since 1.1.0 + * @return the associated compiler. */ - @VisibleForTestingOnly public JctCompiler getCompiler() { return compiler; } @@ -72,16 +69,7 @@ public JctFileManager createFileManager(Workspace workspace) { .configure(fileManager); } - /** - * Create the default configurer chain to use for the given workspace. - * - *

This is visible for testing only. - * - * @param workspace the workspace to configure with. - * @return the chain to use. - */ - @VisibleForTestingOnly - public JctFileManagerConfigurerChain createConfigurerChain(Workspace workspace) { + JctFileManagerConfigurerChain createConfigurerChain(Workspace workspace) { // The order here is important. Do not adjust it without testing extensively first! return new JctFileManagerConfigurerChain() .addLast(new JctFileManagerWorkspaceConfigurer(workspace)) diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/LoggingFileManagerProxy.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/LoggingFileManagerProxy.java index d30f40b73..9f113e7f4 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/LoggingFileManagerProxy.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/impl/LoggingFileManagerProxy.java @@ -69,7 +69,7 @@ private LoggingFileManagerProxy(JctFileManager inner, boolean stackTraces) { */ @Nullable @Override - public Object invoke(Object proxy, Method method, Object @Nullable ... args) throws Throwable { + public Object invoke(Object proxy, Method method, Object @Nullable[] args) throws Throwable { if (method.getName().equals("toString")) { return toString(); } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java index 82180b67d..df3b78144 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/AbstractCompilersProvider.java @@ -309,7 +309,7 @@ private JctCompilerConfigurer initializeConfigurer( } } - @SuppressWarnings("unchecked") + @SuppressWarnings({"rawtypes", "unchecked", "RedundantSuppression"}) private static Class[] emptyArray() { return (Class[]) new Class[0]; } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilersProvider.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilersProvider.java index 84686ca45..df3cb2526 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilersProvider.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilersProvider.java @@ -17,7 +17,6 @@ import io.github.ascopes.jct.compilers.JctCompiler; import io.github.ascopes.jct.compilers.impl.JavacJctCompilerImpl; -import io.github.ascopes.jct.utils.VisibleForTestingOnly; import org.junit.jupiter.params.support.AnnotationConsumer; /** @@ -29,14 +28,7 @@ public final class JavacCompilersProvider extends AbstractCompilersProvider implements AnnotationConsumer { - /** - * Initialise the provider. - * - *

This is only visible for testing purposes, users should have no need to - * initialise this class directly. - */ - @VisibleForTestingOnly - public JavacCompilersProvider() { + JavacCompilersProvider() { // Visible for testing only. } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java index 16ee36c00..40cf9b943 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/FileUtils.java @@ -37,7 +37,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class FileUtils extends UtilityClass { +public final class FileUtils { // Exclude any "empty" extensions. At the time of writing, this will just exclude Kind.EMPTY, // but doing this will prevent future API changes from breaking any assumptions we make. In diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IoExceptionUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IoExceptionUtils.java index 5c16fd843..4e7938fe0 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IoExceptionUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IoExceptionUtils.java @@ -24,7 +24,7 @@ * * @author Ashley Scopes */ -public final class IoExceptionUtils extends UtilityClass { +public final class IoExceptionUtils { private IoExceptionUtils() { // Disallow initialisation. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IterableUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IterableUtils.java index 9acf13b3b..bd2aab0e0 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IterableUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/IterableUtils.java @@ -31,7 +31,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class IterableUtils extends UtilityClass { +public final class IterableUtils { private IterableUtils() { // Disallow initialisation. @@ -184,9 +184,7 @@ public static T[] requireNonNullValues( throw new NullPointerException(error); } - //noinspection RedundantCast -- Cast is not redundant as we're casting away any nullability - // annotations for nullness typecheckers. Don't let IntelliJ tell you otherwise as it is a - // bug. - return (T[]) array; + //noinspection NullableProblems + return array; } } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/LoomPolyfill.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/LoomPolyfill.java index 856bbbed3..edef6b371 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/LoomPolyfill.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/LoomPolyfill.java @@ -24,7 +24,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class LoomPolyfill extends UtilityClass { +public final class LoomPolyfill { private LoomPolyfill() { // Static-only class. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java index 4735be978..71fd5a6c0 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/ModuleDiscoverer.java @@ -35,7 +35,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class ModuleDiscoverer extends UtilityClass { +public final class ModuleDiscoverer { private static final Logger log = LoggerFactory.getLogger(ModuleDiscoverer.class); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java index 63058b634..efab0b84f 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/SpecialLocationUtils.java @@ -31,7 +31,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class SpecialLocationUtils extends UtilityClass { +public final class SpecialLocationUtils { // Files we don't want to propagate by default as they may clash with the environment. private static final Set BLACKLISTED_FILE_NAMES = Set.of( diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java index 4856db87b..fd634cc48 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/StringUtils.java @@ -33,7 +33,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class StringUtils extends UtilityClass { +public final class StringUtils { // Number formatting stuff private static final BigDecimal THOUSAND = BigDecimal.valueOf(1_000); diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/UtilityClass.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/UtilityClass.java deleted file mode 100644 index 163516d9d..000000000 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/UtilityClass.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 - 2025, the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.github.ascopes.jct.utils; - -/** - * Abstract base for a static-only class. This base cannot be initialised. - * - * @author Ashley Scopes - * @since 0.0.1 - */ -public abstract class UtilityClass { - - protected UtilityClass() { - throw new UnsupportedOperationException( - "this is a utility class that cannot be initialised or extended" - ); - } -} diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java deleted file mode 100644 index 680fe0bfd..000000000 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/utils/VisibleForTestingOnly.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2022 - 2025, the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.github.ascopes.jct.utils; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotation that marks the annotated method or constructor as only being visible for testing - * purposes. - * - *

This means any API should not be using this element directly. - * - * @author Ashley Scopes - * @since 0.0.1 - */ -@Documented -@Retention(RetentionPolicy.CLASS) -@Target({ElementType.CONSTRUCTOR, ElementType.METHOD}) -public @interface VisibleForTestingOnly { -} diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java index 416b15c4e..ed89f407c 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspace.java @@ -17,7 +17,6 @@ import io.github.ascopes.jct.filemanagers.JctFileManager; import io.github.ascopes.jct.filemanagers.ModuleLocation; -import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.List; diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspaces.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspaces.java index 18867fe23..b13efa72a 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspaces.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/Workspaces.java @@ -16,7 +16,6 @@ package io.github.ascopes.jct.workspaces; import io.github.ascopes.jct.compilers.JctCompiler; -import io.github.ascopes.jct.utils.UtilityClass; import io.github.ascopes.jct.workspaces.impl.WorkspaceImpl; /** @@ -25,7 +24,7 @@ * @author Ashley Scopes * @since 0.0.1 */ -public final class Workspaces extends UtilityClass { +public final class Workspaces { private Workspaces() { // Do nothing. diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java index 7bf3912da..d73e24018 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/workspaces/impl/WorkspaceDumper.java @@ -18,7 +18,6 @@ import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo; import io.github.ascopes.jct.workspaces.PathRoot; -import java.io.Closeable; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; diff --git a/java-compiler-testing/src/main/java/module-info.java b/java-compiler-testing/src/main/java/module-info.java index 7b9fefad5..3b2d8ba42 100644 --- a/java-compiler-testing/src/main/java/module-info.java +++ b/java-compiler-testing/src/main/java/module-info.java @@ -123,15 +123,15 @@ /// DEPENDENCIES /// //////////////////// - requires com.github.marschall.memoryfilesystem; - requires java.compiler; - requires java.management; - requires me.xdrop.fuzzywuzzy; - requires org.assertj.core; - requires static org.jspecify; - requires static org.junit.jupiter.api; - requires static org.junit.jupiter.params; - requires org.slf4j; + requires transitive com.github.marschall.memoryfilesystem; + requires transitive java.compiler; + requires transitive java.management; + requires me.xdrop.fuzzywuzzy; // automatic module + requires transitive org.assertj.core; + requires transitive org.jspecify; + requires static transitive org.junit.jupiter.api; + requires static transitive org.junit.jupiter.params; + requires transitive org.slf4j; ////////////////// /// PUBLIC API /// diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/AbstractJctCompilerTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/AbstractJctCompilerTest.java index a68c72c7b..edb1e86a7 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/AbstractJctCompilerTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/AbstractJctCompilerTest.java @@ -21,6 +21,7 @@ import static io.github.ascopes.jct.fixtures.Fixtures.someOf; import static io.github.ascopes.jct.fixtures.Fixtures.someRelease; import static io.github.ascopes.jct.fixtures.Fixtures.someText; +import static io.github.ascopes.jct.fixtures.Fixtures.unused; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.fail; @@ -396,6 +397,8 @@ void compileReturnsTheExpectedCompilation() { ) ) { // Given + unused(compilationFactoryConstructor); + fileManagersCls.when(() -> JctFileManagers.newJctFileManagerFactory(any())) .thenReturn(fileManagerFactory); @@ -418,6 +421,7 @@ void compilePropagatesExceptionsThrownByTheCompilationProcess() { ) ) { // Given + unused(compilationFactoryConstructor); fileManagersCls.when(() -> JctFileManagers.newJctFileManagerFactory(any())) .thenReturn(fileManagerFactory); @@ -447,6 +451,7 @@ void compileRethrowsFileManagerClosureExceptions() throws IOException { ) ) { // Given + unused(compilationFactoryConstructor); fileManagersCls.when(() -> JctFileManagers.newJctFileManagerFactory(any())) .thenReturn(fileManagerFactory); @@ -1757,9 +1762,7 @@ void buildFlagsBuildsTheExpectedFlags() { assertThat(actualFlags).isEqualTo(expectedFlags); } - ///////////////////// - /// Param sources /// - ///////////////////// + /// ////////////////// Param sources /// ////////////////// static Stream locales() { return Stream.of( @@ -1781,9 +1784,7 @@ static Stream charsets() { ); } - //////////////////////////////// - /// Helper methods and types /// - //////////////////////////////// + /// ///////////////////////////// Helper methods and types /// ///////////////////////////// class CompilerImpl extends AbstractJctCompiler { @@ -1828,11 +1829,9 @@ final List concat(List first, List... more) { return newList; } - /// /// Reflection logic in tests is nasty, but this helps keep the tests for the constructor, - /// accessors, and mutators separate. - /// Since the AbstractJctCompiler is mostly just a fat POJO, I will allow it this time. - /// + /// accessors, and mutators separate. Since the AbstractJctCompiler is mostly just a fat POJO, I + /// will allow it this time. AbstractObjectAssert assertThatCompilerField(String field) { return assertThat(compiler).extracting(field); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java index 77e27a24e..07e0967dc 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationFactoryImplTest.java @@ -22,6 +22,7 @@ import static io.github.ascopes.jct.fixtures.Fixtures.someLinesOfText; import static io.github.ascopes.jct.fixtures.Fixtures.someText; import static io.github.ascopes.jct.fixtures.Fixtures.someTraceDiagnostic; +import static io.github.ascopes.jct.fixtures.Fixtures.unused; import static io.github.ascopes.jct.utils.IterableUtils.flatten; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -476,7 +477,9 @@ void diagnosticsGetPlacedInTheCompilationResult() throws IOException { MockInitializer configurer = (mock, ctx) -> when(mock.getDiagnostics()).thenReturn(diagnostics); - try (var ignored = mockConstruction(TracingDiagnosticListener.class, configurer)) { + try (var mockedConstruction = mockConstruction(TracingDiagnosticListener.class, configurer)) { + unused(mockedConstruction); + // Do not inline this, it will break in Mockito's stubber backend. var fileObjects = Set.of(somePathFileObject(someBinaryName())); when(fileManager.list(any(), any(), any(), anyBoolean())) diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java index f8c1dcb88..161850f29 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/compilers/impl/JctCompilationImplTest.java @@ -472,11 +472,13 @@ void buildingWithNullOutputLinesRaisesNullPointerException() { } @SafeVarargs + @SuppressWarnings("varargs") static Set nullableSetOf(T... values) { return new LinkedHashSet<>(Arrays.asList(values)); } @SafeVarargs + @SuppressWarnings("varargs") static List nullableListOf(T... values) { return Arrays.asList(values); } diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/diagnostics/TeeWriterTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/diagnostics/TeeWriterTest.java index ee515c490..4b9fb4de0 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/diagnostics/TeeWriterTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/diagnostics/TeeWriterTest.java @@ -16,6 +16,7 @@ package io.github.ascopes.jct.diagnostics; import static io.github.ascopes.jct.fixtures.Fixtures.someText; +import static io.github.ascopes.jct.fixtures.Fixtures.unused; import static java.nio.charset.Charset.defaultCharset; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; @@ -117,14 +118,13 @@ void flushDelegatesToTheWriter() throws IOException { } @DisplayName(".close() delegates to the writer") - @SuppressWarnings("EmptyTryBlock") @Test void closeDelegatesToTheWriter() throws IOException { // Given var writer = mock(Writer.class); - try (var ignoredTee = new TeeWriter(writer)) { - // Do nothing + try (var tee = new TeeWriter(writer)) { + unused(tee); } // Then diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImplTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImplTest.java index 496fa3056..7efe0e685 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImplTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/filemanagers/impl/JctFileManagerFactoryImplTest.java @@ -15,6 +15,7 @@ */ package io.github.ascopes.jct.filemanagers.impl; +import static io.github.ascopes.jct.fixtures.Fixtures.unused; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_MOCKS; @@ -80,7 +81,8 @@ void getCompilerReturnsTheCompiler() { @Test void createdFileManagersUseTheEffectiveRelease() { // Given - try (var ignored = configurerChainMock()) { + try (var chain = configurerChainMock()) { + unused(chain); var release = Fixtures.someRelease(); when(compiler.getEffectiveRelease()).thenReturn(release); diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/ExtraArgumentMatchers.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/ExtraArgumentMatchers.java index 4f15c4975..140b807d9 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/ExtraArgumentMatchers.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/ExtraArgumentMatchers.java @@ -60,6 +60,7 @@ public static T hasGenericType(T... varargs) { * @return the argument matcher. */ @SafeVarargs + @SuppressWarnings("varargs") public static > T containsExactlyElements(E... expected) { return containsExactlyElements(Set.of(expected)); } diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java index ff0f0d855..a52513e0f 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Fixtures.java @@ -49,6 +49,7 @@ import javax.tools.Diagnostic.Kind; import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileObject; +import org.jspecify.annotations.Nullable; import org.mockito.quality.Strictness; /** @@ -479,6 +480,17 @@ public static T oneOf(Collection items) { return iter.next(); } + /** + * Hack to shut up javac about unused attributes within try-with-resources, because + * Mockito really gives us no sensible choice when mocking statics/construction. Side + * effects are fairly regular in this library as well unfortunately. + * + * @param whatever whatever you want to not use. + */ + public static void unused(@SuppressWarnings("unused") @Nullable Object whatever) { + // Do nothing what-so-ever, but spook javac into leaving us alone. + } + /** * Return some of the members of a given enum. * diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java index 519a06ba3..89e84955a 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/Slf4jLoggerFake.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import io.github.ascopes.jct.utils.ToStringBuilder; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Arrays; @@ -150,21 +149,7 @@ public boolean isErrorEnabled(Marker marker) { return true; } - private static class LogRecord { - - private final Throwable ex; - private final String message; - private final Object[] args; - - LogRecord( - Throwable ex, - String message, - Object... args - ) { - this.ex = ex; - this.message = message; - this.args = args; - } + private record LogRecord(Throwable ex, String message, Object... args) { @Override public boolean equals(Object other) { @@ -175,14 +160,5 @@ public boolean equals(Object other) { } return false; } - - @Override - public String toString() { - return new ToStringBuilder(this) - .attribute("ex", ex) - .attribute("message", message) - .attribute("args", args) - .toString(); - } } } diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/UtilityClassTestTemplate.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/UtilityClassTestTemplate.java index e2f944d18..6b015dc32 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/UtilityClassTestTemplate.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/fixtures/UtilityClassTestTemplate.java @@ -17,13 +17,11 @@ import static java.util.function.Predicate.not; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatObject; import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN; import static org.assertj.core.api.InstanceOfAssertFactories.array; import static org.junit.jupiter.api.DynamicTest.dynamicTest; -import io.github.ascopes.jct.utils.UtilityClass; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -62,13 +60,6 @@ default void openModuleForReflection() { type.getModule().addOpens(type.getPackageName(), getClass().getModule()); } - @DisplayName("Class should extend UtilityClass") - @Test - default void testClassExtendsUtilityClass() { - assertThat(getTypeBeingTested()) - .hasSuperclass(UtilityClass.class); - } - @DisplayName("Class should not implement any interfaces") @Test default void classShouldNotImplementAnyInterfaces() { @@ -108,15 +99,6 @@ default void testClassConstructorHasNoArguments() { .isEqualTo(0); } - @DisplayName("Class constructor should throw an UnsupportedOperationException") - @Test - default void testClassConstructorThrowsUnsupportedOperationException() { - assertThatCode(() -> getSingleConstructor().newInstance()) - .cause() - .isInstanceOf(UnsupportedOperationException.class) - .hasMessage("this is a utility class that cannot be initialised or extended"); - } - @DisplayName("All methods should be static") @TestFactory default Stream allMethodsShouldBeStatic() { diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java index 4dde7eb34..37a1d6a68 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/AbstractCompilersProviderTest.java @@ -372,6 +372,7 @@ public CompilersProviderImpl(int minSupportedVersion, int maxSupportedVersion) { } @SafeVarargs + @SuppressWarnings("varargs") final void configureInternals( int min, int max, diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java index 7eb9d5d9d..815041d05 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/junit/JavacCompilersProviderTest.java @@ -144,6 +144,7 @@ void providerUsesTheMaxCompilerVersionAllowedIfExceeded() { } @SafeVarargs + @SuppressWarnings("varargs") final JavacCompilerTest someAnnotation( int min, int max, diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/FileUtilsTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/FileUtilsTest.java index cf199d3c7..95212da35 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/FileUtilsTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/FileUtilsTest.java @@ -609,6 +609,7 @@ static Stream fileWithAnyKindExistingFileTestCases() { } @SafeVarargs + @SuppressWarnings("varargs") static Set set(T... args) { return Set.of(args); } diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java index e7521284d..cf8bcde1e 100644 --- a/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/utils/SpecialLocationsUtilsTest.java @@ -17,6 +17,7 @@ import static io.github.ascopes.jct.fixtures.Fixtures.oneOf; import static io.github.ascopes.jct.fixtures.Fixtures.someText; +import static io.github.ascopes.jct.fixtures.Fixtures.unused; import static java.util.function.Predicate.not; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -39,8 +40,6 @@ import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.api.parallel.Isolated; @@ -118,8 +117,10 @@ void currentModulePathLocationsReturnsTheClassPathLocationsThatExist() throws IO // Given try ( var tempPaths = new TempPaths(); - var ignored = new MockedSystemProperty("jdk.module.path", tempPaths.toPathString()) + var property = new MockedSystemProperty("jdk.module.path", tempPaths.toPathString()) ) { + unused(property); + // We always exclude this path. var ideaRt = tempPaths.addFile("idea_rt.jar"); diff --git a/pom.xml b/pom.xml index 32e13faf1..b170bf15a 100644 --- a/pom.xml +++ b/pom.xml @@ -248,6 +248,9 @@ ${maven-compiler-plugin.version} + + -Xlint:all,-classfile,-processing,-requires-automatic,-serial + true true ${java-release}