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

raphw / byte-buddy / #801

27 Oct 2025 09:37AM UTC coverage: 84.715% (-0.4%) from 85.118%
#801

push

raphw
Fix imports.

29586 of 34924 relevant lines covered (84.72%)

0.85 hits per line

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

86.76
/byte-buddy-dep/src/main/java/net/bytebuddy/description/ModifierReviewable.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;
17

18
import net.bytebuddy.description.modifier.EnumerationState;
19
import net.bytebuddy.description.modifier.FieldManifestation;
20
import net.bytebuddy.description.modifier.FieldPersistence;
21
import net.bytebuddy.description.modifier.MethodManifestation;
22
import net.bytebuddy.description.modifier.MethodStrictness;
23
import net.bytebuddy.description.modifier.Ownership;
24
import net.bytebuddy.description.modifier.ParameterManifestation;
25
import net.bytebuddy.description.modifier.ProvisioningState;
26
import net.bytebuddy.description.modifier.SynchronizationState;
27
import net.bytebuddy.description.modifier.SyntheticState;
28
import net.bytebuddy.description.modifier.TypeManifestation;
29
import net.bytebuddy.description.modifier.Visibility;
30
import org.objectweb.asm.Opcodes;
31

32
/**
33
 * Implementations of this interface can be described in terms of a Java modifier.
34
 */
35
public interface ModifierReviewable {
36

37
    /**
38
     * Representation of the default modifier.
39
     */
40
    int EMPTY_MASK = 0;
41

42
    /**
43
     * Returns the modifier that is described by this object.
44
     *
45
     * @return The modifier that is described by this object.
46
     */
47
    int getModifiers();
48

49
    /**
50
     * Specifies if the modifier described by this object is {@code final}.
51
     *
52
     * @return {@code true} if the modifier described by this object is {@code final}.
53
     */
54
    boolean isFinal();
55

56
    /**
57
     * Specifies if the modifier described by this object is synthetic.
58
     *
59
     * @return {@code true} if the modifier described by this object is synthetic.
60
     */
61
    boolean isSynthetic();
62

63
    /**
64
     * Returns this objects synthetic state.
65
     *
66
     * @return This objects synthetic state.
67
     */
68
    SyntheticState getSyntheticState();
69

70
    /**
71
     * A modifier reviewable for a {@link ByteCodeElement}, i.e. a type, a field or a method.
72
     */
73
    interface OfByteCodeElement extends ModifierReviewable {
74

75
        /**
76
         * Specifies if the modifier described by this object is {@code public}.
77
         *
78
         * @return {@code true} if the modifier described by this object is {@code public}.
79
         */
80
        boolean isPublic();
81

82
        /**
83
         * Specifies if the modifier described by this object is {@code protected}.
84
         *
85
         * @return {@code true} if the modifier described by this object is {@code protected}.
86
         */
87
        boolean isProtected();
88

89
        /**
90
         * Specifies if the modifier described by this object is package private.
91
         *
92
         * @return {@code true} if the modifier described by this object is package private.
93
         */
94
        boolean isPackagePrivate();
95

96
        /**
97
         * Specifies if the modifier described by this object is {@code private}.
98
         *
99
         * @return {@code true} if the modifier described by this object is {@code private}.
100
         */
101
        boolean isPrivate();
102

103
        /**
104
         * Specifies if the modifier described by this object is {@code static}.
105
         *
106
         * @return {@code true} if the modifier described by this object is {@code static}.
107
         */
108
        boolean isStatic();
109

110
        /**
111
         * Specifies if the modifier described by this object represents the deprecated flag.
112
         *
113
         * @return {@code true} if the modifier described by this object represents the deprecated flag.
114
         */
115
        boolean isDeprecated();
116

117
        /**
118
         * Return's this byte code element's ownership.
119
         *
120
         * @return This byte code element's ownership.
121
         */
122
        Ownership getOwnership();
123

124
        /**
125
         * Returns this byte code element's visibility.
126
         *
127
         * @return This byte code element's visibility.
128
         */
129
        Visibility getVisibility();
130
    }
131

132
    /**
133
     * A modifier reviewable for a byte code element that can be abstract, i.e. a {@link net.bytebuddy.description.type.TypeDescription}
134
     * or a {@link net.bytebuddy.description.method.MethodDescription}.
135
     */
136
    interface OfAbstraction extends OfByteCodeElement {
137

138
        /**
139
         * Specifies if the modifier described by this object is {@code abstract}.
140
         *
141
         * @return {@code true} if the modifier described by this object is {@code abstract}.
142
         */
143
        boolean isAbstract();
144
    }
145

146
    /**
147
     * A modifier reviewable for a byte code element that can represent an enumeration, i.e. a {@link net.bytebuddy.description.field.FieldDescription}
148
     * that holds an enumeration value or a {@link net.bytebuddy.description.type.TypeDescription} that represents an enumeration.
149
     */
150
    interface OfEnumeration extends OfByteCodeElement {
151

152
        /**
153
         * Specifies if the modifier described by this object represents the enum flag.
154
         *
155
         * @return {@code true} if the modifier described by this object represents the enum flag.
156
         */
157
        boolean isEnum();
158

159
        /**
160
         * Returns this byte code element's enumeration state.
161
         *
162
         * @return This byte code element's enumeration state.
163
         */
164
        EnumerationState getEnumerationState();
165
    }
166

167
    /**
168
     * A modifier reviewable for elements that can be mandated.
169
     */
170
    interface OfMandatable extends ModifierReviewable {
171

172
        /**
173
         * Specifies if the modifier described by this object is mandated.
174
         *
175
         * @return {@code true} if the modifier described by this object is mandated.
176
         */
177
        boolean isMandated();
178
    }
179

180
    /**
181
     * A modifier reviewable for a {@link net.bytebuddy.description.type.TypeDescription}.
182
     */
183
    interface ForTypeDefinition extends OfAbstraction, OfEnumeration {
184

185
        /**
186
         * Specifies if the modifier described by this object represents the interface flag.
187
         *
188
         * @return {@code true} if the modifier described by this object represents the interface flag.
189
         */
190
        boolean isInterface();
191

192
        /**
193
         * Specifies if the modifier described by this object represents the annotation flag.
194
         *
195
         * @return {@code true} if the modifier described by this object represents the annotation flag.
196
         */
197
        boolean isAnnotation();
198

199
        /**
200
         * Returns this type's manifestation.
201
         *
202
         * @return This type's manifestation.
203
         */
204
        TypeManifestation getTypeManifestation();
205
    }
206

207
    /**
208
     * A modifier reviewable for a {@link net.bytebuddy.description.field.FieldDescription}.
209
     */
210
    interface ForFieldDescription extends OfEnumeration {
211

212
        /**
213
         * Specifies if the modifier described by this object represents the volatile flag.
214
         *
215
         * @return {@code true} if the modifier described by this object represents the volatile flag.
216
         */
217
        boolean isVolatile();
218

219
        /**
220
         * Specifies if the modifier described by this object represents the transient flag.
221
         *
222
         * @return {@code true} if the modifier described by this object represents the transient flag.
223
         */
224
        boolean isTransient();
225

226
        /**
227
         * Returns this field's manifestation.
228
         *
229
         * @return This field's manifestation.
230
         */
231
        FieldManifestation getFieldManifestation();
232

233
        /**
234
         * Returns this field's persistence.
235
         *
236
         * @return This field's persistence.
237
         */
238
        FieldPersistence getFieldPersistence();
239
    }
240

241
    /**
242
     * A modifier reviewable for a {@link net.bytebuddy.description.method.MethodDescription}.
243
     */
244
    interface ForMethodDescription extends OfAbstraction {
245

246
        /**
247
         * Specifies if the modifier described by this object is {@code synchronized}.
248
         *
249
         * @return {@code true} if the modifier described by this object is {@code synchronized}.
250
         */
251
        boolean isSynchronized();
252

253
        /**
254
         * Specifies if the modifier described by this object represents the var args flag.
255
         *
256
         * @return {@code true} if the modifier described by this object represents the var args flag.
257
         */
258
        boolean isVarArgs();
259

260
        /**
261
         * Specifies if the modifier described by this object is {@code native}.
262
         *
263
         * @return {@code true} if the modifier described by this object is {@code native}.
264
         */
265
        boolean isNative();
266

267
        /**
268
         * Specifies if the modifier described by this object represents the bridge flag.
269
         *
270
         * @return {@code true} if the modifier described by this object represents the bridge flag
271
         */
272
        boolean isBridge();
273

274
        /**
275
         * Specifies if the modifier described by this object is {@code strictfp}.
276
         *
277
         * @return {@code true} if the modifier described by this object is {@code strictfp}.
278
         */
279
        boolean isStrict();
280

281
        /**
282
         * Returns this method's synchronization state.
283
         *
284
         * @return This method's synchronization state.
285
         */
286
        SynchronizationState getSynchronizationState();
287

288
        /**
289
         * Returns this method's strictness in floating-point computation.
290
         *
291
         * @return This method's strictness in floating-point computation.
292
         */
293
        MethodStrictness getMethodStrictness();
294

295
        /**
296
         * Returns this method's manifestation.
297
         *
298
         * @return This method's manifestation.
299
         */
300
        MethodManifestation getMethodManifestation();
301
    }
302

303
    /**
304
     * A modifier reviewable for a {@link net.bytebuddy.description.method.ParameterDescription}.
305
     */
306
    interface ForParameterDescription extends OfMandatable {
307

308
        /**
309
         * Returns this parameter's manifestation.
310
         *
311
         * @return This parameter's manifestation.
312
         */
313
        ParameterManifestation getParameterManifestation();
314

315
        /**
316
         * Returns this parameter's provisioning state.
317
         *
318
         * @return This parameter's provisioning state.
319
         */
320
        ProvisioningState getProvisioningState();
321
    }
322

323
    /**
324
     * Declares modifiers as they can be observed on a Java module.
325
     */
326
    interface ForModuleDescription extends ModifierReviewable {
327

328
        /**
329
         * Returns {@code true} if the module is open.
330
         *
331
         * @return {@code true} if the module is open.
332
         */
333
        boolean isOpen();
334
    }
335

336
    /**
337
     * Declares modifiers as they can be observed on a module requirement declaration.
338
     */
339
    interface ForModuleRequirement extends OfMandatable {
340

341
        /**
342
         * Returns {@code true} if the module requirement is transitive.
343
         *
344
         * @return {@code true} if the module requirement is transitive.
345
         */
346
        boolean isTransitive();
347

348
        /**
349
         * Returns {@code true} if the module requirement is during the static phase only.
350
         *
351
         * @return {@code true} if the module requirement is during the static phase only.
352
         */
353
        boolean isStaticPhase();
354
    }
355

356
    /**
357
     * An abstract base implementation of a {@link ModifierReviewable} class.
358
     */
359
    abstract class AbstractBase implements ForTypeDefinition,
1✔
360
            ForFieldDescription,
361
            ForMethodDescription,
362
            ForParameterDescription,
363
            ForModuleDescription,
364
            ForModuleRequirement {
365

366
        /**
367
         * {@inheritDoc}
368
         */
369
        public boolean isAbstract() {
370
            return matchesMask(Opcodes.ACC_ABSTRACT);
1✔
371
        }
372

373
        /**
374
         * {@inheritDoc}
375
         */
376
        public boolean isFinal() {
377
            return matchesMask(Opcodes.ACC_FINAL);
1✔
378
        }
379

380
        /**
381
         * {@inheritDoc}
382
         */
383
        public boolean isStatic() {
384
            return matchesMask(Opcodes.ACC_STATIC);
1✔
385
        }
386

387
        /**
388
         * {@inheritDoc}
389
         */
390
        public boolean isPublic() {
391
            return matchesMask(Opcodes.ACC_PUBLIC);
1✔
392
        }
393

394
        /**
395
         * {@inheritDoc}
396
         */
397
        public boolean isProtected() {
398
            return matchesMask(Opcodes.ACC_PROTECTED);
1✔
399
        }
400

401
        /**
402
         * {@inheritDoc}
403
         */
404
        public boolean isPackagePrivate() {
405
            return !isPublic() && !isProtected() && !isPrivate();
1✔
406
        }
407

408
        /**
409
         * {@inheritDoc}
410
         */
411
        public boolean isPrivate() {
412
            return matchesMask(Opcodes.ACC_PRIVATE);
1✔
413
        }
414

415
        /**
416
         * {@inheritDoc}
417
         */
418
        public boolean isNative() {
419
            return matchesMask(Opcodes.ACC_NATIVE);
1✔
420
        }
421

422
        /**
423
         * {@inheritDoc}
424
         */
425
        public boolean isSynchronized() {
426
            return matchesMask(Opcodes.ACC_SYNCHRONIZED);
1✔
427
        }
428

429
        /**
430
         * {@inheritDoc}
431
         */
432
        public boolean isStrict() {
433
            return matchesMask(Opcodes.ACC_STRICT);
1✔
434
        }
435

436
        /**
437
         * {@inheritDoc}
438
         */
439
        public boolean isMandated() {
440
            return matchesMask(Opcodes.ACC_MANDATED);
1✔
441
        }
442

443
        /**
444
         * {@inheritDoc}
445
         */
446
        public boolean isSynthetic() {
447
            return matchesMask(Opcodes.ACC_SYNTHETIC);
1✔
448
        }
449

450
        /**
451
         * {@inheritDoc}
452
         */
453
        public boolean isBridge() {
454
            return matchesMask(Opcodes.ACC_BRIDGE);
1✔
455
        }
456

457
        /**
458
         * {@inheritDoc}
459
         */
460
        public boolean isDeprecated() {
461
            return matchesMask(Opcodes.ACC_DEPRECATED);
1✔
462
        }
463

464
        /**
465
         * {@inheritDoc}
466
         */
467
        public boolean isAnnotation() {
468
            return matchesMask(Opcodes.ACC_ANNOTATION);
1✔
469
        }
470

471
        /**
472
         * {@inheritDoc}
473
         */
474
        public boolean isEnum() {
475
            return matchesMask(Opcodes.ACC_ENUM);
1✔
476
        }
477

478
        /**
479
         * {@inheritDoc}
480
         */
481
        public boolean isInterface() {
482
            return matchesMask(Opcodes.ACC_INTERFACE);
1✔
483
        }
484

485
        /**
486
         * {@inheritDoc}
487
         */
488
        public boolean isTransient() {
489
            return matchesMask(Opcodes.ACC_TRANSIENT);
1✔
490
        }
491

492
        /**
493
         * {@inheritDoc}
494
         */
495
        public boolean isVolatile() {
496
            return matchesMask(Opcodes.ACC_VOLATILE);
1✔
497
        }
498

499
        /**
500
         * {@inheritDoc}
501
         */
502
        public boolean isVarArgs() {
503
            return matchesMask(Opcodes.ACC_VARARGS);
1✔
504
        }
505

506
        /**
507
         * {@inheritDoc}
508
         */
509
        public boolean isOpen() {
510
            return matchesMask(Opcodes.ACC_OPEN);
×
511
        }
512

513
        /**
514
         * {@inheritDoc}
515
         */
516
        public boolean isStaticPhase() {
517
            return matchesMask(Opcodes.ACC_STATIC_PHASE);
×
518
        }
519

520
        /**
521
         * {@inheritDoc}
522
         */
523
        public boolean isTransitive() {
524
            return matchesMask(Opcodes.ACC_TRANSITIVE);
×
525
        }
526

527
        /**
528
         * {@inheritDoc}
529
         */
530
        public SyntheticState getSyntheticState() {
531
            return isSynthetic()
1✔
532
                    ? SyntheticState.SYNTHETIC
533
                    : SyntheticState.PLAIN;
534
        }
535

536
        /**
537
         * {@inheritDoc}
538
         */
539
        public Visibility getVisibility() {
540
            int modifiers = getModifiers();
1✔
541
            switch (modifiers & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) {
1✔
542
                case Opcodes.ACC_PUBLIC:
543
                    return Visibility.PUBLIC;
1✔
544
                case Opcodes.ACC_PROTECTED:
545
                    return Visibility.PROTECTED;
1✔
546
                case EMPTY_MASK:
547
                    return Visibility.PACKAGE_PRIVATE;
1✔
548
                case Opcodes.ACC_PRIVATE:
549
                    return Visibility.PRIVATE;
1✔
550
                default:
551
                    throw new IllegalStateException("Unexpected modifiers: " + modifiers);
×
552
            }
553
        }
554

555
        /**
556
         * {@inheritDoc}
557
         */
558
        public Ownership getOwnership() {
559
            return isStatic()
1✔
560
                    ? Ownership.STATIC
561
                    : Ownership.MEMBER;
562
        }
563

564
        /**
565
         * {@inheritDoc}
566
         */
567
        public EnumerationState getEnumerationState() {
568
            return isEnum()
1✔
569
                    ? EnumerationState.ENUMERATION
570
                    : EnumerationState.PLAIN;
571
        }
572

573
        /**
574
         * {@inheritDoc}
575
         */
576
        public TypeManifestation getTypeManifestation() {
577
            int modifiers = getModifiers();
1✔
578
            switch (modifiers & (Opcodes.ACC_ANNOTATION | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_FINAL)) {
1✔
579
                case Opcodes.ACC_FINAL:
580
                    return TypeManifestation.FINAL;
1✔
581
                case Opcodes.ACC_ABSTRACT:
582
                    return TypeManifestation.ABSTRACT;
1✔
583
                case Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE:
584
                    return TypeManifestation.INTERFACE;
1✔
585
                case Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE | Opcodes.ACC_ANNOTATION:
586
                    return TypeManifestation.ANNOTATION;
1✔
587
                case EMPTY_MASK:
588
                    return TypeManifestation.PLAIN;
1✔
589
                default:
590
                    throw new IllegalStateException("Unexpected modifiers: " + modifiers);
×
591
            }
592
        }
593

594
        /**
595
         * {@inheritDoc}
596
         */
597
        public FieldManifestation getFieldManifestation() {
598
            int modifiers = getModifiers();
1✔
599
            switch (modifiers & (Opcodes.ACC_VOLATILE | Opcodes.ACC_FINAL)) {
1✔
600
                case Opcodes.ACC_FINAL:
601
                    return FieldManifestation.FINAL;
1✔
602
                case Opcodes.ACC_VOLATILE:
603
                    return FieldManifestation.VOLATILE;
1✔
604
                case EMPTY_MASK:
605
                    return FieldManifestation.PLAIN;
×
606
                default:
607
                    throw new IllegalStateException("Unexpected modifiers: " + modifiers);
×
608
            }
609
        }
610

611
        /**
612
         * {@inheritDoc}
613
         */
614
        public FieldPersistence getFieldPersistence() {
615
            int modifiers = getModifiers();
1✔
616
            switch (modifiers & Opcodes.ACC_TRANSIENT) {
1✔
617
                case Opcodes.ACC_TRANSIENT:
618
                    return FieldPersistence.TRANSIENT;
1✔
619
                case EMPTY_MASK:
620
                    return FieldPersistence.PLAIN;
1✔
621
                default:
622
                    throw new IllegalStateException("Unexpected modifiers: " + modifiers);
×
623
            }
624
        }
625

626
        /**
627
         * {@inheritDoc}
628
         */
629
        public SynchronizationState getSynchronizationState() {
630
            return isSynchronized()
1✔
631
                    ? SynchronizationState.SYNCHRONIZED
632
                    : SynchronizationState.PLAIN;
633
        }
634

635
        /**
636
         * {@inheritDoc}
637
         */
638
        public MethodManifestation getMethodManifestation() {
639
            int modifiers = getModifiers();
1✔
640
            switch (modifiers & (Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_FINAL | Opcodes.ACC_BRIDGE)) {
1✔
641
                case Opcodes.ACC_NATIVE | Opcodes.ACC_FINAL:
642
                    return MethodManifestation.FINAL_NATIVE;
1✔
643
                case Opcodes.ACC_NATIVE:
644
                    return MethodManifestation.NATIVE;
1✔
645
                case Opcodes.ACC_FINAL:
646
                    return MethodManifestation.FINAL;
1✔
647
                case Opcodes.ACC_BRIDGE:
648
                    return MethodManifestation.BRIDGE;
1✔
649
                case Opcodes.ACC_BRIDGE | Opcodes.ACC_FINAL:
650
                    return MethodManifestation.FINAL_BRIDGE;
1✔
651
                case Opcodes.ACC_ABSTRACT:
652
                    return MethodManifestation.ABSTRACT;
1✔
653
                case EMPTY_MASK:
654
                    return MethodManifestation.PLAIN;
1✔
655
                default:
656
                    throw new IllegalStateException("Unexpected modifiers: " + modifiers);
×
657
            }
658
        }
659

660
        /**
661
         * {@inheritDoc}
662
         */
663
        public MethodStrictness getMethodStrictness() {
664
            return isStrict()
1✔
665
                    ? MethodStrictness.STRICT
666
                    : MethodStrictness.PLAIN;
667
        }
668

669
        /**
670
         * {@inheritDoc}
671
         */
672
        public ParameterManifestation getParameterManifestation() {
673
            return isFinal()
1✔
674
                    ? ParameterManifestation.FINAL
675
                    : ParameterManifestation.PLAIN;
676
        }
677

678
        /**
679
         * {@inheritDoc}
680
         */
681
        public ProvisioningState getProvisioningState() {
682
            return isMandated()
1✔
683
                    ? ProvisioningState.MANDATED
684
                    : ProvisioningState.PLAIN;
685
        }
686

687
        /**
688
         * Checks if a mask is matched by this instance.
689
         *
690
         * @param mask The mask to check.
691
         * @return {@code true} if the mask is matched.
692
         */
693
        private boolean matchesMask(int mask) {
694
            return (getModifiers() & mask) == mask;
1✔
695
        }
696
    }
697
}
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