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

raphw / byte-buddy / #809

02 Nov 2025 10:24PM UTC coverage: 84.035% (-0.6%) from 84.614%
#809

push

raphw
Clean up code.

5 of 7 new or added lines in 4 files covered. (71.43%)

958 existing lines in 10 files now uncovered.

29803 of 35465 relevant lines covered (84.03%)

0.84 hits per line

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

76.47
/byte-buddy-dep/src/main/java/net/bytebuddy/description/modifier/ModifierContributor.java
1
/*
2
 * Copyright 2014 - Present Rafael Winterhalter
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.bytebuddy.description.modifier;
17

18
import net.bytebuddy.build.HashCodeAndEqualsPlugin;
19
import org.objectweb.asm.Opcodes;
20

21
import java.util.Arrays;
22
import java.util.Collection;
23

24
/**
25
 * An element that describes a type modifier as described in the
26
 * <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html">JVMS</a>.
27
 * <p>&nbsp;</p>
28
 * This allows for a more expressive and type safe alternative of defining a type's or type member's modifiers.
29
 * However, note that modifier's that apply competing modifiers (such as {@code private} and {@code protected}
30
 * should not be combined and will result in invalid types. An exception is thrown when built-in modifiers that
31
 * cannot be combined are used together.
32
 */
33
public interface ModifierContributor {
34

35
    /**
36
     * The empty modifier.
37
     */
38
    int EMPTY_MASK = 0;
39

40
    /**
41
     * Returns the mask of this modifier.
42
     *
43
     * @return The modifier mask that is to be applied to the target type or type member.
44
     */
45
    int getMask();
46

47
    /**
48
     * Returns the entire range of modifiers that address this contributor's property.
49
     *
50
     * @return The range of this contributor's property.
51
     */
52
    int getRange();
53

54
    /**
55
     * Determines if this is the default modifier.
56
     *
57
     * @return {@code true} if this contributor represents the default modifier.
58
     */
59
    boolean isDefault();
60

61
    /**
62
     * A marker interface for modifiers that can be applied to types.
63
     */
64
    interface ForType extends ModifierContributor {
65

66
        /**
67
         * A mask for all legal modifiers of a Java type.
68
         */
69
        int MASK = Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC
70
                | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_ANNOTATION | Opcodes.ACC_DEPRECATED
71
                | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC | Opcodes.ACC_STRICT;
72
    }
73

74
    /**
75
     * A marker interface for modifiers that can be applied to modules.
76
     */
77
    interface ForModule extends ModifierContributor {
78

79
        /**
80
         * A mask for all legal modifiers of a Java module.
81
         */
82
        int MASK = Opcodes.ACC_OPEN | Opcodes.ACC_MANDATED | Opcodes.ACC_SYNTHETIC;
83

84
        /**
85
         * A marker interface for modifiers that can be applied to module requirement.
86
         */
87
        interface OfRequire extends ModifierContributor {
88

89
            /**
90
             * A mask for all legal modifiers of a Java module requirement.
91
             */
92
            int MASK = Opcodes.ACC_TRANSITIVE | Opcodes.ACC_MANDATED | Opcodes.ACC_SYNTHETIC;
93
        }
94

95
        /**
96
         * A marker interface for modifiers that can be applied to module exports.
97
         */
98
        interface OfExport extends ModifierContributor {
99

100
            /**
101
             * A mask for all legal modifiers of a Java module export.
102
             */
103
            int MASK = Opcodes.ACC_STATIC_PHASE | Opcodes.ACC_MANDATED | Opcodes.ACC_SYNTHETIC;
104
        }
105

106
        /**
107
         * A marker interface for modifiers that can be applied to module opening.
108
         */
109
        interface OfOpen extends ModifierContributor {
110

111
            /**
112
             * A mask for all legal modifiers of a Java module opening.
113
             */
114
            int MASK = Opcodes.ACC_STATIC_PHASE | Opcodes.ACC_MANDATED | Opcodes.ACC_SYNTHETIC;
115
        }
116
    }
117

118
    /**
119
     * A marker interface for modifiers that can be applied to fields.
120
     */
121
    interface ForField extends ModifierContributor {
122

123
        /**
124
         * A mask for all legal modifiers of a Java field.
125
         */
126
        int MASK = Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE
127
                | Opcodes.ACC_DEPRECATED | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC
128
                | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_TRANSIENT | Opcodes.ACC_VOLATILE;
129
    }
130

131
    /**
132
     * A marker interface for modifiers that can be applied to methods.
133
     */
134
    interface ForMethod extends ModifierContributor {
135

136
        /**
137
         * A mask for all legal modifiers of a Java method.
138
         */
139
        int MASK = Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE | Opcodes.ACC_SYNTHETIC
140
                | Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL | Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT
141
                | Opcodes.ACC_STATIC | Opcodes.ACC_STRICT | Opcodes.ACC_SYNCHRONIZED
142
                | Opcodes.ACC_VARARGS;
143
    }
144

145
    /**
146
     * A marker interface for modifiers that can be applied to method parameters.
147
     */
148
    interface ForParameter extends ModifierContributor {
149

150
        /**
151
         * A mask for all legal modifiers of a Java parameter.
152
         */
153
        int MASK = Opcodes.ACC_MANDATED | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC;
154

155
    }
156

157
    /**
158
     * A resolver for Java modifiers represented by {@link ModifierContributor}s.
159
     *
160
     * @param <T> The type of the {@link ModifierContributor}s being resolved.
161
     */
162
    @HashCodeAndEqualsPlugin.Enhance
163
    class Resolver<T extends ModifierContributor> {
164

165
        /**
166
         * The modifier contributors to resolve.
167
         */
168
        private final Collection<? extends T> modifierContributors;
169

170
        /**
171
         * Creates a new resolver.
172
         *
173
         * @param modifierContributors The modifier contributors to resolve.
174
         */
175
        protected Resolver(Collection<? extends T> modifierContributors) {
1✔
176
            this.modifierContributors = modifierContributors;
1✔
177
        }
1✔
178

179
        /**
180
         * Creates a new resolver for modifier contributors to a type.
181
         *
182
         * @param modifierContributor The modifier contributors to resolve.
183
         * @return A resolver for the provided modifier contributors.
184
         */
185
        public static Resolver<ForType> of(ForType... modifierContributor) {
186
            return of(Arrays.asList(modifierContributor));
1✔
187
        }
188

189
        /**
190
         * Creates a new resolver for modifier contributors to a module.
191
         *
192
         * @param modifierContributor The modifier contributors to resolve.
193
         * @return A resolver for the provided modifier contributors.
194
         */
195
        public static Resolver<ForModule> of(ForModule... modifierContributor) {
UNCOV
196
            return of(Arrays.asList(modifierContributor));
×
197
        }
198

199
        /**
200
         * Creates a new resolver for modifier contributors to a module requirement.
201
         *
202
         * @param modifierContributor The modifier contributors to resolve.
203
         * @return A resolver for the provided modifier contributors.
204
         */
205
        public static Resolver<ForModule.OfRequire> of(ForModule.OfRequire... modifierContributor) {
UNCOV
206
            return of(Arrays.asList(modifierContributor));
×
207
        }
208

209
        /**
210
         * Creates a new resolver for modifier contributors to a module export.
211
         *
212
         * @param modifierContributor The modifier contributors to resolve.
213
         * @return A resolver for the provided modifier contributors.
214
         */
215
        public static Resolver<ForModule.OfExport> of(ForModule.OfExport... modifierContributor) {
UNCOV
216
            return of(Arrays.asList(modifierContributor));
×
217
        }
218

219
        /**
220
         * Creates a new resolver for modifier contributors to a module opening.
221
         *
222
         * @param modifierContributor The modifier contributors to resolve.
223
         * @return A resolver for the provided modifier contributors.
224
         */
225
        public static Resolver<ForModule.OfOpen> of(ForModule.OfOpen... modifierContributor) {
UNCOV
226
            return of(Arrays.asList(modifierContributor));
×
227
        }
228

229
        /**
230
         * Creates a new resolver for modifier contributors to a field.
231
         *
232
         * @param modifierContributor The modifier contributors to resolve.
233
         * @return A resolver for the provided modifier contributors.
234
         */
235
        public static Resolver<ForField> of(ForField... modifierContributor) {
236
            return of(Arrays.asList(modifierContributor));
1✔
237
        }
238

239
        /**
240
         * Creates a new resolver for modifier contributors to a method.
241
         *
242
         * @param modifierContributor The modifier contributors to resolve.
243
         * @return A resolver for the provided modifier contributors.
244
         */
245
        public static Resolver<ForMethod> of(ForMethod... modifierContributor) {
246
            return of(Arrays.asList(modifierContributor));
1✔
247
        }
248

249
        /**
250
         * Creates a new resolver for modifier contributors to a parameter.
251
         *
252
         * @param modifierContributor The modifier contributors to resolve.
253
         * @return A resolver for the provided modifier contributors.
254
         */
255
        public static Resolver<ForParameter> of(ForParameter... modifierContributor) {
256
            return Resolver.of(Arrays.asList(modifierContributor));
1✔
257
        }
258

259
        /**
260
         * Creates a new resolver for any modifier contributor of a given type.
261
         *
262
         * @param modifierContributors The modifier contributors to resolve.
263
         * @param <S>                  The modifier contributors type.
264
         * @return A resolver for the provided modifier contributors.
265
         */
266
        public static <S extends ModifierContributor> Resolver<S> of(Collection<? extends S> modifierContributors) {
267
            return new Resolver<S>(modifierContributors);
1✔
268
        }
269

270
        /**
271
         * Resolves the modifier contributors based on a zero modifier.
272
         *
273
         * @return The resolved modifiers.
274
         */
275
        public int resolve() {
276
            return resolve(EMPTY_MASK);
1✔
277
        }
278

279
        /**
280
         * Resolves the modifier contributors based on a given modifier.
281
         *
282
         * @param modifiers The base modifiers.
283
         * @return The resolved modifiers.
284
         */
285
        public int resolve(int modifiers) {
286
            for (T modifierContributor : modifierContributors) {
1✔
287
                modifiers = (modifiers & ~modifierContributor.getRange()) | modifierContributor.getMask();
1✔
288
            }
1✔
289
            return modifiers;
1✔
290
        }
291
    }
292
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc