• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

burningwave / reflection / #97

27 Nov 2026 08:15PM UTC coverage: 74.528%. Remained the same
#97

push

Roberto-Gentili
Set the version to 4.6.0-SNAPSHOT. Releasing new version

790 of 1060 relevant lines covered (74.53%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/src/main/java/org/burningwave/reflection/MethodCriteria.java
1
/*
2
 * This file is part of Burningwave Reflection.
3
 *
4
 * Author: Roberto Gentili
5
 *
6
 * Hosted at: https://github.com/burningwave/reflection
7
 *
8
 * --
9
 *
10
 * The MIT License (MIT)
11
 *
12
 * Copyright (c) 2022 Roberto Gentili
13
 *
14
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
15
 * documentation files (the "Software"), to deal in the Software without restriction, including without
16
 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17
 * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
18
 * conditions:
19
 *
20
 * The above copyright notice and this permission notice shall be included in all copies or substantial
21
 * portions of the Software.
22
 *
23
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25
 * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
27
 * OR OTHER DEALINGS IN THE SOFTWARE.
28
 */
29
package org.burningwave.reflection;
30

31
import java.lang.reflect.Method;
32
import java.util.function.BiPredicate;
33
import java.util.function.Function;
34
import java.util.function.Predicate;
35

36

37
/**
38
 * A criteria that selects the methods of a class:
39
 * <pre>{@code
40
 * MethodCriteria criteria = MethodCriteria.forEntireClassHierarchy().name("execute"::equals).and().parameterTypesAreAssignableFrom(String.class);
41
 * Collection<Method> methods = Methods.INSTANCE.findAllAndMakeThemAccessible(criteria, MyClass.class);
42
 * }</pre>
43
 */
44
public class MethodCriteria extends ExecutableMemberCriteria<
45
        Method, MethodCriteria, Criteria.TestContext<Method, MethodCriteria>
46
> {
47

48
        private MethodCriteria() {
49
                super();
1 ✔
50
        }
1 ✔
51

52
        /**
53
         * Creates a criteria that stops scanning the hierarchy after the first class that matches a predicate.
54
         *
55
         * @param predicate the predicate, which receives the class where the search started and the class being scanned
56
         * @return the new criteria
57
         */
58
        public static MethodCriteria byScanUpTo(BiPredicate<Class<?>, Class<?>> predicate) {
59
                return new MethodCriteria().scanUpTo(predicate);
×
60
        }
61

62
        /**
63
         * Creates a criteria that stops scanning the hierarchy after the first class that matches a predicate.
64
         *
65
         * @param predicate the predicate, which receives the class being scanned
66
         * @return the new criteria
67
         */
68
        public static MethodCriteria byScanUpTo(Predicate<Class<?>> predicate) {
69
                return new MethodCriteria().scanUpTo(predicate);
1 ✔
70
        }
71

72
        /**
73
         * Creates a criteria that scans the whole hierarchy of the class where the search starts, up to {@link Object}.
74
         *
75
         * @return the new criteria
76
         */
77
        public static MethodCriteria forEntireClassHierarchy() {
78
                return new MethodCriteria();
1 ✔
79
        }
80

81
        /**
82
         * Creates a criteria that does not scan the superclasses of the class where the search starts.
83
         *
84
         * @return the new criteria
85
         */
86
        public static MethodCriteria withoutConsideringParentClasses() {
87
                return byScanUpTo((lastClassInHierarchy, currentScannedClass) -> {
×
88
            return lastClassInHierarchy.equals(currentScannedClass);
×
89
        });
90
        }
91

92
        /**
93
         * Adds a condition on the return type of the method.
94
         *
95
         * @param predicate the predicate, which receives the return type of the method
96
         * @return this criteria
97
         */
98
        public MethodCriteria returnType(final Predicate<Class<?>> predicate) {
99
                this.predicate = concat(
×
100
                        this.predicate,
101
                        (context, member) -> predicate.test(member.getReturnType())
×
102
                );
103
                return this;
×
104
        }
105

106
        @Override
107
        Function<Class<?>, Method[]> getMembersSupplierFunction() {
108
                return clazz -> {
1 ✔
109
                        final String cacheKey = Constructors.INSTANCE.getCacheKey(clazz, Members.ALL_FOR_CLASS);
1 ✔
110
                        return Cache.INSTANCE.uniqueKeyForMethodsArray.getOrUploadIfAbsent(
1 ✔
111
                                cacheKey, () -> {
112
                                        return Facade.INSTANCE.getDeclaredMethods(clazz);
1 ✔
113
                                }
114
                        );
115
                };
116
        }
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc