Skip to content

Commit

Permalink
Create default predicate in EndpointIndexer
Browse files Browse the repository at this point in the history
  • Loading branch information
aureamunoz committed Dec 10, 2024
1 parent a7dd34c commit 6221d48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -854,18 +853,6 @@ private FilterClassIntrospector createFilterClassIntrospector() {
return ab.get();
}

@BuildStep
EndpointValidationPredicatesBuildItem createSpringRestControllerPredicate() {
Predicate<ClassInfo> predicate = new Predicate<ClassInfo>() {
@Override
public boolean test(ClassInfo classInfo) {
return Modifier.isInterface(classInfo.flags())
|| Modifier.isAbstract(classInfo.flags());
}
};
return new EndpointValidationPredicatesBuildItem(predicate);
}

// We want to add @Typed to resources, beanparams and providers so that they can be resolved as CDI bean using purely their
// class as a bean type. This removes any ambiguity that potential subclasses may have.
@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -268,7 +269,7 @@ protected EndpointIndexer(Builder<T, ?, METHOD> builder) {
this.isDisabledCreator = builder.isDisabledCreator;
this.skipMethodParameter = builder.skipMethodParameter;
this.skipNotRestParameters = builder.skipNotRestParameters;
this.validateEndpoint = builder.validateEndpoint;
this.validateEndpoint = builder.defaultPredicate;
}

public Optional<ResourceClass> createEndpoints(ClassInfo classInfo, boolean considerApplication) {
Expand Down Expand Up @@ -1714,7 +1715,13 @@ public boolean handleMultipartForReturnType(AdditionalWriters additionalWriters,
private Function<ClassInfo, Supplier<Boolean>> isDisabledCreator = null;

private Predicate<Map<DotName, AnnotationInstance>> skipMethodParameter = null;
private List<Predicate<ClassInfo>> validateEndpoint = null;
private List<Predicate<ClassInfo>> defaultPredicate = Arrays.asList(new Predicate<>() {
@Override
public boolean test(ClassInfo classInfo) {
return Modifier.isInterface(classInfo.flags())
|| Modifier.isAbstract(classInfo.flags());
}
});

private boolean skipNotRestParameters = false;

Expand Down Expand Up @@ -1852,7 +1859,10 @@ public B setSkipMethodParameter(
}

public B setValidateEndpoint(List<Predicate<ClassInfo>> validateEndpoint) {
this.validateEndpoint = validateEndpoint;
List<Predicate<ClassInfo>> predicates = new ArrayList<>(validateEndpoint.size() + 1);
predicates.addAll(validateEndpoint);
predicates.addAll(this.defaultPredicate);
this.defaultPredicate = predicates;
return (B) this;
}

Expand Down

0 comments on commit 6221d48

Please sign in to comment.