• 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

90.0
/src/main/java/org/burningwave/reflection/ConstructorCriteria.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.Constructor;
32
import java.util.function.BiPredicate;
33
import java.util.function.Function;
34

35
/**
36
 * A criteria that selects the constructors of a class: since the constructors are not inherited, the search usually
37
 * does not need to scan the superclasses.
38
 * <pre>{@code
39
 * ConstructorCriteria criteria = ConstructorCriteria.withoutConsideringParentClasses().parameterTypesAreAssignableFrom(String.class);
40
 * Collection<Constructor<?>> constructors = Constructors.INSTANCE.findAllAndMakeThemAccessible(criteria, MyClass.class);
41
 * }</pre>
42
 */
43
public class ConstructorCriteria extends ExecutableMemberCriteria<
44
        Constructor<?>, ConstructorCriteria, Criteria.TestContext<Constructor<?>, ConstructorCriteria>
45
> {
46
        private ConstructorCriteria() {
47
                super();
1 ✔
48
        }
1 ✔
49

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

60
        /**
61
         * Creates a criteria that scans the whole hierarchy of the class where the search starts, up to {@link Object}.
62
         *
63
         * @return the new criteria
64
         */
65
        public static ConstructorCriteria forEntireClassHierarchy() {
66
                return new ConstructorCriteria();
×
67
        }
68

69
        /**
70
         * Creates a criteria that does not scan the superclasses of the class where the search starts.
71
         *
72
         * @return the new criteria
73
         */
74
        public static ConstructorCriteria withoutConsideringParentClasses() {
75
                return byScanUpTo((lastClassInHierarchy, currentScannedClass) -> {
1 ✔
76
            return lastClassInHierarchy.equals(currentScannedClass);
1 ✔
77
        });
78
        }
79

80
        @Override
81
        Function<Class<?>, Constructor<?>[]> getMembersSupplierFunction() {
82
                return clazz -> {
1 ✔
83
                        return Cache.INSTANCE.uniqueKeyForConstructorsArray.getOrUploadIfAbsent(
1 ✔
84
                                Constructors.INSTANCE.getCacheKey(clazz, Members.ALL_FOR_CLASS), () -> {
1 ✔
85
                                        return Facade.INSTANCE.getDeclaredConstructors(clazz);
1 ✔
86
                                }
87
                        );
88
                };
89
        }
90

91
}
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