Skip to content

Commit

Permalink
GH-762 - Open up ApplicationModules.of(…) to take a DescribedPredicat…
Browse files Browse the repository at this point in the history
…e<? super JavaClass>.
  • Loading branch information
odrotbohm committed Aug 13, 2024
1 parent 1dbce34 commit 41bd816
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static DescribedPredicate<CanBeAnnotated> getAtGenerated() {
* @param option must not be {@literal null}.
*/
protected ApplicationModules(ModulithMetadata metadata,
DescribedPredicate<JavaClass> ignored, boolean useFullyQualifiedModuleNames, ImportOption option) {
DescribedPredicate<? super JavaClass> ignored, boolean useFullyQualifiedModuleNames, ImportOption option) {
this(metadata, metadata.getBasePackages(), ignored, useFullyQualifiedModuleNames, option);
}

Expand All @@ -118,18 +118,20 @@ protected ApplicationModules(ModulithMetadata metadata,
*/
@Deprecated(forRemoval = true)
protected ApplicationModules(ModulithMetadata metadata, Collection<String> packages,
DescribedPredicate<JavaClass> ignored, boolean useFullyQualifiedModuleNames, ImportOption option) {
DescribedPredicate<? super JavaClass> ignored, boolean useFullyQualifiedModuleNames, ImportOption option) {

Assert.notNull(metadata, "ModulithMetadata must not be null!");
Assert.notNull(packages, "Base packages must not be null!");
Assert.notNull(ignored, "Ignores must not be null!");
Assert.notNull(option, "ImportOptions must not be null!");

DescribedPredicate<? super JavaClass> excluded = DescribedPredicate.or(ignored, IS_AOT_TYPE, IS_SPRING_CGLIB_PROXY);

this.metadata = metadata;
this.allClasses = new ClassFileImporter() //
.withImportOption(option) //
.importPackages(packages) //
.that(not(ignored.or(IS_AOT_TYPE).or(IS_SPRING_CGLIB_PROXY)));
.that(not(excluded));

Assert.notEmpty(allClasses, () -> "No classes found in packages %s!".formatted(packages));

Expand Down Expand Up @@ -215,7 +217,7 @@ public static ApplicationModules of(Class<?> modulithType) {
* @param ignored must not be {@literal null}.
* @return will never be {@literal null}.
*/
public static ApplicationModules of(Class<?> modulithType, DescribedPredicate<JavaClass> ignored) {
public static ApplicationModules of(Class<?> modulithType, DescribedPredicate<? super JavaClass> ignored) {

Assert.notNull(modulithType, "Modulith root type must not be null!");
Assert.notNull(ignored, "Predicate to describe ignored types must not be null!");
Expand Down Expand Up @@ -653,12 +655,12 @@ public static DescribedPredicate<JavaClass> withoutModule(String name) {

private static class CacheKey {

private final DescribedPredicate<JavaClass> ignored;
private final DescribedPredicate<? super JavaClass> ignored;
private final ImportOption options;
private final Object metadataSource;
private final Supplier<ModulithMetadata> metadata;

public CacheKey(DescribedPredicate<JavaClass> ignored, ImportOption options, Object metadataSource,
public CacheKey(DescribedPredicate<? super JavaClass> ignored, ImportOption options, Object metadataSource,
Supplier<ModulithMetadata> metadata) {

this.ignored = ignored;
Expand All @@ -667,15 +669,15 @@ public CacheKey(DescribedPredicate<JavaClass> ignored, ImportOption options, Obj
this.metadata = SingletonSupplier.of(metadata);
}

static CacheKey of(String pkg, DescribedPredicate<JavaClass> ignored, ImportOption options) {
static CacheKey of(String pkg, DescribedPredicate<? super JavaClass> ignored, ImportOption options) {
return new CacheKey(ignored, options, pkg, () -> ModulithMetadata.of(pkg));
}

static CacheKey of(Class<?> type, DescribedPredicate<JavaClass> ignored, ImportOption options) {
static CacheKey of(Class<?> type, DescribedPredicate<? super JavaClass> ignored, ImportOption options) {
return new CacheKey(ignored, options, type, () -> ModulithMetadata.of(type));
}

DescribedPredicate<JavaClass> getIgnored() {
DescribedPredicate<? super JavaClass> getIgnored() {
return ignored;
}

Expand Down

0 comments on commit 41bd816

Please sign in to comment.