• 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

95.74
/byte-buddy-dep/src/main/java/net/bytebuddy/dynamic/scaffold/InstrumentedType.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.dynamic.scaffold;
17

18
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
import net.bytebuddy.ClassFileVersion;
20
import net.bytebuddy.description.annotation.AnnotationDescription;
21
import net.bytebuddy.description.annotation.AnnotationList;
22
import net.bytebuddy.description.annotation.AnnotationValue;
23
import net.bytebuddy.description.field.FieldDescription;
24
import net.bytebuddy.description.field.FieldList;
25
import net.bytebuddy.description.method.MethodDescription;
26
import net.bytebuddy.description.method.MethodList;
27
import net.bytebuddy.description.method.ParameterDescription;
28
import net.bytebuddy.description.modifier.ModifierContributor;
29
import net.bytebuddy.description.module.ModuleDescription;
30
import net.bytebuddy.description.type.PackageDescription;
31
import net.bytebuddy.description.type.RecordComponentDescription;
32
import net.bytebuddy.description.type.RecordComponentList;
33
import net.bytebuddy.description.type.TypeDescription;
34
import net.bytebuddy.description.type.TypeList;
35
import net.bytebuddy.description.type.TypeVariableToken;
36
import net.bytebuddy.dynamic.TargetType;
37
import net.bytebuddy.dynamic.Transformer;
38
import net.bytebuddy.implementation.LoadedTypeInitializer;
39
import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
40
import net.bytebuddy.matcher.ElementMatcher;
41
import net.bytebuddy.utility.CompoundList;
42
import net.bytebuddy.utility.JavaType;
43
import net.bytebuddy.utility.nullability.MaybeNull;
44
import org.objectweb.asm.Opcodes;
45

46
import java.lang.annotation.ElementType;
47
import java.util.ArrayList;
48
import java.util.Arrays;
49
import java.util.Collections;
50
import java.util.HashMap;
51
import java.util.HashSet;
52
import java.util.List;
53
import java.util.Map;
54
import java.util.Set;
55

56
import static net.bytebuddy.matcher.ElementMatchers.is;
57
import static net.bytebuddy.matcher.ElementMatchers.not;
58

59
/**
60
 * Implementations of this interface represent an instrumented type that is subject to change. Implementations
61
 * should however be immutable and return new instance when its builder methods are invoked.
62
 */
63
public interface InstrumentedType extends TypeDescription {
64

65
    /**
66
     * Creates a new instrumented type that defines the provided module metadata or no such metadata
67
     * if {@code null} is provided.
68
     *
69
     * @param moduleDescription The metadata to include or {@code null}.
70
     * @return A new instrumented type that is equal to this instrumented type but with adjusted module metadata.
71
     */
72
    InstrumentedType withModuleDescription(@MaybeNull ModuleDescription moduleDescription);
73

74
    /**
75
     * Creates a new instrumented type that includes a new field.
76
     *
77
     * @param token A token that represents the field's shape.
78
     * @return A new instrumented type that is equal to this instrumented type but with the additional field.
79
     */
80
    InstrumentedType withField(FieldDescription.Token token);
81

82
    /**
83
     * Creates a new instrumented type that includes a new field.
84
     *
85
     * @param token A token that represents the field's shape.
86
     * @param value The value that this assigned to this field.
87
     * @return A new instrumented type that is equal to this instrumented type but with the additional field.
88
     */
89
    InstrumentedType withAuxiliaryField(FieldDescription.Token token, Object value);
90

91
    /**
92
     * Creates a new instrumented type that includes a new method or constructor.
93
     *
94
     * @param token A token that represents the method's shape.
95
     * @return A new instrumented type that is equal to this instrumented type but with the additional method.
96
     */
97
    InstrumentedType withMethod(MethodDescription.Token token);
98

99
    /**
100
     * Creates a new instrumented type that includes a new record component.
101
     *
102
     * @param token A token that represents the record component's shape.
103
     * @return A new instrumented type that is equal to this instrumented type but with the additional record component.
104
     */
105
    InstrumentedType withRecordComponent(RecordComponentDescription.Token token);
106

107
    /**
108
     * Creates a new instrumented type with changed modifiers.
109
     *
110
     * @param modifiers The instrumented type's modifiers.
111
     * @return A new instrumented type that is equal to this instrumented type but with the given modifiers.
112
     */
113
    InstrumentedType withModifiers(int modifiers);
114

115
    /**
116
     * Creates a new instrumented type with the given interfaces implemented.
117
     *
118
     * @param interfaceTypes The interface types to implement.
119
     * @return A new instrumented type that is equal to this instrumented type but with the given interfaces implemented.
120
     */
121
    InstrumentedType withInterfaces(TypeList.Generic interfaceTypes);
122

123
    /**
124
     * Creates a new instrumented type with the given type variable defined.
125
     *
126
     * @param typeVariable The type variable to declare.
127
     * @return A new instrumented type that is equal to this instrumented type but with the given type variable declared.
128
     */
129
    InstrumentedType withTypeVariable(TypeVariableToken typeVariable);
130

131
    /**
132
     * Creates a new instrumented type with the given annotations.
133
     *
134
     * @param annotationDescriptions The annotations to add to the instrumented type.
135
     * @return A new instrumented type that is equal to this instrumented type but annotated with the given annotations
136
     */
137
    InstrumentedType withAnnotations(List<? extends AnnotationDescription> annotationDescriptions);
138

139
    /**
140
     * Creates a new instrumented type with the supplied nest host. An instrumented type can be its own nest host.
141
     * Setting a nest host removes all nest members from the instrumented type.
142
     *
143
     * @param nestHost The nest host of the created instrumented type.
144
     * @return A new instrumented type with the supplied type as its nest host.
145
     */
146
    InstrumentedType withNestHost(TypeDescription nestHost);
147

148
    /**
149
     * Creates a new instrumented types with the supplied nest members added to this instrumented type. The instrumented
150
     * type is defined as a nest host if this method is invoked. Any previous nest members are prepended to the supplied types.
151
     *
152
     * @param nestMembers The nest members to add to the created instrumented type.
153
     * @return A new instrumented type that applies the supplied nest members.
154
     */
155
    InstrumentedType withNestMembers(TypeList nestMembers);
156

157
    /**
158
     * Creates a new instrumented type with the supplied enclosing type.
159
     *
160
     * @param enclosingType The type to define as the created instrumented type's enclosing type.
161
     * @return A new instrumented type with the supplied type as its enclosing type.
162
     */
163
    InstrumentedType withEnclosingType(TypeDescription enclosingType);
164

165
    /**
166
     * Creates a new instrumented type with the supplied enclosing method.
167
     *
168
     * @param enclosingMethod The method to define as the created instrumented type's enclosing method.
169
     * @return A new instrumented type with the supplied method as its enclosing method.
170
     */
171
    InstrumentedType withEnclosingMethod(MethodDescription.InDefinedShape enclosingMethod);
172

173
    /**
174
     * Creates a new instrumented type that is declared by the supplied type.
175
     *
176
     * @param declaringType The type that declares the instrumented type or {@code null} if no such type exists.
177
     * @return A new instrumented type that is declared by the instrumented type.
178
     */
179
    InstrumentedType withDeclaringType(@MaybeNull TypeDescription declaringType);
180

181
    /**
182
     * Creates a new instrumented type that indicates that it declared the supplied types.
183
     *
184
     * @param declaredTypes The types to add to the created instrumented type as declared types.
185
     * @return A new instrumented type that indicates that it has declared the supplied types.
186
     */
187
    InstrumentedType withDeclaredTypes(TypeList declaredTypes);
188

189
    /**
190
     * Creates a new instrumented type that includes the supplied permitted subclasses or unseals the type.
191
     *
192
     * @param permittedSubclasses A list of permitted subclasses to include or {@code null} to unseal the type.
193
     * @return A new instrumented type that includes the supplied permitted subclasses or unseals the type.
194
     */
195
    InstrumentedType withPermittedSubclasses(@MaybeNull TypeList permittedSubclasses);
196

197
    /**
198
     * Creates a new instrumented type that indicates that is defined as a local class. Setting this property
199
     * resets the anonymous class property.
200
     *
201
     * @param localClass {@code true} if the instrumented type is supposed to be treated as a local class.
202
     * @return A new instrumented type that is treated as a local class.
203
     */
204
    InstrumentedType withLocalClass(boolean localClass);
205

206
    /**
207
     * Creates a new instrumented type that indicates that it is defined as an anonymous class. Setting this property
208
     * resets the local class property.
209
     *
210
     * @param anonymousClass {@code true} if the instrumented type is supposed to be treated as an anonymous class.
211
     * @return A new instrumented type that is treated as an anonymous class.
212
     */
213
    InstrumentedType withAnonymousClass(boolean anonymousClass);
214

215
    /**
216
     * Creates a new instrumented type that indicates that it defined as a record type. Setting this property to false
217
     * removes all record components.
218
     *
219
     * @param record {@code true} if the instrumented type is supposed to be a record.
220
     * @return A new instrumented type that is defined as a record.
221
     */
222
    InstrumentedType withRecord(boolean record);
223

224
    /**
225
     * Creates a new instrumented type that includes the given {@link net.bytebuddy.implementation.LoadedTypeInitializer}.
226
     *
227
     * @param loadedTypeInitializer The type initializer to include.
228
     * @return A new instrumented type that is equal to this instrumented type but with the additional type initializer.
229
     */
230
    InstrumentedType withInitializer(LoadedTypeInitializer loadedTypeInitializer);
231

232
    /**
233
     * Creates a new instrumented type that executes the given initializer in the instrumented type's
234
     * type initializer.
235
     *
236
     * @param byteCodeAppender The byte code to add to the type initializer.
237
     * @return A new instrumented type that is equal to this instrumented type but with the given stack manipulation
238
     * attached to its type initializer.
239
     */
240
    InstrumentedType withInitializer(ByteCodeAppender byteCodeAppender);
241

242
    /**
243
     * Returns the {@link net.bytebuddy.implementation.LoadedTypeInitializer}s that were registered
244
     * for this instrumented type.
245
     *
246
     * @return The registered loaded type initializers for this instrumented type.
247
     */
248
    LoadedTypeInitializer getLoadedTypeInitializer();
249

250
    /**
251
     * Returns this instrumented type's type initializer.
252
     *
253
     * @return This instrumented type's type initializer.
254
     */
255
    TypeInitializer getTypeInitializer();
256

257
    /**
258
     * Validates the instrumented type to define a legal Java type.
259
     *
260
     * @return This instrumented type as a non-modifiable type description.
261
     */
262
    TypeDescription validated();
263

264
    /**
265
     * Implementations represent an {@link InstrumentedType} with a flexible name.
266
     */
267
    interface WithFlexibleName extends InstrumentedType {
268

269
        /**
270
         * {@inheritDoc}
271
         */
272
        WithFlexibleName withModuleDescription(@MaybeNull ModuleDescription moduleDescription);
273

274
        /**
275
         * {@inheritDoc}
276
         */
277
        WithFlexibleName withField(FieldDescription.Token token);
278

279
        /**
280
         * {@inheritDoc}
281
         */
282
        WithFlexibleName withAuxiliaryField(FieldDescription.Token token, Object value);
283

284
        /**
285
         * {@inheritDoc}
286
         */
287
        WithFlexibleName withMethod(MethodDescription.Token token);
288

289
        /**
290
         * {@inheritDoc}
291
         */
292
        WithFlexibleName withRecordComponent(RecordComponentDescription.Token token);
293

294
        /**
295
         * {@inheritDoc}
296
         */
297
        WithFlexibleName withModifiers(int modifiers);
298

299
        /**
300
         * {@inheritDoc}
301
         */
302
        WithFlexibleName withInterfaces(TypeList.Generic interfaceTypes);
303

304
        /**
305
         * {@inheritDoc}
306
         */
307
        WithFlexibleName withNestHost(TypeDescription nestHost);
308

309
        /**
310
         * {@inheritDoc}
311
         */
312
        WithFlexibleName withNestMembers(TypeList nestMembers);
313

314
        /**
315
         * {@inheritDoc}
316
         */
317
        WithFlexibleName withEnclosingType(@MaybeNull TypeDescription enclosingType);
318

319
        /**
320
         * {@inheritDoc}
321
         */
322
        WithFlexibleName withEnclosingMethod(MethodDescription.InDefinedShape enclosingMethod);
323

324
        /**
325
         * {@inheritDoc}
326
         */
327
        WithFlexibleName withDeclaringType(@MaybeNull TypeDescription declaringType);
328

329
        /**
330
         * {@inheritDoc}
331
         */
332
        WithFlexibleName withDeclaredTypes(TypeList declaredTypes);
333

334
        /**
335
         * {@inheritDoc}
336
         */
337
        WithFlexibleName withPermittedSubclasses(@MaybeNull TypeList permittedSubclasses);
338

339
        /**
340
         * {@inheritDoc}
341
         */
342
        WithFlexibleName withLocalClass(boolean localClass);
343

344
        /**
345
         * {@inheritDoc}
346
         */
347
        WithFlexibleName withAnonymousClass(boolean anonymousClass);
348

349
        /**
350
         * {@inheritDoc}
351
         */
352
        WithFlexibleName withRecord(boolean record);
353

354
        /**
355
         * {@inheritDoc}
356
         */
357
        WithFlexibleName withTypeVariable(TypeVariableToken typeVariable);
358

359
        /**
360
         * {@inheritDoc}
361
         */
362
        WithFlexibleName withAnnotations(List<? extends AnnotationDescription> annotationDescriptions);
363

364
        /**
365
         * {@inheritDoc}
366
         */
367
        WithFlexibleName withInitializer(LoadedTypeInitializer loadedTypeInitializer);
368

369
        /**
370
         * {@inheritDoc}
371
         */
372
        WithFlexibleName withInitializer(ByteCodeAppender byteCodeAppender);
373

374
        /**
375
         * Creates a new instrumented type with a changed name.
376
         *
377
         * @param name The name of the instrumented type.
378
         * @return A new instrumented type that has the given name.
379
         */
380
        WithFlexibleName withName(String name);
381

382
        /**
383
         * Applies a transformation onto all existing type variables of this instrumented type. A transformation is potentially unsafe
384
         * and it is the responsibility of the supplier to return a valid type variable token from the transformer.
385
         *
386
         * @param matcher     The matcher to decide what type variables to transform.
387
         * @param transformer The transformer to apply on all matched type variables.
388
         * @return A new instrumented type with all matched type variables transformed.
389
         */
390
        WithFlexibleName withTypeVariables(ElementMatcher<? super Generic> matcher, Transformer<TypeVariableToken> transformer);
391
    }
392

393
    /**
394
     * Implementations are able to prepare an {@link InstrumentedType}.
395
     */
396
    interface Prepareable {
397

398
        /**
399
         * Prepares a given instrumented type.
400
         *
401
         * @param instrumentedType The instrumented type in its current form.
402
         * @return The prepared instrumented type.
403
         */
404
        InstrumentedType prepare(InstrumentedType instrumentedType);
405

406
        /**
407
         * A prepareable that does not alter the instrumented type.
408
         */
409
        enum NoOp implements Prepareable {
1✔
410

411
            /**
412
             * The singleton instance.
413
             */
414
            INSTANCE;
1✔
415

416
            /**
417
             * {@inheritDoc}
418
             */
419
            public InstrumentedType prepare(InstrumentedType instrumentedType) {
420
                return instrumentedType;
1✔
421
            }
422
        }
423
    }
424

425
    /**
426
     * A factory for creating an {@link InstrumentedType}.
427
     */
428
    interface Factory {
429

430
        /**
431
         * Creates an instrumented type that represents the provided type.
432
         *
433
         * @param typeDescription The type to represent.
434
         * @return An appropriate instrumented type.
435
         */
436
        InstrumentedType.WithFlexibleName represent(TypeDescription typeDescription);
437

438
        /**
439
         * Creates a new instrumented type as a subclass.
440
         *
441
         * @param name       The type's name.
442
         * @param modifiers  The type's modifiers.
443
         * @param superClass The type's super class or {@code null} if no super class.
444
         * @return A new instrumented type representing a subclass of the given parameters.
445
         */
446
        InstrumentedType.WithFlexibleName subclass(String name, int modifiers, @MaybeNull TypeDescription.Generic superClass);
447

448
        /**
449
         * Default implementations of instrumented type factories.
450
         */
451
        enum Default implements Factory {
1✔
452

453
            /**
454
             * A factory for an instrumented type that allows to modify represented types.
455
             */
456
            MODIFIABLE {
1✔
457
                /** {@inheritDoc} */
458
                public InstrumentedType.WithFlexibleName represent(TypeDescription typeDescription) {
459
                    return new InstrumentedType.Default(typeDescription.getName(),
1✔
460
                            typeDescription.getModifiers(),
1✔
461
                            typeDescription.toModuleDescription(),
1✔
462
                            typeDescription.getTypeVariables().asTokenList(is(typeDescription)),
1✔
463
                            typeDescription.getSuperClass(),
1✔
464
                            typeDescription.getInterfaces().accept(Generic.Visitor.Substitutor.ForDetachment.of(typeDescription)),
1✔
465
                            typeDescription.getDeclaredFields().asTokenList(is(typeDescription)),
1✔
466
                            Collections.<String, Object>emptyMap(),
1✔
467
                            typeDescription.getDeclaredMethods().asTokenList(is(typeDescription)),
1✔
468
                            typeDescription.getRecordComponents().asTokenList(is(typeDescription)),
1✔
469
                            typeDescription.getDeclaredAnnotations(),
1✔
470
                            TypeInitializer.None.INSTANCE,
471
                            LoadedTypeInitializer.NoOp.INSTANCE,
472
                            typeDescription.getDeclaringType(),
1✔
473
                            typeDescription.getEnclosingMethod(),
1✔
474
                            typeDescription.getEnclosingType(),
1✔
475
                            typeDescription.getDeclaredTypes(),
1✔
476
                            typeDescription.isSealed()
1✔
477
                                    ? typeDescription.getPermittedSubtypes()
1✔
478
                                    : TypeList.UNDEFINED,
479
                            typeDescription.isAnonymousType(),
1✔
480
                            typeDescription.isLocalType(),
1✔
481
                            typeDescription.isRecord(),
1✔
482
                            typeDescription.isNestHost()
1✔
483
                                    ? TargetType.DESCRIPTION
484
                                    : typeDescription.getNestHost(),
1✔
485
                            typeDescription.isNestHost()
1✔
486
                                    ? typeDescription.getNestMembers().filter(not(is(typeDescription)))
1✔
487
                                    : Collections.<TypeDescription>emptyList());
1✔
488
                }
489
            },
490

491
            /**
492
             * A factory for an instrumented type that does not allow to modify represented types.
493
             */
494
            FROZEN {
1✔
495
                /** {@inheritDoc} */
496
                public InstrumentedType.WithFlexibleName represent(TypeDescription typeDescription) {
497
                    return new Frozen(typeDescription, LoadedTypeInitializer.NoOp.INSTANCE);
1✔
498
                }
499
            };
500

501
            /**
502
             * {@inheritDoc}
503
             */
504
            public InstrumentedType.WithFlexibleName subclass(String name, int modifiers, @MaybeNull TypeDescription.Generic superClass) {
505
                return new InstrumentedType.Default(name,
1✔
506
                        modifiers,
507
                        ModuleDescription.UNDEFINED,
508
                        Collections.<TypeVariableToken>emptyList(),
1✔
509
                        superClass,
510
                        Collections.<Generic>emptyList(),
1✔
511
                        Collections.<FieldDescription.Token>emptyList(),
1✔
512
                        Collections.<String, Object>emptyMap(),
1✔
513
                        Collections.<MethodDescription.Token>emptyList(),
1✔
514
                        Collections.<RecordComponentDescription.Token>emptyList(),
1✔
515
                        Collections.<AnnotationDescription>emptyList(),
1✔
516
                        TypeInitializer.None.INSTANCE,
517
                        LoadedTypeInitializer.NoOp.INSTANCE,
518
                        TypeDescription.UNDEFINED,
519
                        MethodDescription.UNDEFINED,
520
                        TypeDescription.UNDEFINED,
521
                        Collections.<TypeDescription>emptyList(),
1✔
522
                        TypeList.UNDEFINED,
523
                        false,
524
                        false,
525
                        false,
526
                        TargetType.DESCRIPTION,
527
                        Collections.<TypeDescription>emptyList());
1✔
528
            }
529
        }
530
    }
531

532
    /**
533
     * A default implementation of an instrumented type.
534
     */
535
    class Default extends AbstractBase.OfSimpleType implements InstrumentedType.WithFlexibleName {
536

537
        /**
538
         * A set containing all keywords of the Java programming language.
539
         */
540
        private static final Set<String> KEYWORDS = new HashSet<String>(Arrays.asList(
1✔
541
                "abstract", "continue", "for", "new", "switch", "assert", "default", "goto", "package", "synchronized", "boolean",
542
                "do", "if", "private", "this", "break", "double", "implements", "protected", "throw", "byte", "else", "import",
543
                "public", "throws", "case", "enum", "instanceof", "return", "transient", "catch", "extends", "int", "short",
544
                "try", "char", "final", "interface", "static", "void", "class", "finally", "long", "strictfp", "volatile",
545
                "const", "float", "native", "super", "while"
546
        ));
547

548
        /**
549
         * The binary name of the instrumented type.
550
         */
551
        private final String name;
552

553
        /**
554
         * The modifiers of the instrumented type.
555
         */
556
        private final int modifiers;
557

558
        /**
559
         * The generic super type of the instrumented type.
560
         */
561
        @MaybeNull
562
        private final Generic superClass;
563

564
        /**
565
         * The module metadata that this type implies or {@code null}.
566
         */
567
        @MaybeNull
568
        private final ModuleDescription moduleDescription;
569

570
        /**
571
         * The instrumented type's type variables in their tokenized form.
572
         */
573
        private final List<? extends TypeVariableToken> typeVariables;
574

575
        /**
576
         * A list of interfaces of the instrumented type.
577
         */
578
        private final List<? extends Generic> interfaceTypes;
579

580
        /**
581
         * A list of field tokens describing the fields of the instrumented type.
582
         */
583
        private final List<? extends FieldDescription.Token> fieldTokens;
584

585
        /**
586
         * A mapping of auxiliary field names to their mapped values.
587
         */
588
        private final Map<String, Object> auxiliaryFields;
589

590
        /**
591
         * A list of method tokens describing the methods of the instrumented type.
592
         */
593
        private final List<? extends MethodDescription.Token> methodTokens;
594

595
        /**
596
         * A list of record component tokens describing the record components of the instrumented type.
597
         */
598
        private final List<? extends RecordComponentDescription.Token> recordComponentTokens;
599

600
        /**
601
         * A list of annotations of the annotated type.
602
         */
603
        private final List<? extends AnnotationDescription> annotationDescriptions;
604

605
        /**
606
         * The type initializer of the instrumented type.
607
         */
608
        private final TypeInitializer typeInitializer;
609

610
        /**
611
         * The loaded type initializer of the instrumented type.
612
         */
613
        private final LoadedTypeInitializer loadedTypeInitializer;
614

615
        /**
616
         * The declaring type of the instrumented type or {@code null} if no such type exists.
617
         */
618
        @MaybeNull
619
        private final TypeDescription declaringType;
620

621
        /**
622
         * The enclosing method of the instrumented type or {@code null} if no such type exists.
623
         */
624
        @MaybeNull
625
        private final MethodDescription.InDefinedShape enclosingMethod;
626

627
        /**
628
         * The enclosing type of the instrumented type or {@code null} if no such type exists.
629
         */
630
        @MaybeNull
631
        private final TypeDescription enclosingType;
632

633
        /**
634
         * A list of types that are declared by this type.
635
         */
636
        private final List<? extends TypeDescription> declaredTypes;
637

638
        /**
639
         * A list of permitted subclasses or {@code null} if this type is not sealed.
640
         */
641
        @MaybeNull
642
        private final List<? extends TypeDescription> permittedSubclasses;
643

644
        /**
645
         * {@code true} if this type is an anonymous class.
646
         */
647
        private final boolean anonymousClass;
648

649
        /**
650
         * {@code true} if this type is a local class.
651
         */
652
        private final boolean localClass;
653

654
        /**
655
         * {@code true} if this class is a record class.
656
         */
657
        private final boolean record;
658

659
        /**
660
         * The nest host of this instrumented type or a description of {@link TargetType} if this type is its own nest host.
661
         */
662
        private final TypeDescription nestHost;
663

664
        /**
665
         * A list of all members of this types nest group excluding this type.
666
         */
667
        private final List<? extends TypeDescription> nestMembers;
668

669
        /**
670
         * Creates a new instrumented type.
671
         *
672
         * @param name                   The binary name of the instrumented type.
673
         * @param modifiers              The modifiers of the instrumented type.
674
         * @param moduleDescription      The module metadata that this type implies or {@code null}.
675
         * @param typeVariables          The instrumented type's type variables in their tokenized form.
676
         * @param superClass             The generic super type of the instrumented type.
677
         * @param interfaceTypes         A list of interfaces of the instrumented type.
678
         * @param fieldTokens            A list of field tokens describing the fields of the instrumented type.
679
         * @param auxiliaryFieldValues   A mapping of auxiliary field names to their mapped values.
680
         * @param methodTokens           A list of method tokens describing the methods of the instrumented type.
681
         * @param recordComponentTokens  A list of record component tokens describing the record components of the instrumented type.
682
         * @param annotationDescriptions A list of annotations of the annotated type.
683
         * @param typeInitializer        The type initializer of the instrumented type.
684
         * @param loadedTypeInitializer  The loaded type initializer of the instrumented type.
685
         * @param declaringType          The declaring type of the instrumented type or {@code null} if no such type exists.
686
         * @param enclosingMethod        The enclosing method of the instrumented type or {@code null} if no such type exists.
687
         * @param enclosingType          The enclosing type of the instrumented type or {@code null} if no such type exists.
688
         * @param declaredTypes          A list of types that are declared by this type.
689
         * @param permittedSubclasses    A list of permitted subclasses or {@code null} if this type is not sealed.
690
         * @param anonymousClass         {@code true} if this type is an anonymous class.
691
         * @param localClass             {@code true} if this type is a local class.
692
         * @param record                 {@code true} if this type is a record class.
693
         * @param nestHost               The nest host of this instrumented type or a description of {@link TargetType} if this type is its own nest host.
694
         * @param nestMembers            A list of all members of this types nest group excluding this type.
695
         */
696
        protected Default(String name,
697
                          int modifiers,
698
                          @MaybeNull ModuleDescription moduleDescription,
699
                          List<? extends TypeVariableToken> typeVariables,
700
                          @MaybeNull Generic superClass,
701
                          List<? extends Generic> interfaceTypes,
702
                          List<? extends FieldDescription.Token> fieldTokens,
703
                          Map<String, Object> auxiliaryFieldValues,
704
                          List<? extends MethodDescription.Token> methodTokens,
705
                          List<? extends RecordComponentDescription.Token> recordComponentTokens,
706
                          List<? extends AnnotationDescription> annotationDescriptions,
707
                          TypeInitializer typeInitializer,
708
                          LoadedTypeInitializer loadedTypeInitializer,
709
                          @MaybeNull TypeDescription declaringType,
710
                          @MaybeNull MethodDescription.InDefinedShape enclosingMethod,
711
                          @MaybeNull TypeDescription enclosingType,
712
                          List<? extends TypeDescription> declaredTypes,
713
                          @MaybeNull List<? extends TypeDescription> permittedSubclasses,
714
                          boolean anonymousClass,
715
                          boolean localClass,
716
                          boolean record,
717
                          TypeDescription nestHost,
718
                          List<? extends TypeDescription> nestMembers) {
1✔
719
            this.name = name;
1✔
720
            this.modifiers = modifiers;
1✔
721
            this.moduleDescription = moduleDescription;
1✔
722
            this.typeVariables = typeVariables;
1✔
723
            this.superClass = superClass;
1✔
724
            this.interfaceTypes = interfaceTypes;
1✔
725
            this.fieldTokens = fieldTokens;
1✔
726
            this.auxiliaryFields = auxiliaryFieldValues;
1✔
727
            this.methodTokens = methodTokens;
1✔
728
            this.recordComponentTokens = recordComponentTokens;
1✔
729
            this.annotationDescriptions = annotationDescriptions;
1✔
730
            this.typeInitializer = typeInitializer;
1✔
731
            this.loadedTypeInitializer = loadedTypeInitializer;
1✔
732
            this.declaringType = declaringType;
1✔
733
            this.enclosingMethod = enclosingMethod;
1✔
734
            this.enclosingType = enclosingType;
1✔
735
            this.declaredTypes = declaredTypes;
1✔
736
            this.permittedSubclasses = permittedSubclasses;
1✔
737
            this.anonymousClass = anonymousClass;
1✔
738
            this.localClass = localClass;
1✔
739
            this.record = record;
1✔
740
            this.nestHost = nestHost;
1✔
741
            this.nestMembers = nestMembers;
1✔
742
        }
1✔
743

744
        /**
745
         * Creates a new instrumented type.
746
         *
747
         * @param name                The type's name.
748
         * @param superClass          The type's super class.
749
         * @param modifierContributor The type's modifiers.
750
         * @return An appropriate instrumented type.
751
         */
752
        public static InstrumentedType of(String name, TypeDescription.Generic superClass, ModifierContributor.ForType... modifierContributor) {
753
            return of(name, superClass, ModifierContributor.Resolver.of(modifierContributor).resolve());
1✔
754
        }
755

756
        /**
757
         * Creates a new instrumented type.
758
         *
759
         * @param name       The type's name.
760
         * @param superClass The type's super class.
761
         * @param modifiers  The type's modifiers.
762
         * @return An appropriate instrumented type.
763
         */
764
        public static InstrumentedType of(String name, TypeDescription.Generic superClass, int modifiers) {
765
            return Factory.Default.MODIFIABLE.subclass(name, modifiers, superClass);
1✔
766
        }
767

768
        /**
769
         * {@inheritDoc}
770
         */
771
        public WithFlexibleName withModifiers(int modifiers) {
772
            return new Default(name,
1✔
773
                    modifiers,
774
                    moduleDescription,
775
                    typeVariables,
776
                    superClass,
777
                    interfaceTypes,
778
                    fieldTokens,
779
                    auxiliaryFields,
780
                    methodTokens,
781
                    recordComponentTokens,
782
                    annotationDescriptions,
783
                    typeInitializer,
784
                    loadedTypeInitializer,
785
                    declaringType,
786
                    enclosingMethod,
787
                    enclosingType,
788
                    declaredTypes,
789
                    permittedSubclasses,
790
                    anonymousClass,
791
                    localClass,
792
                    record,
793
                    nestHost,
794
                    nestMembers);
795
        }
796

797
        /**
798
         * {@inheritDoc}
799
         */
800
        public WithFlexibleName withField(FieldDescription.Token token) {
801
            return new Default(name,
1✔
802
                    modifiers,
803
                    moduleDescription,
804
                    typeVariables,
805
                    superClass,
806
                    interfaceTypes,
807
                    CompoundList.of(fieldTokens, token.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))),
1✔
808
                    auxiliaryFields,
809
                    methodTokens,
810
                    recordComponentTokens,
811
                    annotationDescriptions,
812
                    typeInitializer,
813
                    loadedTypeInitializer,
814
                    declaringType,
815
                    enclosingMethod,
816
                    enclosingType,
817
                    declaredTypes,
818
                    permittedSubclasses,
819
                    anonymousClass,
820
                    localClass,
821
                    record,
822
                    nestHost,
823
                    nestMembers);
824
        }
825

826
        /**
827
         * {@inheritDoc}
828
         */
829
        public WithFlexibleName withAuxiliaryField(FieldDescription.Token token, Object value) {
830
            Map<String, Object> auxiliaryFields = new HashMap<String, Object>(this.auxiliaryFields);
1✔
831
            Object previous = auxiliaryFields.put(token.getName(), value);
1✔
832
            if (previous != null) {
1✔
833
                if (previous == value) {
1✔
834
                    return this;
1✔
835
                } else {
836
                    throw new IllegalStateException("Field " + token.getName()
1✔
837
                            + " for " + this
838
                            + " already mapped to " + previous
839
                            + " and not " + value);
840
                }
841
            }
842
            return new Default(name,
1✔
843
                    modifiers,
844
                    moduleDescription,
845
                    typeVariables,
846
                    superClass,
847
                    interfaceTypes,
848
                    CompoundList.of(fieldTokens, token.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))),
1✔
849
                    auxiliaryFields,
850
                    methodTokens,
851
                    recordComponentTokens,
852
                    annotationDescriptions,
853
                    typeInitializer,
854
                    new LoadedTypeInitializer.Compound(loadedTypeInitializer, new LoadedTypeInitializer.ForStaticField(token.getName(), value)),
1✔
855
                    declaringType,
856
                    enclosingMethod,
857
                    enclosingType,
858
                    declaredTypes,
859
                    permittedSubclasses,
860
                    anonymousClass,
861
                    localClass,
862
                    record,
863
                    nestHost,
864
                    nestMembers);
865
        }
866

867
        /**
868
         * {@inheritDoc}
869
         */
870
        public WithFlexibleName withMethod(MethodDescription.Token token) {
871
            return new Default(name,
1✔
872
                    modifiers,
873
                    moduleDescription,
874
                    typeVariables,
875
                    superClass,
876
                    interfaceTypes,
877
                    fieldTokens,
878
                    auxiliaryFields,
879
                    CompoundList.of(methodTokens, token.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))),
1✔
880
                    recordComponentTokens,
881
                    annotationDescriptions,
882
                    typeInitializer,
883
                    loadedTypeInitializer,
884
                    declaringType,
885
                    enclosingMethod,
886
                    enclosingType,
887
                    declaredTypes,
888
                    permittedSubclasses,
889
                    anonymousClass,
890
                    localClass,
891
                    record,
892
                    nestHost,
893
                    nestMembers);
894
        }
895

896
        /**
897
         * {@inheritDoc}
898
         */
899
        public WithFlexibleName withRecordComponent(RecordComponentDescription.Token token) {
900
            return new Default(name,
1✔
901
                    modifiers,
902
                    moduleDescription,
903
                    typeVariables,
904
                    superClass,
905
                    interfaceTypes,
906
                    fieldTokens,
907
                    auxiliaryFields,
908
                    methodTokens,
909
                    CompoundList.of(recordComponentTokens, token.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))),
1✔
910
                    annotationDescriptions,
911
                    typeInitializer,
912
                    loadedTypeInitializer,
913
                    declaringType,
914
                    enclosingMethod,
915
                    enclosingType,
916
                    declaredTypes,
917
                    permittedSubclasses,
918
                    anonymousClass,
919
                    localClass,
920
                    true,
921
                    nestHost,
922
                    nestMembers);
923
        }
924

925
        /**
926
         * {@inheritDoc}
927
         */
928
        public WithFlexibleName withInterfaces(TypeList.Generic interfaceTypes) {
929
            return new Default(name,
1✔
930
                    modifiers,
931
                    moduleDescription,
932
                    typeVariables,
933
                    superClass,
934
                    CompoundList.of(this.interfaceTypes, interfaceTypes.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))),
1✔
935
                    fieldTokens,
936
                    auxiliaryFields,
937
                    methodTokens,
938
                    recordComponentTokens,
939
                    annotationDescriptions,
940
                    typeInitializer,
941
                    loadedTypeInitializer,
942
                    declaringType,
943
                    enclosingMethod,
944
                    enclosingType,
945
                    declaredTypes,
946
                    permittedSubclasses,
947
                    anonymousClass,
948
                    localClass,
949
                    record,
950
                    nestHost,
951
                    nestMembers);
952
        }
953

954
        /**
955
         * {@inheritDoc}
956
         */
957
        public WithFlexibleName withAnnotations(List<? extends AnnotationDescription> annotationDescriptions) {
958
            return new Default(name,
1✔
959
                    modifiers,
960
                    moduleDescription,
961
                    typeVariables,
962
                    superClass,
963
                    interfaceTypes,
964
                    fieldTokens,
965
                    auxiliaryFields,
966
                    methodTokens,
967
                    recordComponentTokens,
968
                    CompoundList.of(this.annotationDescriptions, annotationDescriptions),
1✔
969
                    typeInitializer,
970
                    loadedTypeInitializer,
971
                    declaringType,
972
                    enclosingMethod,
973
                    enclosingType,
974
                    declaredTypes,
975
                    permittedSubclasses,
976
                    anonymousClass,
977
                    localClass,
978
                    record,
979
                    nestHost,
980
                    nestMembers);
981
        }
982

983
        /**
984
         * {@inheritDoc}
985
         */
986
        public WithFlexibleName withNestHost(TypeDescription nestHost) {
987
            return new Default(name,
1✔
988
                    modifiers,
989
                    moduleDescription,
990
                    typeVariables,
991
                    superClass,
992
                    interfaceTypes,
993
                    fieldTokens,
994
                    auxiliaryFields,
995
                    methodTokens,
996
                    recordComponentTokens,
997
                    annotationDescriptions,
998
                    typeInitializer,
999
                    loadedTypeInitializer,
1000
                    declaringType,
1001
                    enclosingMethod,
1002
                    enclosingType,
1003
                    declaredTypes,
1004
                    permittedSubclasses,
1005
                    anonymousClass,
1006
                    localClass,
1007
                    record,
1008
                    nestHost.equals(this)
1✔
1009
                            ? TargetType.DESCRIPTION
1010
                            : nestHost,
1011
                    Collections.<TypeDescription>emptyList());
1✔
1012
        }
1013

1014
        /**
1015
         * {@inheritDoc}
1016
         */
1017
        public WithFlexibleName withNestMembers(TypeList nestMembers) {
1018
            return new Default(name,
1✔
1019
                    modifiers,
1020
                    moduleDescription,
1021
                    typeVariables,
1022
                    superClass,
1023
                    interfaceTypes,
1024
                    fieldTokens,
1025
                    auxiliaryFields,
1026
                    methodTokens,
1027
                    recordComponentTokens,
1028
                    annotationDescriptions,
1029
                    typeInitializer,
1030
                    loadedTypeInitializer,
1031
                    declaringType,
1032
                    enclosingMethod,
1033
                    enclosingType,
1034
                    declaredTypes,
1035
                    permittedSubclasses,
1036
                    anonymousClass,
1037
                    localClass,
1038
                    record,
1039
                    TargetType.DESCRIPTION,
1040
                    CompoundList.of(this.nestMembers, nestMembers));
1✔
1041
        }
1042

1043
        /**
1044
         * {@inheritDoc}
1045
         */
1046
        public WithFlexibleName withEnclosingType(@MaybeNull TypeDescription enclosingType) {
1047
            return new Default(name,
1✔
1048
                    modifiers,
1049
                    moduleDescription,
1050
                    typeVariables,
1051
                    superClass,
1052
                    interfaceTypes,
1053
                    fieldTokens,
1054
                    auxiliaryFields,
1055
                    methodTokens,
1056
                    recordComponentTokens,
1057
                    annotationDescriptions,
1058
                    typeInitializer,
1059
                    loadedTypeInitializer,
1060
                    declaringType,
1061
                    MethodDescription.UNDEFINED,
1062
                    enclosingType,
1063
                    declaredTypes,
1064
                    permittedSubclasses,
1065
                    anonymousClass,
1066
                    localClass,
1067
                    record,
1068
                    nestHost,
1069
                    nestMembers);
1070
        }
1071

1072
        /**
1073
         * {@inheritDoc}
1074
         */
1075
        public WithFlexibleName withEnclosingMethod(MethodDescription.InDefinedShape enclosingMethod) {
1076
            return new Default(name,
1✔
1077
                    modifiers,
1078
                    moduleDescription,
1079
                    typeVariables,
1080
                    superClass,
1081
                    interfaceTypes,
1082
                    fieldTokens,
1083
                    auxiliaryFields,
1084
                    methodTokens,
1085
                    recordComponentTokens,
1086
                    annotationDescriptions,
1087
                    typeInitializer,
1088
                    loadedTypeInitializer,
1089
                    declaringType,
1090
                    enclosingMethod,
1091
                    enclosingMethod.getDeclaringType(),
1✔
1092
                    declaredTypes,
1093
                    permittedSubclasses,
1094
                    anonymousClass,
1095
                    localClass,
1096
                    record,
1097
                    nestHost,
1098
                    nestMembers);
1099
        }
1100

1101
        /**
1102
         * {@inheritDoc}
1103
         */
1104
        public WithFlexibleName withDeclaringType(@MaybeNull TypeDescription declaringType) {
1105
            return new Default(name,
1✔
1106
                    modifiers,
1107
                    moduleDescription,
1108
                    typeVariables,
1109
                    superClass,
1110
                    interfaceTypes,
1111
                    fieldTokens,
1112
                    auxiliaryFields,
1113
                    methodTokens,
1114
                    recordComponentTokens,
1115
                    annotationDescriptions,
1116
                    typeInitializer,
1117
                    loadedTypeInitializer,
1118
                    declaringType,
1119
                    enclosingMethod,
1120
                    enclosingType,
1121
                    declaredTypes,
1122
                    permittedSubclasses,
1123
                    anonymousClass,
1124
                    localClass,
1125
                    record,
1126
                    nestHost,
1127
                    nestMembers);
1128
        }
1129

1130
        /**
1131
         * {@inheritDoc}
1132
         */
1133
        public WithFlexibleName withDeclaredTypes(TypeList declaredTypes) {
1134
            return new Default(name,
1✔
1135
                    modifiers,
1136
                    moduleDescription,
1137
                    typeVariables,
1138
                    superClass,
1139
                    interfaceTypes,
1140
                    fieldTokens,
1141
                    auxiliaryFields,
1142
                    methodTokens,
1143
                    recordComponentTokens,
1144
                    annotationDescriptions,
1145
                    typeInitializer,
1146
                    loadedTypeInitializer,
1147
                    declaringType,
1148
                    enclosingMethod,
1149
                    enclosingType,
1150
                    CompoundList.of(this.declaredTypes, declaredTypes),
1✔
1151
                    permittedSubclasses,
1152
                    anonymousClass,
1153
                    localClass,
1154
                    record,
1155
                    nestHost,
1156
                    nestMembers);
1157
        }
1158

1159
        /**
1160
         * {@inheritDoc}
1161
         */
1162
        public WithFlexibleName withPermittedSubclasses(@MaybeNull TypeList permittedSubclasses) {
1163
            return new Default(name,
1✔
1164
                    modifiers,
1165
                    moduleDescription,
1166
                    typeVariables,
1167
                    superClass,
1168
                    interfaceTypes,
1169
                    fieldTokens,
1170
                    auxiliaryFields,
1171
                    methodTokens,
1172
                    recordComponentTokens,
1173
                    annotationDescriptions,
1174
                    typeInitializer,
1175
                    loadedTypeInitializer,
1176
                    declaringType,
1177
                    enclosingMethod,
1178
                    enclosingType,
1179
                    declaredTypes,
1180
                    permittedSubclasses == null || this.permittedSubclasses == null
1181
                            ? permittedSubclasses
1182
                            : CompoundList.of(this.permittedSubclasses, permittedSubclasses),
1✔
1183
                    anonymousClass,
1184
                    localClass,
1185
                    record,
1186
                    nestHost,
1187
                    nestMembers);
1188
        }
1189

1190
        @Override
1191
        public WithFlexibleName withModuleDescription(@MaybeNull ModuleDescription moduleDescription) {
1192
            return new Default(name,
1✔
1193
                    modifiers,
1194
                    moduleDescription,
1195
                    typeVariables,
1196
                    superClass,
1197
                    interfaceTypes,
1198
                    fieldTokens,
1199
                    auxiliaryFields,
1200
                    methodTokens,
1201
                    recordComponentTokens,
1202
                    annotationDescriptions,
1203
                    typeInitializer,
1204
                    loadedTypeInitializer,
1205
                    declaringType,
1206
                    enclosingMethod,
1207
                    enclosingType,
1208
                    declaredTypes,
1209
                    permittedSubclasses,
1210
                    anonymousClass,
1211
                    localClass,
1212
                    record,
1213
                    nestHost,
1214
                    nestMembers);
1215
        }
1216

1217
        /**
1218
         * {@inheritDoc}
1219
         */
1220
        public WithFlexibleName withTypeVariable(TypeVariableToken typeVariable) {
1221
            return new Default(name,
1✔
1222
                    modifiers,
1223
                    moduleDescription,
1224
                    CompoundList.of(typeVariables, typeVariable.accept(Generic.Visitor.Substitutor.ForDetachment.of(this))),
1✔
1225
                    superClass,
1226
                    interfaceTypes,
1227
                    fieldTokens,
1228
                    auxiliaryFields,
1229
                    methodTokens,
1230
                    recordComponentTokens,
1231
                    annotationDescriptions,
1232
                    typeInitializer,
1233
                    loadedTypeInitializer,
1234
                    declaringType,
1235
                    enclosingMethod,
1236
                    enclosingType,
1237
                    declaredTypes,
1238
                    permittedSubclasses,
1239
                    anonymousClass,
1240
                    localClass,
1241
                    record,
1242
                    nestHost,
1243
                    nestMembers);
1244
        }
1245

1246
        /**
1247
         * {@inheritDoc}
1248
         */
1249
        public WithFlexibleName withName(String name) {
1250
            return new Default(name,
1✔
1251
                    modifiers,
1252
                    moduleDescription,
1253
                    typeVariables,
1254
                    superClass,
1255
                    interfaceTypes,
1256
                    fieldTokens,
1257
                    auxiliaryFields,
1258
                    methodTokens,
1259
                    recordComponentTokens,
1260
                    annotationDescriptions,
1261
                    typeInitializer,
1262
                    loadedTypeInitializer,
1263
                    declaringType,
1264
                    enclosingMethod,
1265
                    enclosingType,
1266
                    declaredTypes,
1267
                    permittedSubclasses,
1268
                    anonymousClass,
1269
                    localClass,
1270
                    record,
1271
                    nestHost,
1272
                    nestMembers);
1273
        }
1274

1275
        /**
1276
         * {@inheritDoc}
1277
         */
1278
        public WithFlexibleName withTypeVariables(ElementMatcher<? super Generic> matcher, Transformer<TypeVariableToken> transformer) {
1279
            List<TypeVariableToken> typeVariables = new ArrayList<TypeVariableToken>(this.typeVariables.size());
1✔
1280
            int index = 0;
1✔
1281
            for (TypeVariableToken typeVariableToken : this.typeVariables) {
1✔
1282
                typeVariables.add(matcher.matches(getTypeVariables().get(index++))
1✔
1283
                        ? transformer.transform(this, typeVariableToken)
1✔
1284
                        : typeVariableToken);
1285
            }
1✔
1286
            return new Default(name,
1✔
1287
                    modifiers,
1288
                    moduleDescription,
1289
                    typeVariables,
1290
                    superClass,
1291
                    interfaceTypes,
1292
                    fieldTokens,
1293
                    auxiliaryFields,
1294
                    methodTokens,
1295
                    recordComponentTokens,
1296
                    annotationDescriptions,
1297
                    typeInitializer,
1298
                    loadedTypeInitializer,
1299
                    declaringType,
1300
                    enclosingMethod,
1301
                    enclosingType,
1302
                    declaredTypes,
1303
                    permittedSubclasses,
1304
                    anonymousClass,
1305
                    localClass,
1306
                    record,
1307
                    nestHost,
1308
                    nestMembers);
1309
        }
1310

1311
        /**
1312
         * {@inheritDoc}
1313
         */
1314
        public WithFlexibleName withLocalClass(boolean localClass) {
1315
            return new Default(name,
1✔
1316
                    modifiers,
1317
                    moduleDescription,
1318
                    typeVariables,
1319
                    superClass,
1320
                    interfaceTypes,
1321
                    fieldTokens,
1322
                    auxiliaryFields,
1323
                    methodTokens,
1324
                    recordComponentTokens,
1325
                    annotationDescriptions,
1326
                    typeInitializer,
1327
                    loadedTypeInitializer,
1328
                    declaringType,
1329
                    enclosingMethod,
1330
                    enclosingType,
1331
                    declaredTypes,
1332
                    permittedSubclasses,
1333
                    false,
1334
                    localClass,
1335
                    record,
1336
                    nestHost,
1337
                    nestMembers);
1338
        }
1339

1340
        /**
1341
         * {@inheritDoc}
1342
         */
1343
        public WithFlexibleName withAnonymousClass(boolean anonymousClass) {
1344
            return new Default(name,
1✔
1345
                    modifiers,
1346
                    moduleDescription,
1347
                    typeVariables,
1348
                    superClass,
1349
                    interfaceTypes,
1350
                    fieldTokens,
1351
                    auxiliaryFields,
1352
                    methodTokens,
1353
                    recordComponentTokens,
1354
                    annotationDescriptions,
1355
                    typeInitializer,
1356
                    loadedTypeInitializer,
1357
                    declaringType,
1358
                    enclosingMethod,
1359
                    enclosingType,
1360
                    declaredTypes,
1361
                    permittedSubclasses,
1362
                    anonymousClass,
1363
                    false,
1364
                    record,
1365
                    nestHost,
1366
                    nestMembers);
1367
        }
1368

1369
        /**
1370
         * {@inheritDoc}
1371
         */
1372
        public WithFlexibleName withRecord(boolean record) {
1373
            return new Default(name,
1✔
1374
                    modifiers,
1375
                    moduleDescription,
1376
                    typeVariables,
1377
                    superClass,
1378
                    interfaceTypes,
1379
                    fieldTokens,
1380
                    auxiliaryFields,
1381
                    methodTokens,
1382
                    record
1383
                            ? recordComponentTokens
1384
                            : Collections.<RecordComponentDescription.Token>emptyList(),
1✔
1385
                    annotationDescriptions,
1386
                    typeInitializer,
1387
                    loadedTypeInitializer,
1388
                    declaringType,
1389
                    enclosingMethod,
1390
                    enclosingType,
1391
                    declaredTypes,
1392
                    permittedSubclasses,
1393
                    anonymousClass,
1394
                    localClass,
1395
                    record,
1396
                    nestHost,
1397
                    nestMembers);
1398
        }
1399

1400
        /**
1401
         * {@inheritDoc}
1402
         */
1403
        public WithFlexibleName withInitializer(LoadedTypeInitializer loadedTypeInitializer) {
1404
            return new Default(name,
1✔
1405
                    modifiers,
1406
                    moduleDescription,
1407
                    typeVariables,
1408
                    superClass,
1409
                    interfaceTypes,
1410
                    fieldTokens,
1411
                    auxiliaryFields,
1412
                    methodTokens,
1413
                    recordComponentTokens,
1414
                    annotationDescriptions,
1415
                    typeInitializer,
1416
                    new LoadedTypeInitializer.Compound(this.loadedTypeInitializer, loadedTypeInitializer),
1417
                    declaringType,
1418
                    enclosingMethod,
1419
                    enclosingType,
1420
                    declaredTypes,
1421
                    permittedSubclasses,
1422
                    anonymousClass,
1423
                    localClass,
1424
                    record,
1425
                    nestHost,
1426
                    nestMembers);
1427
        }
1428

1429
        /**
1430
         * {@inheritDoc}
1431
         */
1432
        public WithFlexibleName withInitializer(ByteCodeAppender byteCodeAppender) {
1433
            return new Default(name,
1✔
1434
                    modifiers,
1435
                    moduleDescription,
1436
                    typeVariables,
1437
                    superClass,
1438
                    interfaceTypes,
1439
                    fieldTokens,
1440
                    auxiliaryFields,
1441
                    methodTokens,
1442
                    recordComponentTokens,
1443
                    annotationDescriptions,
1444
                    typeInitializer.expandWith(byteCodeAppender),
1✔
1445
                    loadedTypeInitializer,
1446
                    declaringType,
1447
                    enclosingMethod,
1448
                    enclosingType,
1449
                    declaredTypes,
1450
                    permittedSubclasses,
1451
                    anonymousClass,
1452
                    localClass,
1453
                    record,
1454
                    nestHost,
1455
                    nestMembers);
1456
        }
1457

1458
        /**
1459
         * {@inheritDoc}
1460
         */
1461
        public LoadedTypeInitializer getLoadedTypeInitializer() {
1462
            return loadedTypeInitializer;
1✔
1463
        }
1464

1465
        /**
1466
         * {@inheritDoc}
1467
         */
1468
        public TypeInitializer getTypeInitializer() {
1469
            return typeInitializer;
1✔
1470
        }
1471

1472
        /**
1473
         * {@inheritDoc}
1474
         */
1475
        @MaybeNull
1476
        public MethodDescription.InDefinedShape getEnclosingMethod() {
1477
            return enclosingMethod;
1✔
1478
        }
1479

1480
        /**
1481
         * {@inheritDoc}
1482
         */
1483
        @MaybeNull
1484
        public TypeDescription getEnclosingType() {
1485
            return enclosingType;
1✔
1486
        }
1487

1488
        /**
1489
         * {@inheritDoc}
1490
         */
1491
        public TypeList getDeclaredTypes() {
1492
            return new TypeList.Explicit(declaredTypes);
1✔
1493
        }
1494

1495
        /**
1496
         * {@inheritDoc}
1497
         */
1498
        public boolean isAnonymousType() {
1499
            return anonymousClass;
1✔
1500
        }
1501

1502
        /**
1503
         * {@inheritDoc}
1504
         */
1505
        public boolean isLocalType() {
1506
            return localClass;
1✔
1507
        }
1508

1509
        /**
1510
         * {@inheritDoc}
1511
         */
1512
        @MaybeNull
1513
        public PackageDescription getPackage() {
1514
            int packageIndex = name.lastIndexOf('.');
1✔
1515
            return packageIndex == -1
1✔
1516
                    ? PackageDescription.DEFAULT
1517
                    : new PackageDescription.Simple(name.substring(0, packageIndex));
1✔
1518
        }
1519

1520
        /**
1521
         * {@inheritDoc}
1522
         */
1523
        @MaybeNull
1524
        public ModuleDescription toModuleDescription() {
1525
            return moduleDescription;
1✔
1526
        }
1527

1528
        /**
1529
         * {@inheritDoc}
1530
         */
1531
        public AnnotationList getDeclaredAnnotations() {
1532
            return new AnnotationList.Explicit(annotationDescriptions);
1✔
1533
        }
1534

1535
        /**
1536
         * {@inheritDoc}
1537
         */
1538
        @MaybeNull
1539
        public TypeDescription getDeclaringType() {
1540
            return declaringType;
1✔
1541
        }
1542

1543
        /**
1544
         * {@inheritDoc}
1545
         */
1546
        @MaybeNull
1547
        public Generic getSuperClass() {
1548
            return superClass == null
1✔
1549
                    ? Generic.UNDEFINED
1550
                    : new Generic.LazyProjection.WithResolvedErasure(superClass, Generic.Visitor.Substitutor.ForAttachment.of(this));
1✔
1551
        }
1552

1553
        /**
1554
         * {@inheritDoc}
1555
         */
1556
        public TypeList.Generic getInterfaces() {
1557
            return new TypeList.Generic.ForDetachedTypes.WithResolvedErasure(interfaceTypes, TypeDescription.Generic.Visitor.Substitutor.ForAttachment.of(this));
1✔
1558
        }
1559

1560
        /**
1561
         * {@inheritDoc}
1562
         */
1563
        public FieldList<FieldDescription.InDefinedShape> getDeclaredFields() {
1564
            return new FieldList.ForTokens(this, fieldTokens);
1✔
1565
        }
1566

1567
        /**
1568
         * {@inheritDoc}
1569
         */
1570
        public MethodList<MethodDescription.InDefinedShape> getDeclaredMethods() {
1571
            return new MethodList.ForTokens(this, methodTokens);
1✔
1572
        }
1573

1574
        /**
1575
         * {@inheritDoc}
1576
         */
1577
        public TypeList.Generic getTypeVariables() {
1578
            return TypeList.Generic.ForDetachedTypes.attachVariables(this, typeVariables);
1✔
1579
        }
1580

1581
        /**
1582
         * {@inheritDoc}
1583
         */
1584
        public int getModifiers() {
1585
            return modifiers;
1✔
1586
        }
1587

1588
        /**
1589
         * {@inheritDoc}
1590
         */
1591
        public String getName() {
1592
            return name;
1✔
1593
        }
1594

1595
        /**
1596
         * {@inheritDoc}
1597
         */
1598
        public TypeDescription getNestHost() {
1599
            return nestHost.represents(TargetType.class)
1✔
1600
                    ? this
1601
                    : nestHost;
1602
        }
1603

1604
        /**
1605
         * {@inheritDoc}
1606
         */
1607
        public TypeList getNestMembers() {
1608
            return nestHost.represents(TargetType.class)
1✔
1609
                    ? new TypeList.Explicit(CompoundList.of(this, nestMembers))
1✔
UNCOV
1610
                    : nestHost.getNestMembers();
×
1611
        }
1612

1613
        /**
1614
         * {@inheritDoc}
1615
         */
1616
        public RecordComponentList<RecordComponentDescription.InDefinedShape> getRecordComponents() {
1617
            return new RecordComponentList.ForTokens(this, recordComponentTokens);
1✔
1618
        }
1619

1620
        /**
1621
         * {@inheritDoc}
1622
         */
1623
        @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Assuming super class for given instance.")
1624
        public boolean isRecord() {
1625
            return record
1✔
1626
                    && superClass != null
1627
                    && getSuperClass().asErasure().equals(JavaType.RECORD.getTypeStub());
1✔
1628
        }
1629

1630
        @Override
1631
        public boolean isSealed() {
1632
            return permittedSubclasses != null;
1✔
1633
        }
1634

1635
        /**
1636
         * {@inheritDoc}
1637
         */
1638
        public TypeList getPermittedSubtypes() {
1639
            return permittedSubclasses == null
1✔
1640
                    ? new TypeList.Empty()
1641
                    : new TypeList.Explicit(permittedSubclasses);
1642
        }
1643

1644
        /**
1645
         * {@inheritDoc}
1646
         */
1647
        public TypeDescription validated() {
1648
            if (!isValidIdentifier(getName().split("\\."))) {
1✔
1649
                throw new IllegalStateException("Illegal type name: " + getName() + " for " + this);
1✔
1650
            } else if ((getModifiers() & ~ModifierContributor.ForType.MASK) != EMPTY_MASK) {
1✔
1651
                throw new IllegalStateException("Illegal modifiers " + getModifiers() + " for " + this);
1✔
1652
            } else if (isPackageType() && getModifiers() != PackageDescription.PACKAGE_MODIFIERS) {
1✔
1653
                throw new IllegalStateException("Illegal modifiers " + getModifiers() + " for package " + this);
1✔
1654
            }
1655
            TypeDescription.Generic superClass = getSuperClass();
1✔
1656
            if (superClass != null) {
1✔
1657
                if (!superClass.accept(Generic.Visitor.Validator.SUPER_CLASS)) {
1✔
1658
                    throw new IllegalStateException("Illegal super class " + superClass + " for " + this);
1✔
1659
                } else if (!superClass.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1660
                    throw new IllegalStateException("Illegal type annotations on super class " + superClass + " for " + this);
1✔
1661
                } else if (!superClass.asErasure().isVisibleTo(this)) {
1✔
1662
                    throw new IllegalStateException("Invisible super type " + superClass + " for " + this);
1✔
1663
                }
1664
            }
1665
            Set<TypeDescription> interfaceErasures = new HashSet<TypeDescription>();
1✔
1666
            for (TypeDescription.Generic interfaceType : getInterfaces()) {
1✔
1667
                if (!interfaceType.accept(Generic.Visitor.Validator.INTERFACE)) {
1✔
1668
                    throw new IllegalStateException("Illegal interface " + interfaceType + " for " + this);
1✔
1669
                } else if (!interfaceType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1670
                    throw new IllegalStateException("Illegal type annotations on interface " + interfaceType + " for " + this);
1✔
1671
                } else if (!interfaceErasures.add(interfaceType.asErasure())) {
1✔
1672
                    throw new IllegalStateException("Already implemented interface " + interfaceType + " for " + this);
1✔
1673
                } else if (!interfaceType.asErasure().isVisibleTo(this)) {
1✔
1674
                    throw new IllegalStateException("Invisible interface type " + interfaceType + " for " + this);
1✔
1675
                }
1676
            }
1✔
1677
            TypeList.Generic typeVariables = getTypeVariables();
1✔
1678
            if (!typeVariables.isEmpty() && isAssignableTo(Throwable.class)) {
1✔
1679
                throw new IllegalStateException("Cannot define throwable " + this + " to be generic");
1✔
1680
            }
1681
            Set<String> typeVariableNames = new HashSet<String>();
1✔
1682
            for (TypeDescription.Generic typeVariable : typeVariables) {
1✔
1683
                String variableSymbol = typeVariable.getSymbol();
1✔
1684
                if (!typeVariableNames.add(variableSymbol)) {
1✔
1685
                    throw new IllegalStateException("Duplicate type variable symbol '" + typeVariable + "' for " + this);
1✔
1686
                } else if (!isValidIdentifier(variableSymbol)) {
1✔
1687
                    throw new IllegalStateException("Illegal type variable name '" + typeVariable + "' for " + this);
1✔
1688
                } else if (!Generic.Visitor.Validator.ForTypeAnnotations.ofFormalTypeVariable(typeVariable)) {
1✔
1689
                    throw new IllegalStateException("Illegal type annotation on '" + typeVariable + "' for " + this);
1✔
1690
                }
1691
                boolean interfaceBound = false;
1✔
1692
                Set<TypeDescription.Generic> bounds = new HashSet<Generic>();
1✔
1693
                for (TypeDescription.Generic bound : typeVariable.getUpperBounds()) {
1✔
1694
                    if (!bound.accept(Generic.Visitor.Validator.TYPE_VARIABLE)) {
1✔
1695
                        throw new IllegalStateException("Illegal type variable bound " + bound + " of " + typeVariable + " for " + this);
1✔
1696
                    } else if (!bound.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1697
                        throw new IllegalStateException("Illegal type annotations on type variable " + bound + " for " + this);
1✔
1698
                    } else if (!bounds.add(bound)) {
1✔
1699
                        throw new IllegalStateException("Duplicate bound " + bound + " of " + typeVariable + " for " + this);
1✔
1700
                    } else if (interfaceBound && (bound.getSort().isTypeVariable() || !bound.isInterface())) {
1✔
1701
                        throw new IllegalStateException("Illegal interface bound " + bound + " of " + typeVariable + " for " + this);
1✔
1702
                    }
1703
                    interfaceBound = true;
1✔
1704
                }
1✔
1705
                if (!interfaceBound) {
1✔
1706
                    throw new IllegalStateException("Type variable " + typeVariable + " for " + this + " does not define at least one bound");
1✔
1707
                }
1708
            }
1✔
1709
            TypeDescription enclosingType = getEnclosingType();
1✔
1710
            if (enclosingType != null && (enclosingType.isArray() || enclosingType.isPrimitive())) {
1✔
1711
                throw new IllegalStateException("Cannot define array type or primitive type " + enclosingType + " + as enclosing type for " + this);
1✔
1712
            }
1713
            MethodDescription.InDefinedShape enclosingMethod = getEnclosingMethod();
1✔
1714
            if (enclosingMethod != null && enclosingMethod.isTypeInitializer()) {
1✔
UNCOV
1715
                throw new IllegalStateException("Cannot enclose type declaration in class initializer " + enclosingMethod);
×
1716
            }
1717
            TypeDescription declaringType = getDeclaringType();
1✔
1718
            if (declaringType != null) {
1✔
1719
                if (declaringType.isPrimitive() || declaringType.isArray()) {
1✔
1720
                    throw new IllegalStateException("Cannot define array type or primitive type " + declaringType + " as declaring type for " + this);
1✔
1721
                }
1722
            } else if (enclosingType == null && enclosingMethod == null && (isLocalType() || isAnonymousType())) {
1✔
1723
                throw new IllegalStateException("Cannot define an anonymous or local class without a declaring type for " + this);
1✔
1724
            }
1725
            Set<TypeDescription> declaredTypes = new HashSet<TypeDescription>();
1✔
1726
            for (TypeDescription declaredType : getDeclaredTypes()) {
1✔
1727
                if (declaredType.isArray() || declaredType.isPrimitive()) {
1✔
1728
                    throw new IllegalStateException("Cannot define array type or primitive type " + declaredType + " + as declared type for " + this);
1✔
1729
                } else if (!declaredTypes.add(declaredType)) {
1✔
1730
                    throw new IllegalStateException("Duplicate definition of declared type " + declaredType);
1✔
1731
                }
1732
            }
1✔
1733
            TypeDescription nestHost = getNestHost();
1✔
1734
            if (nestHost.equals(this)) {
1✔
1735
                Set<TypeDescription> nestMembers = new HashSet<TypeDescription>();
1✔
1736
                for (TypeDescription nestMember : getNestMembers()) {
1✔
1737
                    if (nestMember.isArray() || nestMember.isPrimitive()) {
1✔
1738
                        throw new IllegalStateException("Cannot define array type or primitive type " + nestMember + " + as nest member of " + this);
1✔
1739
                    } else if (!nestMember.isSamePackage(this)) {
1✔
1740
                        throw new IllegalStateException("Cannot define nest member " + nestMember + " + within different package then " + this);
1✔
1741
                    } else if (!nestMembers.add(nestMember)) {
1✔
1742
                        throw new IllegalStateException("Duplicate definition of nest member " + nestMember);
1✔
1743
                    }
1744
                }
1✔
1745
            } else if (nestHost.isArray() || nestHost.isPrimitive()) {
1✔
1746
                throw new IllegalStateException("Cannot define array type or primitive type " + nestHost + " + as nest host for " + this);
1✔
1747
            } else if (!nestHost.isSamePackage(this)) {
1✔
1748
                throw new IllegalStateException("Cannot define nest host " + nestHost + " within different package then " + this);
1✔
1749
            }
1750
            for (TypeDescription permittedSubclass : getPermittedSubtypes()) {
1✔
1751
                if (!permittedSubclass.isAssignableTo(this) || permittedSubclass.equals(this)) {
1✔
1752
                    throw new IllegalStateException("Cannot assign permitted subclass " + permittedSubclass + " to " + this);
1✔
1753
                }
UNCOV
1754
            }
×
1755
            Set<TypeDescription> typeAnnotationTypes = new HashSet<TypeDescription>();
1✔
1756
            for (AnnotationDescription annotationDescription : getDeclaredAnnotations()) {
1✔
1757
                if (!annotationDescription.isSupportedOn(ElementType.TYPE)
1✔
1758
                        && !(isAnnotation() && annotationDescription.isSupportedOn(ElementType.ANNOTATION_TYPE))
1✔
1759
                        && !(isPackageType() && annotationDescription.isSupportedOn(ElementType.PACKAGE))
1✔
1760
                        && !(isModuleType() && annotationDescription.isSupportedOn("MODULE"))) {
1✔
1761
                    throw new IllegalStateException("Cannot add " + annotationDescription + " on " + this);
1✔
1762
                } else if (!typeAnnotationTypes.add(annotationDescription.getAnnotationType())) {
1✔
1763
                    throw new IllegalStateException("Duplicate annotation " + annotationDescription + " for " + this);
1✔
1764
                }
1765
            }
1✔
1766
            Set<FieldDescription.SignatureToken> fieldSignatureTokens = new HashSet<FieldDescription.SignatureToken>();
1✔
1767
            for (FieldDescription.InDefinedShape fieldDescription : getDeclaredFields()) {
1✔
1768
                String fieldName = fieldDescription.getName();
1✔
1769
                if (!fieldSignatureTokens.add(fieldDescription.asSignatureToken())) {
1✔
1770
                    throw new IllegalStateException("Duplicate field definition for " + fieldDescription);
1✔
1771
                } else if (!isValidUnqualifiedNameIdentifier(fieldName)) {
1✔
1772
                    throw new IllegalStateException("Illegal field name for " + fieldDescription);
1✔
1773
                } else if ((fieldDescription.getModifiers() & ~ModifierContributor.ForField.MASK) != EMPTY_MASK) {
1✔
1774
                    throw new IllegalStateException("Illegal field modifiers " + fieldDescription.getModifiers() + " for " + fieldDescription);
1✔
1775
                }
1776
                Generic fieldType = fieldDescription.getType();
1✔
1777
                if (!fieldType.accept(Generic.Visitor.Validator.FIELD)) {
1✔
UNCOV
1778
                    throw new IllegalStateException("Illegal field type " + fieldType + " for " + fieldDescription);
×
1779
                } else if (!fieldType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1780
                    throw new IllegalStateException("Illegal type annotations on " + fieldType + " for " + this);
1✔
1781
                } else if (!fieldDescription.isSynthetic() && !fieldType.asErasure().isVisibleTo(this)) {
1✔
1782
                    throw new IllegalStateException("Invisible field type " + fieldDescription.getType() + " for " + fieldDescription);
1✔
1783
                }
1784
                Set<TypeDescription> fieldAnnotationTypes = new HashSet<TypeDescription>();
1✔
1785
                for (AnnotationDescription annotationDescription : fieldDescription.getDeclaredAnnotations()) {
1✔
1786
                    if (!annotationDescription.isSupportedOn(ElementType.FIELD)) {
1✔
1787
                        throw new IllegalStateException("Cannot add " + annotationDescription + " on " + fieldDescription);
1✔
1788
                    } else if (!fieldAnnotationTypes.add(annotationDescription.getAnnotationType())) {
1✔
1789
                        throw new IllegalStateException("Duplicate annotation " + annotationDescription + " for " + fieldDescription);
1✔
1790
                    }
1791
                }
1✔
1792
            }
1✔
1793
            Set<MethodDescription.SignatureToken> methodSignatureTokens = new HashSet<MethodDescription.SignatureToken>();
1✔
1794
            for (MethodDescription.InDefinedShape methodDescription : getDeclaredMethods()) {
1✔
1795
                if (!methodSignatureTokens.add(methodDescription.asSignatureToken())) {
1✔
1796
                    throw new IllegalStateException("Duplicate method signature for " + methodDescription);
1✔
1797
                } else if ((methodDescription.getModifiers() & ~ModifierContributor.ForMethod.MASK) != 0) {
1✔
1798
                    throw new IllegalStateException("Illegal modifiers " + methodDescription.getModifiers() + " for " + methodDescription);
1✔
1799
                } else if (methodDescription.isAbstract() && (methodDescription.getModifiers() & Opcodes.ACC_STRICT) != 0) {
1✔
UNCOV
1800
                    throw new IllegalStateException("Cannot declare strict computations for " + methodDescription);
×
1801
                } else if (isInterface() && !methodDescription.isPublic() && !methodDescription.isPrivate()) {
1✔
1802
                    throw new IllegalStateException("Methods declared by an interface must be public or private " + methodDescription);
1✔
1803
                }
1804
                Set<String> methodTypeVariableNames = new HashSet<String>();
1✔
1805
                for (TypeDescription.Generic typeVariable : methodDescription.getTypeVariables()) {
1✔
1806
                    String variableSymbol = typeVariable.getSymbol();
1✔
1807
                    if (!methodTypeVariableNames.add(variableSymbol)) {
1✔
1808
                        throw new IllegalStateException("Duplicate type variable symbol '" + typeVariable + "' for " + methodDescription);
1✔
1809
                    } else if (!isValidIdentifier(variableSymbol)) {
1✔
1810
                        throw new IllegalStateException("Illegal type variable name '" + typeVariable + "' for " + methodDescription);
1✔
1811
                    } else if (!Generic.Visitor.Validator.ForTypeAnnotations.ofFormalTypeVariable(typeVariable)) {
1✔
1812
                        throw new IllegalStateException("Illegal type annotation on '" + typeVariable + "' for " + methodDescription);
1✔
1813
                    }
1814
                    boolean interfaceBound = false;
1✔
1815
                    Set<TypeDescription.Generic> bounds = new HashSet<Generic>();
1✔
1816
                    for (TypeDescription.Generic bound : typeVariable.getUpperBounds()) {
1✔
1817
                        if (!bound.accept(Generic.Visitor.Validator.TYPE_VARIABLE)) {
1✔
1818
                            throw new IllegalStateException("Illegal type variable bound " + bound + " of " + typeVariable + " for " + methodDescription);
1✔
1819
                        } else if (!bound.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1820
                            throw new IllegalStateException("Illegal type annotations on bound " + bound + " of " + typeVariable + " for " + this);
1✔
1821
                        } else if (!bounds.add(bound)) {
1✔
1822
                            throw new IllegalStateException("Duplicate bound " + bound + " of " + typeVariable + " for " + methodDescription);
1✔
1823
                        } else if (interfaceBound && (bound.getSort().isTypeVariable() || !bound.isInterface())) {
1✔
1824
                            throw new IllegalStateException("Illegal interface bound " + bound + " of " + typeVariable + " for " + methodDescription);
1✔
1825
                        }
1826
                        interfaceBound = true;
1✔
1827
                    }
1✔
1828
                    if (!interfaceBound) {
1✔
1829
                        throw new IllegalStateException("Type variable " + typeVariable + " for " + methodDescription + " does not define at least one bound");
1✔
1830
                    }
1831
                }
1✔
1832
                Generic returnType = methodDescription.getReturnType();
1✔
1833
                if (methodDescription.isTypeInitializer()) {
1✔
1834
                    throw new IllegalStateException("Illegal explicit declaration of a type initializer by " + this);
1✔
1835
                } else if (methodDescription.isConstructor()) {
1✔
1836
                    if (!returnType.represents(void.class)) {
1✔
1837
                        throw new IllegalStateException("A constructor must return void " + methodDescription);
1✔
1838
                    } else if (!returnType.getDeclaredAnnotations().isEmpty()) {
1✔
UNCOV
1839
                        throw new IllegalStateException("The void non-type must not be annotated for " + methodDescription);
×
1840
                    }
1841
                } else if (!isValidMethodIdentifier(methodDescription.getInternalName())) {
1✔
1842
                    throw new IllegalStateException("Illegal method name " + returnType + " for " + methodDescription);
1✔
1843
                } else if (!returnType.accept(Generic.Visitor.Validator.METHOD_RETURN)) {
1✔
UNCOV
1844
                    throw new IllegalStateException("Illegal return type " + returnType + " for " + methodDescription);
×
1845
                } else if (!returnType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1846
                    throw new IllegalStateException("Illegal type annotations on return type " + returnType + " for " + methodDescription);
1✔
1847
                } else if (!methodDescription.isSynthetic() && !methodDescription.getReturnType().asErasure().isVisibleTo(this)) {
1✔
1848
                    throw new IllegalStateException("Invisible return type " + methodDescription.getReturnType() + " for " + methodDescription);
1✔
1849
                }
1850
                Set<String> parameterNames = new HashSet<String>();
1✔
1851
                for (ParameterDescription.InDefinedShape parameterDescription : methodDescription.getParameters()) {
1✔
1852
                    Generic parameterType = parameterDescription.getType();
1✔
1853
                    if (!parameterType.accept(Generic.Visitor.Validator.METHOD_PARAMETER)) {
1✔
1854
                        throw new IllegalStateException("Illegal parameter type of " + parameterDescription + " for " + methodDescription);
1✔
1855
                    } else if (!parameterType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
UNCOV
1856
                        throw new IllegalStateException("Illegal type annotations on parameter " + parameterDescription + " for " + methodDescription);
×
1857
                    } else if (!methodDescription.isSynthetic() && !parameterType.asErasure().isVisibleTo(this)) {
1✔
1858
                        throw new IllegalStateException("Invisible parameter type of " + parameterDescription + " for " + methodDescription);
1✔
1859
                    }
1860
                    if (parameterDescription.isNamed()) {
1✔
1861
                        String parameterName = parameterDescription.getName();
1✔
1862
                        if (!parameterNames.add(parameterName)) {
1✔
1863
                            throw new IllegalStateException("Duplicate parameter name of " + parameterDescription + " for " + methodDescription);
1✔
1864
                        } else if (!isValidUnqualifiedNameIdentifier(parameterName)) {
1✔
1865
                            throw new IllegalStateException("Illegal parameter name of " + parameterDescription + " for " + methodDescription);
1✔
1866
                        }
1867
                    }
1868
                    if (parameterDescription.hasModifiers() && (parameterDescription.getModifiers() & ~ModifierContributor.ForParameter.MASK) != EMPTY_MASK) {
1✔
1869
                        throw new IllegalStateException("Illegal modifiers of " + parameterDescription + " for " + methodDescription);
1✔
1870
                    }
1871
                    Set<TypeDescription> parameterAnnotationTypes = new HashSet<TypeDescription>();
1✔
1872
                    for (AnnotationDescription annotationDescription : parameterDescription.getDeclaredAnnotations()) {
1✔
1873
                        if (!annotationDescription.isSupportedOn(ElementType.PARAMETER)) {
1✔
1874
                            throw new IllegalStateException("Cannot add " + annotationDescription + " on " + parameterDescription);
1✔
1875
                        } else if (!parameterAnnotationTypes.add(annotationDescription.getAnnotationType())) {
1✔
1876
                            throw new IllegalStateException("Duplicate annotation " + annotationDescription + " of " + parameterDescription + " for " + methodDescription);
1✔
1877
                        }
1878
                    }
1✔
1879
                }
1✔
1880
                for (TypeDescription.Generic exceptionType : methodDescription.getExceptionTypes()) {
1✔
1881
                    if (!exceptionType.accept(Generic.Visitor.Validator.EXCEPTION)) {
1✔
1882
                        throw new IllegalStateException("Illegal exception type " + exceptionType + " for " + methodDescription);
1✔
1883
                    } else if (!exceptionType.accept(Generic.Visitor.Validator.ForTypeAnnotations.INSTANCE)) {
1✔
1884
                        throw new IllegalStateException("Illegal type annotations on " + exceptionType + " for " + methodDescription);
1✔
1885
                    } else if (!methodDescription.isSynthetic() && !exceptionType.asErasure().isVisibleTo(this)) {
1✔
1886
                        throw new IllegalStateException("Invisible exception type " + exceptionType + " for " + methodDescription);
1✔
1887
                    }
1888
                }
1✔
1889
                Set<TypeDescription> methodAnnotationTypes = new HashSet<TypeDescription>();
1✔
1890
                for (AnnotationDescription annotationDescription : methodDescription.getDeclaredAnnotations()) {
1✔
1891
                    if (!annotationDescription.isSupportedOn(methodDescription.isMethod() ? ElementType.METHOD : ElementType.CONSTRUCTOR)) {
1✔
1892
                        throw new IllegalStateException("Cannot add " + annotationDescription + " on " + methodDescription);
1✔
1893
                    } else if (!methodAnnotationTypes.add(annotationDescription.getAnnotationType())) {
1✔
1894
                        throw new IllegalStateException("Duplicate annotation " + annotationDescription + " for " + methodDescription);
1✔
1895
                    }
1896
                }
1✔
1897
                AnnotationValue<?, ?> defaultValue = methodDescription.getDefaultValue();
1✔
1898
                if (defaultValue != null && !methodDescription.isDefaultValue(defaultValue)) {
1✔
1899
                    throw new IllegalStateException("Illegal default value " + defaultValue + "for " + methodDescription);
1✔
1900
                }
1901
                Generic receiverType = methodDescription.getReceiverType();
1✔
1902
                if (receiverType != null && !receiverType.accept(Generic.Visitor.Validator.RECEIVER)) {
1✔
UNCOV
1903
                    throw new IllegalStateException("Illegal receiver type " + receiverType + " for " + methodDescription);
×
1904
                } else if (methodDescription.isStatic()) {
1✔
1905
                    if (receiverType != null) {
1✔
1906
                        throw new IllegalStateException("Static method " + methodDescription + " defines a non-null receiver " + receiverType);
1✔
1907
                    }
1908
                } else if (methodDescription.isConstructor()) {
1✔
1909
                    if (receiverType == null || !receiverType.asErasure().equals(enclosingType == null ? this : enclosingType)) {
1✔
UNCOV
1910
                        throw new IllegalStateException("Constructor " + methodDescription + " defines an illegal receiver " + receiverType);
×
1911
                    }
1912
                } else if (/* methodDescription.isMethod() */ receiverType == null || !equals(receiverType.asErasure())) {
1✔
1913
                    throw new IllegalStateException("Method " + methodDescription + " defines an illegal receiver " + receiverType);
1✔
1914
                }
1915
            }
1✔
1916
            return this;
1✔
1917
        }
1918

1919
        /**
1920
         * Checks if an array of identifiers is a valid compound Java identifier.
1921
         *
1922
         * @param identifier an array of potentially invalid Java identifiers.
1923
         * @return {@code true} if all identifiers are valid and the array is not empty.
1924
         */
1925
        private static boolean isValidIdentifier(String[] identifier) {
1926
            if (identifier.length == 0) {
1✔
UNCOV
1927
                return false;
×
1928
            }
1929
            for (String part : identifier) {
1✔
1930
                if (!isValidIdentifier(part)) {
1✔
1931
                    return false;
1✔
1932
                }
1933
            }
1934
            return true;
1✔
1935
        }
1936

1937
        /**
1938
         * Checks if a Java identifier is valid.
1939
         *
1940
         * @param identifier The identifier to check for validity.
1941
         * @return {@code true} if the given identifier is valid.
1942
         */
1943
        private static boolean isValidIdentifier(String identifier) {
1944
            if (KEYWORDS.contains(identifier)
1✔
1945
                    || identifier.length() == 0
1✔
1946
                    || !(Character.isJavaIdentifierStart(identifier.charAt(0))
1✔
UNCOV
1947
                    || Character.isUnicodeIdentifierStart(identifier.charAt(0)))) {
×
1948
                return false;
1✔
1949
            } else if (identifier.equals(PackageDescription.PACKAGE_CLASS_NAME) || identifier.equals(ModuleDescription.MODULE_CLASS_NAME)) {
1✔
1950
                return true;
1✔
1951
            }
1952
            for (int index = 1; index < identifier.length(); index++) {
1✔
1953
                if (!(Character.isJavaIdentifierPart(identifier.charAt(index)) || Character.isUnicodeIdentifierPart(identifier.charAt(index)))) {
1✔
1954
                    return false;
1✔
1955
                }
1956
            }
1957
            return true;
1✔
1958
        }
1959

1960
        /**
1961
         * Checks if an identifier is a valid "Unqualified Name" for a field, a local variable or a formal parameter,
1962
         * per JVMS 4.2.2.
1963
         *
1964
         * @param identifier The identifier to check for validity.
1965
         * @return {@code true} if the given identifier is valid.
1966
         */
1967
        private static boolean isValidUnqualifiedNameIdentifier(String identifier) {
1968
            if (identifier.length() == 0) {
1✔
UNCOV
1969
                return false;
×
1970
            }
1971
            for (int index = 0; index < identifier.length(); index++) {
1✔
1972
                switch (identifier.charAt(index)) {
1✔
1973
                    case '.':
1974
                    case ';':
1975
                    case '[':
1976
                    case '/':
1977
                        return false;
1✔
1978
                }
1979
            }
1980
            return true;
1✔
1981
        }
1982

1983
        /**
1984
         * Checks if an identifier is a valid "Unqualified Name" for a method, per JVMS 4.2.2.
1985
         *
1986
         * @param identifier The identifier to check for validity.
1987
         * @return {@code true} if the given identifier is valid.
1988
         */
1989
        private static boolean isValidMethodIdentifier(String identifier) {
1990
            if (identifier.length() == 0) {
1✔
UNCOV
1991
                return false;
×
1992
            }
1993
            if (identifier.equals(MethodDescription.TYPE_INITIALIZER_INTERNAL_NAME)
1✔
1994
                    || identifier.equals(MethodDescription.CONSTRUCTOR_INTERNAL_NAME)) {
1✔
UNCOV
1995
                return true;
×
1996
            }
1997
            for (int index = 0; index < identifier.length(); index++) {
1✔
1998
                switch (identifier.charAt(index)) {
1✔
1999
                    case '.':
2000
                    case ';':
2001
                    case '[':
2002
                    case '/':
2003
                    case '<':
2004
                    case '>':
2005
                        return false;
1✔
2006
                }
2007
            }
2008
            return true;
1✔
2009
        }
2010
    }
2011

2012
    /**
2013
     * A frozen representation of an instrumented type of which the structure must not be modified.
2014
     */
2015
    class Frozen extends AbstractBase.OfSimpleType implements InstrumentedType.WithFlexibleName {
2016

2017
        /**
2018
         * The represented type description.
2019
         */
2020
        private final TypeDescription typeDescription;
2021

2022
        /**
2023
         * The type's loaded type initializer.
2024
         */
2025
        private final LoadedTypeInitializer loadedTypeInitializer;
2026

2027
        /**
2028
         * Creates a new frozen representation of an instrumented type.
2029
         *
2030
         * @param typeDescription       The represented type description.
2031
         * @param loadedTypeInitializer The type's loaded type initializer.
2032
         */
2033
        protected Frozen(TypeDescription typeDescription, LoadedTypeInitializer loadedTypeInitializer) {
1✔
2034
            this.typeDescription = typeDescription;
1✔
2035
            this.loadedTypeInitializer = loadedTypeInitializer;
1✔
2036
        }
1✔
2037

2038
        /**
2039
         * {@inheritDoc}
2040
         */
2041
        public AnnotationList getDeclaredAnnotations() {
2042
            return typeDescription.getDeclaredAnnotations();
1✔
2043
        }
2044

2045
        /**
2046
         * {@inheritDoc}
2047
         */
2048
        public int getModifiers() {
2049
            return typeDescription.getModifiers();
1✔
2050
        }
2051

2052
        /**
2053
         * {@inheritDoc}
2054
         */
2055
        public TypeList.Generic getTypeVariables() {
2056
            return typeDescription.getTypeVariables();
1✔
2057
        }
2058

2059
        /**
2060
         * {@inheritDoc}
2061
         */
2062
        public String getName() {
2063
            return typeDescription.getName();
1✔
2064
        }
2065

2066
        /**
2067
         * {@inheritDoc}
2068
         */
2069
        @MaybeNull
2070
        public Generic getSuperClass() {
2071
            return typeDescription.getSuperClass();
1✔
2072
        }
2073

2074
        /**
2075
         * {@inheritDoc}
2076
         */
2077
        public TypeList.Generic getInterfaces() {
2078
            return typeDescription.getInterfaces();
1✔
2079
        }
2080

2081
        /**
2082
         * {@inheritDoc}
2083
         */
2084
        public FieldList<FieldDescription.InDefinedShape> getDeclaredFields() {
2085
            return typeDescription.getDeclaredFields();
1✔
2086
        }
2087

2088
        /**
2089
         * {@inheritDoc}
2090
         */
2091
        public MethodList<MethodDescription.InDefinedShape> getDeclaredMethods() {
2092
            return typeDescription.getDeclaredMethods();
1✔
2093
        }
2094

2095
        /**
2096
         * {@inheritDoc}
2097
         */
2098
        public boolean isAnonymousType() {
2099
            return typeDescription.isAnonymousType();
1✔
2100
        }
2101

2102
        /**
2103
         * {@inheritDoc}
2104
         */
2105
        public boolean isLocalType() {
2106
            return typeDescription.isLocalType();
1✔
2107
        }
2108

2109
        /**
2110
         * {@inheritDoc}
2111
         */
2112
        @MaybeNull
2113
        public PackageDescription getPackage() {
2114
            return typeDescription.getPackage();
1✔
2115
        }
2116

2117
        /**
2118
         * {@inheritDoc}
2119
         */
2120
        @MaybeNull
2121
        public ModuleDescription toModuleDescription() {
2122
            return typeDescription.toModuleDescription();
1✔
2123
        }
2124

2125
        /**
2126
         * {@inheritDoc}
2127
         */
2128
        @MaybeNull
2129
        public TypeDescription getEnclosingType() {
2130
            return typeDescription.getEnclosingType();
1✔
2131
        }
2132

2133
        /**
2134
         * {@inheritDoc}
2135
         */
2136
        @MaybeNull
2137
        public TypeDescription getDeclaringType() {
2138
            return typeDescription.getDeclaringType();
1✔
2139
        }
2140

2141
        /**
2142
         * {@inheritDoc}
2143
         */
2144
        public TypeList getDeclaredTypes() {
2145
            return typeDescription.getDeclaredTypes();
1✔
2146
        }
2147

2148
        /**
2149
         * {@inheritDoc}
2150
         */
2151
        @MaybeNull
2152
        public MethodDescription.InDefinedShape getEnclosingMethod() {
2153
            return typeDescription.getEnclosingMethod();
1✔
2154
        }
2155

2156
        /**
2157
         * {@inheritDoc}
2158
         */
2159
        @MaybeNull
2160
        public String getGenericSignature() {
2161
            // Embrace use of native generic signature by direct delegation.
2162
            return typeDescription.getGenericSignature();
1✔
2163
        }
2164

2165
        /**
2166
         * {@inheritDoc}
2167
         */
2168
        public int getActualModifiers(boolean superFlag) {
2169
            // Embrace use of native actual modifiers by direct delegation.
2170
            return typeDescription.getActualModifiers(superFlag);
1✔
2171
        }
2172

2173
        /**
2174
         * {@inheritDoc}
2175
         */
2176
        public TypeDescription getNestHost() {
2177
            return typeDescription.getNestHost();
1✔
2178
        }
2179

2180
        /**
2181
         * {@inheritDoc}
2182
         */
2183
        public TypeList getNestMembers() {
2184
            return typeDescription.getNestMembers();
1✔
2185
        }
2186

2187
        /**
2188
         * {@inheritDoc}
2189
         */
2190
        public RecordComponentList<RecordComponentDescription.InDefinedShape> getRecordComponents() {
2191
            return typeDescription.getRecordComponents();
1✔
2192
        }
2193

2194
        /**
2195
         * {@inheritDoc}
2196
         */
2197
        public boolean isRecord() {
UNCOV
2198
            return typeDescription.isRecord();
×
2199
        }
2200

2201
        @Override
2202
        public boolean isSealed() {
2203
            return typeDescription.isSealed();
1✔
2204
        }
2205

2206
        /**
2207
         * {@inheritDoc}
2208
         */
2209
        public TypeList getPermittedSubtypes() {
2210
            return typeDescription.getPermittedSubtypes();
1✔
2211
        }
2212

2213
        /**
2214
         * {@inheritDoc}
2215
         */
2216
        public WithFlexibleName withModuleDescription(@MaybeNull ModuleDescription moduleDescription) {
UNCOV
2217
            throw new IllegalStateException("Cannot define module meta data for frozen type: " + typeDescription);
×
2218
        }
2219

2220
        /**
2221
         * {@inheritDoc}
2222
         */
2223
        public WithFlexibleName withField(FieldDescription.Token token) {
2224
            throw new IllegalStateException("Cannot define field for frozen type: " + typeDescription);
1✔
2225
        }
2226

2227
        /**
2228
         * {@inheritDoc}
2229
         */
2230
        public WithFlexibleName withAuxiliaryField(FieldDescription.Token token, Object value) {
2231
            throw new IllegalStateException("Cannot define auxiliary field for frozen type: " + typeDescription);
1✔
2232
        }
2233

2234
        /**
2235
         * {@inheritDoc}
2236
         */
2237
        public WithFlexibleName withMethod(MethodDescription.Token token) {
2238
            throw new IllegalStateException("Cannot define method for frozen type: " + typeDescription);
1✔
2239
        }
2240

2241
        /**
2242
         * {@inheritDoc}
2243
         */
2244
        public WithFlexibleName withRecordComponent(RecordComponentDescription.Token token) {
2245
            throw new IllegalStateException("Cannot define record component for frozen type: " + typeDescription);
1✔
2246
        }
2247

2248
        /**
2249
         * {@inheritDoc}
2250
         */
2251
        public WithFlexibleName withModifiers(int modifiers) {
UNCOV
2252
            throw new IllegalStateException("Cannot change modifiers for frozen type: " + typeDescription);
×
2253
        }
2254

2255
        /**
2256
         * {@inheritDoc}
2257
         */
2258
        public WithFlexibleName withInterfaces(TypeList.Generic interfaceTypes) {
UNCOV
2259
            throw new IllegalStateException("Cannot add interfaces for frozen type: " + typeDescription);
×
2260
        }
2261

2262
        /**
2263
         * {@inheritDoc}
2264
         */
2265
        public WithFlexibleName withTypeVariable(TypeVariableToken typeVariable) {
2266
            throw new IllegalStateException("Cannot define type variable for frozen type: " + typeDescription);
1✔
2267
        }
2268

2269
        /**
2270
         * {@inheritDoc}
2271
         */
2272
        public WithFlexibleName withAnnotations(List<? extends AnnotationDescription> annotationDescriptions) {
2273
            throw new IllegalStateException("Cannot add annotation to frozen type: " + typeDescription);
1✔
2274
        }
2275

2276
        /**
2277
         * {@inheritDoc}
2278
         */
2279
        public WithFlexibleName withNestHost(TypeDescription nestHost) {
2280
            throw new IllegalStateException("Cannot set nest host of frozen type: " + typeDescription);
1✔
2281
        }
2282

2283
        /**
2284
         * {@inheritDoc}
2285
         */
2286
        public WithFlexibleName withNestMembers(TypeList nestMembers) {
2287
            throw new IllegalStateException("Cannot add nest members to frozen type: " + typeDescription);
1✔
2288
        }
2289

2290
        /**
2291
         * {@inheritDoc}
2292
         */
2293
        public WithFlexibleName withEnclosingType(@MaybeNull TypeDescription enclosingType) {
2294
            throw new IllegalStateException("Cannot set enclosing type of frozen type: " + typeDescription);
1✔
2295
        }
2296

2297
        /**
2298
         * {@inheritDoc}
2299
         */
2300
        public WithFlexibleName withEnclosingMethod(MethodDescription.InDefinedShape enclosingMethod) {
2301
            throw new IllegalStateException("Cannot set enclosing method of frozen type: " + typeDescription);
1✔
2302
        }
2303

2304
        /**
2305
         * {@inheritDoc}
2306
         */
2307
        public WithFlexibleName withDeclaringType(@MaybeNull TypeDescription declaringType) {
2308
            throw new IllegalStateException("Cannot add declaring type to frozen type: " + typeDescription);
1✔
2309
        }
2310

2311
        /**
2312
         * {@inheritDoc}
2313
         */
2314
        public WithFlexibleName withDeclaredTypes(TypeList declaredTypes) {
2315
            throw new IllegalStateException("Cannot add declared types to frozen type: " + typeDescription);
1✔
2316
        }
2317

2318
        /**
2319
         * {@inheritDoc}
2320
         */
2321
        public WithFlexibleName withPermittedSubclasses(@MaybeNull TypeList permittedSubclasses) {
2322
            throw new IllegalStateException("Cannot add permitted subclasses to frozen type: " + typeDescription);
1✔
2323
        }
2324

2325
        /**
2326
         * {@inheritDoc}
2327
         */
2328
        public WithFlexibleName withLocalClass(boolean localClass) {
2329
            throw new IllegalStateException("Cannot define local class state for frozen type: " + typeDescription);
1✔
2330
        }
2331

2332
        /**
2333
         * {@inheritDoc}
2334
         */
2335
        public WithFlexibleName withAnonymousClass(boolean anonymousClass) {
2336
            throw new IllegalStateException("Cannot define anonymous class state for frozen type: " + typeDescription);
1✔
2337
        }
2338

2339
        /**
2340
         * {@inheritDoc}
2341
         */
2342
        public WithFlexibleName withRecord(boolean record) {
2343
            throw new IllegalStateException("Cannot define record state for frozen type: " + typeDescription);
1✔
2344
        }
2345

2346
        /**
2347
         * {@inheritDoc}
2348
         */
2349
        public WithFlexibleName withInitializer(LoadedTypeInitializer loadedTypeInitializer) {
UNCOV
2350
            return new Frozen(typeDescription, new LoadedTypeInitializer.Compound(this.loadedTypeInitializer, loadedTypeInitializer));
×
2351
        }
2352

2353
        /**
2354
         * {@inheritDoc}
2355
         */
2356
        public WithFlexibleName withInitializer(ByteCodeAppender byteCodeAppender) {
2357
            throw new IllegalStateException("Cannot add initializer to frozen type: " + typeDescription);
1✔
2358
        }
2359

2360
        /**
2361
         * {@inheritDoc}
2362
         */
2363
        public WithFlexibleName withName(String name) {
2364
            throw new IllegalStateException("Cannot change name of frozen type: " + typeDescription);
1✔
2365
        }
2366

2367
        /**
2368
         * {@inheritDoc}
2369
         */
2370
        public WithFlexibleName withTypeVariables(ElementMatcher<? super Generic> matcher, Transformer<TypeVariableToken> transformer) {
2371
            throw new IllegalStateException("Cannot add type variables of frozen type: " + typeDescription);
1✔
2372
        }
2373

2374
        /**
2375
         * {@inheritDoc}
2376
         */
2377
        public LoadedTypeInitializer getLoadedTypeInitializer() {
2378
            return loadedTypeInitializer;
1✔
2379
        }
2380

2381
        /**
2382
         * {@inheritDoc}
2383
         */
2384
        public TypeInitializer getTypeInitializer() {
2385
            return TypeInitializer.None.INSTANCE;
1✔
2386
        }
2387

2388
        @MaybeNull
2389
        @Override
2390
        public ClassFileVersion getClassFileVersion() {
2391
            return typeDescription.getClassFileVersion();
1✔
2392
        }
2393

2394
        /**
2395
         * {@inheritDoc}
2396
         */
2397
        public TypeDescription validated() {
2398
            return typeDescription;
1✔
2399
        }
2400
    }
2401
}
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