Debian Codegraph @

api/src/main/java/jakarta/enterprise/inject/spi/configurator/AnnotatedMethodConfigurator.java

raw
1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2016, Red Hat, Inc., and individual contributors
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package jakarta.enterprise.inject.spi.configurator;
18
19 import java.lang.annotation.Annotation;
20 import java.util.List;
21 import java.util.function.Predicate;
22 import java.util.stream.Stream;
23
24 import jakarta.enterprise.inject.spi.AnnotatedMethod;
25 import jakarta.enterprise.inject.spi.AnnotatedParameter;
26
27 /**
28 * This interface is part of the {@link AnnotatedTypeConfigurator} SPI and helps defining an {@link AnnotatedMethod}
29 *
30 * <p>CDI Lite implementations are not required to provide support for Portable Extensions.</p>
31 *
32 * @author Martin Kouba
33 * @author Antoine Sabot-Durand
34 * @since 2.0
35 * @param <T> the class declaring the method
36 */
37 public interface AnnotatedMethodConfigurator<T> {
38
39 /**
40 *
41 * @return the original {@link AnnotatedMethod}
42 */
43 AnnotatedMethod<T> getAnnotated();
44
45 /**
46 * Add an annotation to the method.
47 *
48 * @param annotation the annotation to add
49 * @return self
50 */
51 AnnotatedMethodConfigurator<T> add(Annotation annotation);
52
53 /**
54 * Remove annotations that match the specified predicate.
55 *
56 * <p>
57 * Example predicates:
58 * </p>
59 *
60 * <pre>
61 * {@code
62 * // To remove all the annotations:
63 * (a) -> true
64 *
65 * // To remove annotations with a concrete annotation type:
66 * (a) -> a.annotationType().equals(Foo.class)
67 *
68 * // To remove annotation equal to a specified object:
69 * (a) -> a.equals(fooAnnotation)
70 *
71 * // To remove annotations that are considered equivalent for the purposes of typesafe resolution:
72 * (a) -> beanManager.areQualifiersEquivalent(a, fooQualifier)
73 * (a) -> beanManager.areInterceptorBindingsEquivalent(a, fooInterceptorBinding)
74 * }
75 * </pre>
76 *
77 * @param predicate {@link Predicate} used to filter annotations to remove
78 * @return self
79 */
80 AnnotatedMethodConfigurator<T> remove(Predicate<Annotation> predicate);
81
82 /**
83 * Remove all the annotations.
84 *
85 * @return self
86 */
87 default AnnotatedMethodConfigurator<T> removeAll() {
88 return remove((a) -> true);
89 }
90
91 /**
92 *
93 * @return an immutable list of {@link AnnotatedParameterConfigurator}s reflecting the
94 * {@link AnnotatedMethod#getParameters()}
95 */
96 List<AnnotatedParameterConfigurator<T>> params();
97
98 /**
99 *
100 * @param predicate Testing the original {@link AnnotatedParameter}
101 * @return a sequence of {@link AnnotatedParameterConfigurator}s matching the given predicate
102 * @see AnnotatedParameterConfigurator#getAnnotated()
103 */
104 default Stream<AnnotatedParameterConfigurator<T>> filterParams(Predicate<AnnotatedParameter<T>> predicate) {
105 return params().stream().filter(p -> predicate.test(p.getAnnotated()));
106 }
107
108 }