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

raphw / byte-buddy / #805

29 Oct 2025 10:00AM UTC coverage: 84.915% (-0.05%) from 84.961%
#805

push

raphw
Fix generic witness.

0 of 1 new or added line in 1 file covered. (0.0%)

158 existing lines in 3 files now uncovered.

29779 of 35069 relevant lines covered (84.92%)

0.85 hits per line

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

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

18
import net.bytebuddy.build.AccessControllerPlugin;
19
import net.bytebuddy.description.ModifierReviewable;
20
import net.bytebuddy.description.NamedElement;
21
import net.bytebuddy.description.annotation.AnnotationList;
22
import net.bytebuddy.description.annotation.AnnotationSource;
23
import net.bytebuddy.utility.dispatcher.JavaDispatcher;
24
import net.bytebuddy.utility.nullability.AlwaysNull;
25
import net.bytebuddy.utility.nullability.MaybeNull;
26
import org.objectweb.asm.Opcodes;
27

28
import java.lang.reflect.AnnotatedElement;
29
import java.security.PrivilegedAction;
30
import java.util.LinkedHashMap;
31
import java.util.LinkedHashSet;
32
import java.util.List;
33
import java.util.Map;
34
import java.util.Set;
35

36
/**
37
 * Description of a named Java {@code java.lang.Module}.
38
 */
39
public interface ModuleDescription extends NamedElement,
40
        ModifierReviewable.ForModuleDescription,
41
        AnnotationSource {
42

43
    /**
44
     * Defines a module that is not resolved.
45
     */
46
    @AlwaysNull
47
    ModuleDescription UNDEFINED = null;
1✔
48

49
    /**
50
     * Returns the version of this module.
51
     *
52
     * @return The module's version or {@code null} if no version is specified.
53
     */
54
    @MaybeNull
55
    String getVersion();
56

57
    /**
58
     * Returns the main class of this module.
59
     *
60
     * @return The module's main class or {@code null} if no main class is specified.
61
     */
62
    @MaybeNull
63
    String getMainClass();
64

65
    /**
66
     * Returns all packages contained in this module.
67
     *
68
     * @return A set of all package names within this module.
69
     */
70
    Set<String> getPackages();
71

72
    /**
73
     * Returns all package exports of this module.
74
     *
75
     * @return A mapping of package names to their export declarations.
76
     */
77
    Map<String, Exports> getExports();
78

79
    /**
80
     * Returns all package opens of this module.
81
     *
82
     * @return A mapping of package names to their opens declarations.
83
     */
84
    Map<String, Opens> getOpens();
85

86
    /**
87
     * Returns all module dependencies of this module.
88
     *
89
     * @return A mapping of module names to their require declarations.
90
     */
91
    Map<String, Requires> getRequires();
92

93
    /**
94
     * Returns all service types that this module uses.
95
     *
96
     * @return A set of service class names that this module uses.
97
     */
98
    Set<String> getUses();
99

100
    /**
101
     * Returns all service implementations provided by this module.
102
     *
103
     * @return A mapping of service names to their provider declarations.
104
     */
105
    Map<String, Provides> getProvides();
106

107
    /**
108
     * Represents an exported package declaration in a module. Exports control which packages
109
     * are accessible to other modules.
110
     */
111
    interface Exports extends ModifierReviewable.OfMandatable {
112

113
        /**
114
         * Returns the target modules that this package is exported to.
115
         *
116
         * @return A set of module names that can access this exported package, or an empty set if exported to all modules.
117
         */
118
        Set<String> getTargets();
119

120
        /**
121
         * Determines if this export is qualified (exported to specific modules only).
122
         *
123
         * @return {@code true} if this export has specific target modules, {@code false} if exported to all modules.
124
         */
125
        boolean isQualified();
126

127
        /**
128
         * An abstract base implementation of {@link Exports} that provides a default implementation
129
         * for {@link #isQualified()}.
130
         */
131
        abstract class AbstractBase extends ModifierReviewable.AbstractBase implements Exports {
1✔
132

133
            /**
134
             * {@inheritDoc}
135
             */
136
            public boolean isQualified() {
UNCOV
137
                return !getTargets().isEmpty();
×
138
            }
139

140
            @Override
141
            public int hashCode() {
142
                int hashCode = getModifiers();
1✔
143
                return hashCode + 17 * getTargets().hashCode();
1✔
144
            }
145

146
            @Override
147
            public boolean equals(Object other) {
148
                if (!(other instanceof Exports)) return false;
1✔
149
                Exports exports = (Exports) other;
1✔
150
                return getModifiers() == exports.getModifiers() && getTargets().equals(exports.getTargets());
1✔
151
            }
152

153
            @Override
154
            public String toString() {
UNCOV
155
                return "Opens{"
×
UNCOV
156
                        + "targets=" + getTargets()
×
UNCOV
157
                        + ",modifiers=" + getModifiers()
×
158
                        + '}';
159
            }
160
        }
161

162
        /**
163
         * A simple implementation of {@link Exports} that stores the target modules and modifiers.
164
         */
165
        class Simple extends AbstractBase {
166

167
            /**
168
             * The target modules for this export.
169
             */
170
            private final Set<String> targets;
171

172
            /**
173
             * The modifiers for this export.
174
             */
175
            protected final int modifiers;
176

177
            /**
178
             * Creates a new simple export declaration.
179
             *
180
             * @param targets   The target modules for this export.
181
             * @param modifiers The modifiers for this export.
182
             */
183
            public Simple(Set<String> targets, int modifiers) {
1✔
184
                this.targets = targets;
1✔
185
                this.modifiers = modifiers;
1✔
186
            }
1✔
187

188
            /**
189
             * {@inheritDoc}
190
             */
191
            public Set<String> getTargets() {
192
                return targets;
1✔
193
            }
194

195
            /**
196
             * {@inheritDoc}
197
             */
198
            public int getModifiers() {
199
                return modifiers;
1✔
200
            }
201
        }
202
    }
203

204
    /**
205
     * Represents an opened package declaration in a module. Opens allow deep reflective access
206
     * to packages for other modules.
207
     */
208
    interface Opens extends ModifierReviewable.OfMandatable {
209

210
        /**
211
         * Returns the target modules that this package is opened to.
212
         *
213
         * @return A set of module names that can reflectively access this opened package, or an empty set if opened to all modules.
214
         */
215
        Set<String> getTargets();
216

217
        /**
218
         * Determines if this opens declaration is qualified (opened to specific modules only).
219
         *
220
         * @return {@code true} if this opens has specific target modules, {@code false} if opened to all modules.
221
         */
222
        boolean isQualified();
223

224
        /**
225
         * An abstract base implementation of {@link Opens}.
226
         */
227
        abstract class AbstractBase extends ModifierReviewable.AbstractBase implements Opens {
1✔
228

229
            /**
230
             * {@inheritDoc}
231
             */
232
            public boolean isQualified() {
UNCOV
233
                return !getTargets().isEmpty();
×
234
            }
235

236
            @Override
237
            public int hashCode() {
238
                int hashCode = getModifiers();
1✔
239
                return hashCode + 17 * getTargets().hashCode();
1✔
240
            }
241

242
            @Override
243
            public boolean equals(Object other) {
244
                if (!(other instanceof Opens)) return false;
1✔
245
                Opens opens = (Opens) other;
1✔
246
                return getModifiers() == opens.getModifiers() && getTargets().equals(opens.getTargets());
1✔
247
            }
248

249
            @Override
250
            public String toString() {
UNCOV
251
                return "Opens{"
×
UNCOV
252
                        + "targets=" + getTargets()
×
UNCOV
253
                        + ",modifiers=" + getModifiers()
×
254
                        + '}';
255
            }
256
        }
257

258
        /**
259
         * A simple implementation of {@link Opens}.
260
         */
261
        class Simple extends AbstractBase {
262

263
            /**
264
             * The target modules for this opens declaration.
265
             */
266
            private final Set<String> targets;
267

268
            /**
269
             * The modifiers for this opens declaration.
270
             */
271
            protected final int modifiers;
272

273
            /**
274
             * Creates a new simple opens declaration.
275
             *
276
             * @param targets   The target modules for this opens declaration.
277
             * @param modifiers The modifiers for this opens declaration.
278
             */
279
            public Simple(Set<String> targets, int modifiers) {
1✔
280
                this.targets = targets;
1✔
281
                this.modifiers = modifiers;
1✔
282
            }
1✔
283

284
            /**
285
             * {@inheritDoc}
286
             */
287
            public Set<String> getTargets() {
288
                return targets;
1✔
289
            }
290

291
            /**
292
             * {@inheritDoc}
293
             */
294
            public int getModifiers() {
295
                return modifiers;
1✔
296
            }
297
        }
298
    }
299

300
    /**
301
     * Represents a module dependency declaration. Requires specify which modules this module
302
     * depends on for compilation and runtime.
303
     */
304
    interface Requires extends ModifierReviewable.ForModuleRequirement {
305

306
        /**
307
         * Returns the version of the required module.
308
         *
309
         * @return The required module's version or {@code null} if no specific version is required.
310
         */
311
        @MaybeNull
312
        String getVersion();
313

314
        /**
315
         * An abstract base implementation of {@link Requires}.
316
         */
317
        abstract class AbstractBase extends ModifierReviewable.AbstractBase implements Requires {
1✔
318

319
            @Override
320
            public int hashCode() {
321
                int hashCode = getModifiers();
1✔
322
                String version = getVersion();
1✔
323
                return version == null ? hashCode : (hashCode + 17 * version.hashCode());
1✔
324
            }
325

326
            @Override
327
            public boolean equals(Object other) {
328
                if (!(other instanceof Requires)) return false;
1✔
329
                Requires requires = (Requires) other;
1✔
330
                String version = getVersion();
1✔
331
                return getModifiers() == requires.getModifiers() && version == null ? requires.getVersion() == null : version.equals(requires.getVersion());
1✔
332
            }
333

334
            @Override
335
            public String toString() {
336
                String version = getVersion();
×
UNCOV
337
                return "Requires{"
×
338
                        + "version=" + (version == null ? "" : '"' + version + '\'')
UNCOV
339
                        + ",modifiers=" + getModifiers()
×
340
                        + '}';
341
            }
342
        }
343

344
        /**
345
         * A simple implementation of {@link Requires}.
346
         */
347
        class Simple extends AbstractBase {
348

349
            /**
350
             * The version of the required module.
351
             */
352
            @MaybeNull
353
            private final String version;
354

355
            /**
356
             * The modifiers for this requires declaration.
357
             */
358
            private final int modifiers;
359

360
            /**
361
             * Creates a new simple requires declaration.
362
             *
363
             * @param version   The version of the required module or {@code null} if no specific version is required.
364
             * @param modifiers The modifiers for this requires declaration.
365
             */
366
            public Simple(@MaybeNull String version, int modifiers) {
1✔
367
                this.version = version;
1✔
368
                this.modifiers = modifiers;
1✔
369
            }
1✔
370

371
            /**
372
             * {@inheritDoc}
373
             */
374
            @MaybeNull
375
            public String getVersion() {
376
                return version;
1✔
377
            }
378

379
            /**
380
             * {@inheritDoc}
381
             */
382
            public int getModifiers() {
383
                return modifiers;
1✔
384
            }
385
        }
386
    }
387

388
    /**
389
     * Represents a service provider declaration in a module. Provides specify which service
390
     * implementations this module offers to other modules.
391
     */
392
    interface Provides {
393

394
        /**
395
         * Returns the implementation classes that provide the service.
396
         *
397
         * @return A set of class names that implement the service.
398
         */
399
        Set<String> getProviders();
400

401
        /**
402
         * An abstract base implementation of {@link Provides}.
403
         */
404
        abstract class AbstractBase implements Provides {
1✔
405

406
            @Override
407
            public int hashCode() {
408
                return getProviders().hashCode();
1✔
409
            }
410

411
            @Override
412
            public boolean equals(Object other) {
413
                if (!(other instanceof Provides)) return false;
1✔
414
                Provides provides = (Provides) other;
1✔
415
                return getProviders().equals(provides.getProviders());
1✔
416
            }
417

418
            @Override
419
            public String toString() {
UNCOV
420
                return "Provides{providers=" + getProviders() + '}';
×
421
            }
422
        }
423

424
        /**
425
         * A simple implementation of {@link Provides}.
426
         */
427
        class Simple extends AbstractBase {
428

429
            /**
430
             * The implementation classes that provide the service.
431
             */
432
            private final Set<String> providers;
433

434
            /**
435
             * Creates a new simple provides declaration.
436
             *
437
             * @param providers The implementation classes that provide the service.
438
             */
439
            public Simple(Set<String> providers) {
1✔
440
                this.providers = providers;
1✔
441
            }
1✔
442

443
            /**
444
             * {@inheritDoc}
445
             */
446
            public Set<String> getProviders() {
447
                return providers;
1✔
448
            }
449
        }
450
    }
451

452
    /**
453
     * An abstract base implementation of a {@link ModuleDescription}.
454
     */
455
    abstract class AbstractBase extends ModifierReviewable.AbstractBase implements ModuleDescription {
1✔
456

457
        @Override
458
        public int hashCode() {
459
            return 17 * getActualName().hashCode();
1✔
460
        }
461

462
        @Override
463
        public boolean equals(Object other) {
464
            if (!(other instanceof ModuleDescription)) return false;
1✔
465
            ModuleDescription module = (ModuleDescription) other;
1✔
466
            return getActualName().equals(module.getActualName());
1✔
467
        }
468

469
        @Override
470
        public String toString() {
471
            return "module " + getActualName();
1✔
472
        }
473
    }
474

475
    /**
476
     * A {@link ModuleDescription} implementation that represents a loaded Java module.
477
     * This implementation uses reflection and Java dispatchers to access module information
478
     * from the runtime module system.
479
     */
480
    class ForLoadedModule extends AbstractBase {
481

482
        /**
483
         * A dispatcher for accessing {@code java.lang.Module} methods.
484
         */
UNCOV
485
        protected static final Module MODULE = doPrivileged(JavaDispatcher.of(Module.class));
×
486

487
        /**
488
         * A dispatcher for accessing {@code java.lang.ModuleDescriptor} methods.
489
         */
UNCOV
490
        protected static final ModuleDescriptor MODULE_DESCRIPTOR = doPrivileged(JavaDispatcher.of(ModuleDescriptor.class));
×
491

492
        /**
493
         * A dispatcher for accessing {@code java.lang.ModuleDescriptor.Exports} methods.
494
         */
UNCOV
495
        protected static final ModuleDescriptor.Exports MODULE_DESCRIPTOR_EXPORTS = doPrivileged(JavaDispatcher.of(ModuleDescriptor.Exports.class));
×
496

497
        /**
498
         * A dispatcher for accessing {@code java.lang.ModuleDescriptor.Opens} methods.
499
         */
UNCOV
500
        protected static final ModuleDescriptor.Opens MODULE_DESCRIPTOR_OPENS = doPrivileged(JavaDispatcher.of(ModuleDescriptor.Opens.class));
×
501

502
        /**
503
         * A dispatcher for accessing {@code java.lang.ModuleDescriptor.Requires} methods.
504
         */
UNCOV
505
        protected static final ModuleDescriptor.Requires MODULE_DESCRIPTOR_REQUIRES = doPrivileged(JavaDispatcher.of(ModuleDescriptor.Requires.class));
×
506

507
        /**
508
         * A dispatcher for accessing {@code java.lang.ModuleDescriptor.Provides} methods.
509
         */
UNCOV
510
        protected static final ModuleDescriptor.Provides MODULE_DESCRIPTOR_PROVIDES = doPrivileged(JavaDispatcher.of(ModuleDescriptor.Provides.class));
×
511

512
        /**
513
         * A dispatcher for accessing {@code java.util.Optional} methods.
514
         */
UNCOV
515
        protected static final Optional OPTIONAL = doPrivileged(JavaDispatcher.of(Optional.class));
×
516

517
        /**
518
         * The module represented by this description.
519
         */
520
        private final AnnotatedElement module;
521

522
        /**
523
         * Creates a module description for the supplied module.
524
         *
525
         * @param module The module to represent.
526
         * @return A module description for the supplied module.
527
         * @throws IllegalArgumentException If the supplied instance is not a module or if the module is unnamed.
528
         */
529
        public static ForLoadedModule of(Object module) {
UNCOV
530
            if (!MODULE.isInstance(module)) {
×
UNCOV
531
                throw new IllegalArgumentException("Not a Java module: " + module);
×
UNCOV
532
            } else if (!MODULE.isNamed(module)) {
×
UNCOV
533
                throw new IllegalArgumentException("Not a named module: " + module);
×
534
            }
UNCOV
535
            return new ForLoadedModule((AnnotatedElement) module);
×
536
        }
537

538
        /**
539
         * A proxy for {@code java.security.AccessController#doPrivileged} that is activated if available.
540
         *
541
         * @param action The action to execute from a privileged context.
542
         * @param <T>    The type of the action's resolved value.
543
         * @return The action's resolved value.
544
         */
545
        @AccessControllerPlugin.Enhance
546
        private static <T> T doPrivileged(PrivilegedAction<T> action) {
547
            return action.run();
×
548
        }
549

550
        /**
551
         * Creates a new module description for the supplied module.
552
         *
553
         * @param module The module to represent.
554
         */
UNCOV
555
        protected ForLoadedModule(AnnotatedElement module) {
×
UNCOV
556
            this.module = module;
×
UNCOV
557
        }
×
558

559
        /**
560
         * {@inheritDoc}
561
         */
562
        @MaybeNull
563
        public String getVersion() {
UNCOV
564
            return (String) OPTIONAL.orElse(MODULE_DESCRIPTOR.rawVersion(MODULE.getDescriptor(module)), null);
×
565
        }
566

567
        /**
568
         * {@inheritDoc}
569
         */
570
        @MaybeNull
571
        public String getMainClass() {
UNCOV
572
            return (String) OPTIONAL.orElse(MODULE_DESCRIPTOR.mainClass(MODULE.getDescriptor(module)), null);
×
573
        }
574

575
        /**
576
         * {@inheritDoc}
577
         */
578
        public boolean isOpen() {
UNCOV
579
            return MODULE_DESCRIPTOR.isOpen(MODULE.getDescriptor(module));
×
580
        }
581

582
        /**
583
         * {@inheritDoc}
584
         */
585
        public Set<String> getPackages() {
UNCOV
586
            return MODULE_DESCRIPTOR.packages(MODULE.getDescriptor(module));
×
587
        }
588

589
        /**
590
         * {@inheritDoc}
591
         */
592
        public Set<String> getUses() {
UNCOV
593
            return MODULE_DESCRIPTOR.uses(MODULE.getDescriptor(module));
×
594
        }
595

596
        /**
597
         * {@inheritDoc}
598
         */
599
        public Map<String, Exports> getExports() {
UNCOV
600
            Map<String, Exports> exports = new LinkedHashMap<String, Exports>();
×
UNCOV
601
            for (Object export : MODULE_DESCRIPTOR.exports(MODULE.getDescriptor(module))) {
×
UNCOV
602
                int modifiers = 0;
×
UNCOV
603
                for (Object modifier : MODULE_DESCRIPTOR_EXPORTS.modifiers(export)) {
×
UNCOV
604
                    String name = ((Enum<?>) modifier).name();
×
605
                    if (name.equals("SYNTHETIC")) {
×
UNCOV
606
                        modifiers |= Opcodes.ACC_SYNTHETIC;
×
UNCOV
607
                    } else if (name.equals("MANDATED")) {
×
UNCOV
608
                        modifiers |= Opcodes.ACC_MANDATED;
×
609
                    } else {
UNCOV
610
                        throw new IllegalStateException("Unknown export modifier: " + name);
×
611
                    }
612
                }
×
613
                exports.put(MODULE_DESCRIPTOR_EXPORTS.source(export), new Exports.Simple(MODULE_DESCRIPTOR_EXPORTS.targets(export), modifiers));
×
614
            }
×
615
            return exports;
×
616
        }
617

618
        /**
619
         * {@inheritDoc}
620
         */
621
        public Map<String, Opens> getOpens() {
UNCOV
622
            Map<String, Opens> opens = new LinkedHashMap<String, Opens>();
×
UNCOV
623
            for (Object open : MODULE_DESCRIPTOR.opens(MODULE.getDescriptor(module))) {
×
UNCOV
624
                int modifiers = 0;
×
UNCOV
625
                for (Object modifier : MODULE_DESCRIPTOR_OPENS.modifiers(open)) {
×
UNCOV
626
                    String name = ((Enum<?>) modifier).name();
×
627
                    if (name.equals("SYNTHETIC")) {
×
628
                        modifiers |= Opcodes.ACC_SYNTHETIC;
×
629
                    } else if (name.equals("MANDATED")) {
×
630
                        modifiers |= Opcodes.ACC_MANDATED;
×
631
                    } else {
632
                        throw new IllegalStateException("Unknown opens modifier: " + name);
×
633
                    }
634
                }
×
635
                opens.put(MODULE_DESCRIPTOR_OPENS.source(open), new Opens.Simple(MODULE_DESCRIPTOR_OPENS.targets(open), modifiers));
×
UNCOV
636
            }
×
UNCOV
637
            return opens;
×
638
        }
639

640
        /**
641
         * {@inheritDoc}
642
         */
643
        public Map<String, Requires> getRequires() {
644
            Map<String, Requires> requires = new LinkedHashMap<String, Requires>();
×
645
            for (Object require : MODULE_DESCRIPTOR.requires(MODULE.getDescriptor(module))) {
×
646
                int modifiers = 0;
×
647
                for (Object modifier : MODULE_DESCRIPTOR_REQUIRES.modifiers(require)) {
×
648
                    String name = ((Enum<?>) modifier).name();
×
649
                    if (name.equals("SYNTHETIC")) {
×
UNCOV
650
                        modifiers |= Opcodes.ACC_SYNTHETIC;
×
651
                    } else if (name.equals("MANDATED")) {
×
652
                        modifiers |= Opcodes.ACC_MANDATED;
×
UNCOV
653
                    } else if (name.equals("TRANSITIVE")) {
×
UNCOV
654
                        modifiers |= Opcodes.ACC_TRANSITIVE;
×
UNCOV
655
                    } else if (name.equals("STATIC")) {
×
UNCOV
656
                        modifiers |= Opcodes.ACC_STATIC_PHASE;
×
657
                    } else {
UNCOV
658
                        throw new IllegalStateException("Unknown requires modifier: " + name);
×
659
                    }
660
                }
×
661
                requires.put(MODULE_DESCRIPTOR_REQUIRES.name(require), new Requires.Simple(
×
662
                        (String) OPTIONAL.orElse(MODULE_DESCRIPTOR_REQUIRES.rawCompiledVersion(require), null),
×
663
                        modifiers));
UNCOV
664
            }
×
UNCOV
665
            return requires;
×
666
        }
667

668
        /**
669
         * {@inheritDoc}
670
         */
671
        public Map<String, Provides> getProvides() {
672
            Map<String, Provides> provides = new LinkedHashMap<String, Provides>();
×
673
            for (Object require : MODULE_DESCRIPTOR.provides(MODULE.getDescriptor(module))) {
×
NEW
674
                provides.put(MODULE_DESCRIPTOR_PROVIDES.service(require), new Provides.Simple(new LinkedHashSet<String>(MODULE_DESCRIPTOR_PROVIDES.providers(require))));
×
UNCOV
675
            }
×
UNCOV
676
            return provides;
×
677
        }
678

679
        /**
680
         * {@inheritDoc}
681
         */
682
        public int getModifiers() {
UNCOV
683
            int modifiers = 0;
×
UNCOV
684
            for (Object modifier : MODULE_DESCRIPTOR.modifiers(module)) {
×
UNCOV
685
                String name = ((Enum<?>) modifier).name();
×
UNCOV
686
                if (name.equals("SYNTHETIC")) {
×
UNCOV
687
                    modifiers |= Opcodes.ACC_SYNTHETIC;
×
688
                } else if (name.equals("MANDATED")) {
×
UNCOV
689
                    modifiers |= Opcodes.ACC_MANDATED;
×
UNCOV
690
                } else if (name.equals("OPEN")) {
×
UNCOV
691
                    modifiers |= Opcodes.ACC_OPEN;
×
692
                } else {
UNCOV
693
                    throw new IllegalStateException("Unknown module modifier: " + name);
×
694
                }
UNCOV
695
            }
×
UNCOV
696
            return modifiers;
×
697
        }
698

699
        /**
700
         * {@inheritDoc}
701
         */
702
        public String getActualName() {
UNCOV
703
            return MODULE_DESCRIPTOR.name(MODULE.getDescriptor(module));
×
704
        }
705

706
        /**
707
         * {@inheritDoc}
708
         */
709
        public AnnotationList getDeclaredAnnotations() {
UNCOV
710
            return new AnnotationList.ForLoadedAnnotations(module.getDeclaredAnnotations());
×
711
        }
712

713
        /**
714
         * A proxy for interacting with {@code java.lang.Module}.
715
         */
716
        @JavaDispatcher.Proxied("java.lang.Module")
717
        protected interface Module {
718

719
            /**
720
             * Returns {@code true} if the supplied instance is of type {@code java.lang.Module}.
721
             *
722
             * @param value The instance to investigate.
723
             * @return {@code true} if the supplied value is a {@code java.lang.Module}.
724
             */
725
            @JavaDispatcher.Instance
726
            boolean isInstance(Object value);
727

728
            /**
729
             * Returns {@code true} if the supplied module is named.
730
             *
731
             * @param value The {@code java.lang.Module} to check for the existence of a name.
732
             * @return {@code true} if the supplied module is named.
733
             */
734
            boolean isNamed(Object value);
735

736
            /**
737
             * Returns the module's name.
738
             *
739
             * @param value The {@code java.lang.Module} to check for its name.
740
             * @return The module's (implicit or explicit) name.
741
             */
742
            String getName(Object value);
743

744
            /**
745
             * Returns the module's exported packages.
746
             *
747
             * @param value The {@code java.lang.Module} to check for its packages.
748
             * @return The module's packages.
749
             */
750
            Set<String> getPackages(Object value);
751

752
            /**
753
             * Returns the module descriptor.
754
             * @param value The {@code java.lang.Module} to check for its descriptor.
755
             * @return The module's descriptor.
756
             */
757
            Object getDescriptor(Object value);
758
        }
759

760
        /**
761
         * A proxy for interacting with {@code java.lang.ModuleDescriptor}.
762
         */
763
        @JavaDispatcher.Proxied("java.lang.module.ModuleDescriptor")
764
        protected interface ModuleDescriptor {
765

766
            /**
767
             * Returns the module's name.
768
             *
769
             * @param value The {@code java.lang.ModuleDescriptor} instance.
770
             * @return The module's name.
771
             */
772
            String name(Object value);
773

774
            /**
775
             * Returns the module's modifiers.
776
             *
777
             * @param value The {@code java.lang.ModuleDescriptor} instance.
778
             * @return The module's modifiers.
779
             */
780
            Set<?> modifiers(Object value);
781

782
            /**
783
             * Returns {@code true} if this is an open module.
784
             *
785
             * @param value The {@code java.lang.ModuleDescriptor} instance.
786
             * @return {@code true} if this is an open module.
787
             */
788
            boolean isOpen(Object value);
789

790
            /**
791
             * Returns the module's requires declarations.
792
             *
793
             * @param value The {@code java.lang.ModuleDescriptor} instance.
794
             * @return The module's requires declarations.
795
             */
796
            Set<?> requires(Object value);
797

798
            /**
799
             * Returns the module's exports declarations.
800
             *
801
             * @param value The {@code java.lang.ModuleDescriptor} instance.
802
             * @return The module's exports declarations.
803
             */
804
            Set<?> exports(Object value);
805

806
            /**
807
             * Returns the module's opens declarations.
808
             *
809
             * @param value The {@code java.lang.ModuleDescriptor} instance.
810
             * @return The module's opens declarations.
811
             */
812
            Set<?> opens(Object value);
813

814
            /**
815
             * Returns the module's uses declarations.
816
             *
817
             * @param value The {@code java.lang.ModuleDescriptor} instance.
818
             * @return The module's uses declarations.
819
             */
820
            Set<String> uses(Object value);
821

822
            /**
823
             * Returns the module's provides declarations.
824
             *
825
             * @param value The {@code java.lang.ModuleDescriptor} instance.
826
             * @return The module's provides declarations.
827
             */
828
            Set<?> provides(Object value);
829

830
            /**
831
             * Returns the module's raw version.
832
             *
833
             * @param value The {@code java.lang.ModuleDescriptor} instance.
834
             * @return The module's raw version as an {@code Optional}.
835
             */
836
            Object rawVersion(Object value);
837

838
            /**
839
             * Returns the module's main class.
840
             *
841
             * @param value The {@code java.lang.ModuleDescriptor} instance.
842
             * @return The module's main class as an {@code Optional}.
843
             */
844
            Object mainClass(Object value);
845

846
            /**
847
             * Returns the module's packages.
848
             *
849
             * @param value The {@code java.lang.ModuleDescriptor} instance.
850
             * @return The module's packages.
851
             */
852
            Set<String> packages(Object value);
853

854
            /**
855
             * A proxy for interacting with {@code java.lang.ModuleDescriptor.Requires}.
856
             */
857
            @JavaDispatcher.Proxied("java.lang.module.ModuleDescriptor$Requires")
858
            interface Requires {
859

860
                /**
861
                 * Returns the name of the required module.
862
                 *
863
                 * @param value The {@code java.lang.ModuleDescriptor.Requires} instance.
864
                 * @return The name of the required module.
865
                 */
866
                String name(Object value);
867

868
                /**
869
                 * Returns the modifiers of the requires declaration.
870
                 *
871
                 * @param value The {@code java.lang.ModuleDescriptor.Requires} instance.
872
                 * @return The modifiers of the requires declaration.
873
                 */
874
                Set<?> modifiers(Object value);
875

876
                /**
877
                 * Returns the raw compiled version of the required module.
878
                 *
879
                 * @param value The {@code java.lang.ModuleDescriptor.Requires} instance.
880
                 * @return The raw compiled version as an {@code Optional}.
881
                 */
882
                Object rawCompiledVersion(Object value);
883
            }
884

885
            /**
886
             * A proxy for interacting with {@code java.lang.ModuleDescriptor.Exports}.
887
             */
888
            @JavaDispatcher.Proxied("java.lang.module.ModuleDescriptor$Exports")
889
            interface Exports {
890

891
                /**
892
                 * Returns the source package name for this export.
893
                 *
894
                 * @param value The {@code java.lang.ModuleDescriptor.Exports} instance.
895
                 * @return The source package name.
896
                 */
897
                String source(Object value);
898

899
                /**
900
                 * Returns the modifiers of the exports declaration.
901
                 *
902
                 * @param value The {@code java.lang.ModuleDescriptor.Exports} instance.
903
                 * @return The modifiers of the exports declaration.
904
                 */
905
                Set<?> modifiers(Object value);
906

907
                /**
908
                 * Returns the target modules for this export.
909
                 *
910
                 * @param value The {@code java.lang.ModuleDescriptor.Exports} instance.
911
                 * @return The target modules for this export.
912
                 */
913
                Set<String> targets(Object value);
914
            }
915

916
            /**
917
             * A proxy for interacting with {@code java.lang.ModuleDescriptor.Opens}.
918
             */
919
            @JavaDispatcher.Proxied("java.lang.module.ModuleDescriptor$Opens")
920
            interface Opens {
921

922
                /**
923
                 * Returns the source package name for this opens declaration.
924
                 *
925
                 * @param value The {@code java.lang.ModuleDescriptor.Opens} instance.
926
                 * @return The source package name.
927
                 */
928
                String source(Object value);
929

930
                /**
931
                 * Returns the modifiers of the opens declaration.
932
                 *
933
                 * @param value The {@code java.lang.ModuleDescriptor.Opens} instance.
934
                 * @return The modifiers of the opens declaration.
935
                 */
936
                Set<?> modifiers(Object value);
937

938
                /**
939
                 * Returns the target modules for this opens declaration.
940
                 *
941
                 * @param value The {@code java.lang.ModuleDescriptor.Opens} instance.
942
                 * @return The target modules for this opens declaration.
943
                 */
944
                Set<String> targets(Object value);
945
            }
946

947
            /**
948
             * A proxy for interacting with {@code java.lang.ModuleDescriptor.Provides}.
949
             */
950
            @JavaDispatcher.Proxied("java.lang.module.ModuleDescriptor$Provides")
951
            interface Provides {
952

953
                /**
954
                 * Returns the service interface name for this provides declaration.
955
                 *
956
                 * @param value The {@code java.lang.ModuleDescriptor.Provides} instance.
957
                 * @return The service interface name.
958
                 */
959
                String service(Object value);
960

961
                /**
962
                 * Returns the provider implementation class names for this provides declaration.
963
                 *
964
                 * @param value The {@code java.lang.ModuleDescriptor.Provides} instance.
965
                 * @return The provider implementation class names.
966
                 */
967
                List<String> providers(Object value);
968
            }
969
        }
970

971
        /**
972
         * A proxy for interacting with {@code java.util.Optional}.
973
         */
974
        @JavaDispatcher.Proxied("java.util.Optional")
975
        protected interface Optional {
976

977
            /**
978
             * Returns the value if present, otherwise returns the fallback value.
979
             *
980
             * @param value    The {@code java.util.Optional} instance.
981
             * @param fallback The fallback value to return if the optional is empty.
982
             * @return The value if present, otherwise the fallback value.
983
             */
984
            @MaybeNull
985
            Object orElse(Object value, @MaybeNull Object fallback);
986
        }
987
    }
988
}
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