• 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

53.85
/src/main/java/org/burningwave/reflection/FieldCriteria.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.Field;
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 fields of a class:
39
 * <pre>{@code
40
 * FieldCriteria criteria = FieldCriteria.forEntireClassHierarchy().name("value"::equals).and().type(String.class::equals);
41
 * Collection<Field> fields = Fields.INSTANCE.findAllAndMakeThemAccessible(criteria, MyClass.class);
42
 * }</pre>
43
 */
44
public class FieldCriteria extends MemberCriteria<
45
        Field, FieldCriteria, Criteria.TestContext<Field, FieldCriteria>
46
> {
47
        private FieldCriteria() {
48
                super();
1 ✔
49
        }
1 ✔
50

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

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

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

81
        /**
82
         * Adds a condition on the type of the field.
83
         *
84
         * @param predicate the predicate, which receives the type of the field
85
         * @return this criteria
86
         */
87
        public FieldCriteria type(final Predicate<Class<?>> predicate) {
88
                this.predicate = concat(
×
89
                        this.predicate,
90
                        (context, member) -> predicate.test(member.getType())
×
91
                );
92
                return this;
×
93
        }
94

95

96
        @Override
97
        Function<Class<?>, Field[]> getMembersSupplierFunction() {
98
                return clazz -> {
1 ✔
99
                        final String cacheKey = Constructors.INSTANCE.getCacheKey(clazz, Members.ALL_FOR_CLASS);
1 ✔
100
                        return Cache.INSTANCE.uniqueKeyForFieldsArray.getOrUploadIfAbsent(
1 ✔
101
                                cacheKey, () -> {
102
                                        return Facade.INSTANCE.getDeclaredFields(clazz);
1 ✔
103
                                }
104
                        );
105
                };
106
        }
107
}
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