/
ParameterDescription.java
885 lines (757 loc) · 30.2 KB
/
ParameterDescription.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
package net.bytebuddy.description.method;
import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.annotation.AnnotatedCodeElement;
import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.TypeList;
import net.bytebuddy.description.type.generic.GenericTypeDescription;
import net.bytebuddy.implementation.bytecode.StackSize;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.utility.JavaMethod;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.AbstractList;
import java.util.Collections;
import java.util.List;
import static net.bytebuddy.matcher.ElementMatchers.none;
/**
* Description of the parameter of a Java method or constructor.
*/
public interface ParameterDescription extends AnnotatedCodeElement,
NamedElement.WithRuntimeName,
ModifierReviewable,
ByteCodeElement.TypeDependant<ParameterDescription.InDefinedShape, ParameterDescription.Token> {
/**
* The prefix for names of an unnamed parameter.
*/
String NAME_PREFIX = "arg";
/**
* Returns the type of this parameter.
*
* @return The type of this parameter.
*/
GenericTypeDescription getType();
/**
* Returns the method that declares this parameter.
*
* @return The method that declares this parameter.
*/
MethodDescription getDeclaringMethod();
/**
* Returns this parameter's index.
*
* @return The index of this parameter.
*/
int getIndex();
/**
* Checks if this parameter has an explicit name. A parameter without an explicit name is named implicitly by
* {@code argX} with {@code X} denoting the zero-based index.
*
* @return {@code true} if the parameter has an explicit name.
*/
boolean isNamed();
/**
* Checks if this parameter has an explicit modifier. A parameter without a modifier is simply treated as
* if it had a modifier of zero.
*
* @return {@code true} if this parameter defines explicit modifiers.
*/
boolean hasModifiers();
/**
* Returns the offset to the parameter value within the local method variable.
*
* @return The offset of this parameter's value.
*/
int getOffset();
interface InDefinedShape extends ParameterDescription {
@Override
MethodDescription.InDefinedShape getDeclaringMethod();
abstract class AbstractBase extends ParameterDescription.AbstractBase implements InDefinedShape {
@Override
public InDefinedShape asDefined() {
return this;
}
}
}
/**
* A base implementation of a method parameter description.
*/
abstract class AbstractBase extends ModifierReviewable.AbstractBase implements ParameterDescription {
@Override
public String getName() {
return NAME_PREFIX.concat(String.valueOf(getIndex()));
}
@Override
public String getInternalName() {
return getName();
}
@Override
public String getSourceCodeName() {
return isNamed()
? getName()
: EMPTY_NAME;
}
@Override
public int getModifiers() {
return EMPTY_MASK;
}
@Override
public int getOffset() {
TypeList parameterType = getDeclaringMethod().getParameters().asTypeList().asRawTypes();
int offset = getDeclaringMethod().isStatic()
? StackSize.ZERO.getSize()
: StackSize.SINGLE.getSize();
for (int i = 0; i < getIndex(); i++) {
offset += parameterType.get(i).getStackSize().getSize();
}
return offset;
}
@Override
public Token asToken() {
return asToken(none());
}
@Override
public Token asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
return new Token(getType().accept(new GenericTypeDescription.Visitor.Substitutor.ForDetachment(targetTypeMatcher)),
getDeclaredAnnotations(),
isNamed()
? getName()
: Token.NO_NAME,
hasModifiers()
? (Integer) getModifiers()
: Token.NO_MODIFIERS);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (!(other instanceof ParameterDescription)) {
return false;
}
ParameterDescription parameterDescription = (ParameterDescription) other;
return getDeclaringMethod().equals(parameterDescription.getDeclaringMethod())
&& getIndex() == parameterDescription.getIndex();
}
@Override
public int hashCode() {
return getDeclaringMethod().hashCode() ^ getIndex();
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder(Modifier.toString(getModifiers()));
if (getModifiers() != EMPTY_MASK) {
stringBuilder.append(' ');
}
stringBuilder.append(isVarArgs()
? getType().asRawType().getName().replaceFirst("\\[\\]$", "...")
: getType().asRawType().getName());
return stringBuilder.append(' ').append(getName()).toString();
}
}
/**
* Description of a loaded parameter, represented by a Java 8 {@code java.lang.reflect.Parameter}.
*/
class ForLoadedParameter extends InDefinedShape.AbstractBase {
/**
* Java method representation for the {@code java.lang.reflect.Parameter}'s {@code getType} method.
*/
protected static final JavaMethod GET_TYPE;
/**
* Java method representation for the {@code java.lang.reflect.Parameter}'s {@code getName} method.
*/
private static final JavaMethod GET_NAME;
/**
* Java method representation for the {@code java.lang.reflect.Parameter}'s
* {@code getDeclaringExecutable} method.
*/
private static final JavaMethod GET_DECLARING_EXECUTABLE;
/**
* Java method representation for the {@code java.lang.reflect.Parameter}'s {@code isNamePresent} method.
*/
private static final JavaMethod IS_NAME_PRESENT;
/**
* Java method representation for the {@code java.lang.reflect.Parameter}'s {@code getModifiers} method.
*/
private static final JavaMethod GET_MODIFIERS;
/**
* Java method representation for the {@code java.lang.reflect.Parameter}'s {@code getDeclaredAnnotations}
* method.
*/
private static final JavaMethod GET_DECLARED_ANNOTATIONS;
/*
* Initializes the {@link net.bytebuddy.utility.JavaMethod} instances of this class dependant on
* whether they are available.
*/
static {
JavaMethod getName, getDeclaringExecutable, isNamePresent, getModifiers, getDeclaredAnnotations, getType;
try {
Class<?> parameterType = Class.forName("java.lang.reflect.Parameter");
getName = new JavaMethod.ForLoadedMethod(parameterType.getDeclaredMethod("getName"));
getDeclaringExecutable = new JavaMethod.ForLoadedMethod(parameterType.getDeclaredMethod("getDeclaringExecutable"));
isNamePresent = new JavaMethod.ForLoadedMethod(parameterType.getDeclaredMethod("isNamePresent"));
getModifiers = new JavaMethod.ForLoadedMethod(parameterType.getDeclaredMethod("getModifiers"));
getDeclaredAnnotations = new JavaMethod.ForLoadedMethod(parameterType.getDeclaredMethod("getDeclaredAnnotations"));
getType = new JavaMethod.ForLoadedMethod(parameterType.getDeclaredMethod("getType"));
} catch (Exception ignored) {
getName = JavaMethod.ForUnavailableMethod.INSTANCE;
getDeclaringExecutable = JavaMethod.ForUnavailableMethod.INSTANCE;
isNamePresent = JavaMethod.ForUnavailableMethod.INSTANCE;
getModifiers = JavaMethod.ForUnavailableMethod.INSTANCE;
getDeclaredAnnotations = JavaMethod.ForUnavailableMethod.INSTANCE;
getType = JavaMethod.ForUnavailableMethod.INSTANCE;
}
GET_NAME = getName;
GET_DECLARING_EXECUTABLE = getDeclaringExecutable;
IS_NAME_PRESENT = isNamePresent;
GET_MODIFIERS = getModifiers;
GET_DECLARED_ANNOTATIONS = getDeclaredAnnotations;
GET_TYPE = getType;
}
/**
* An instance of {@code java.lang.reflect.Parameter}.
*/
private final Object parameter;
/**
* The parameter's index.
*/
private final int index;
/**
* Creates a representation of a loaded parameter.
*
* @param parameter An instance of {@code java.lang.reflect.Parameter}.
* @param index The parameter's index.
*/
protected ForLoadedParameter(Object parameter, int index) {
this.parameter = parameter;
this.index = index;
}
@Override
public GenericTypeDescription getType() {
return new GenericTypeDescription.LazyProjection.OfLoadedParameter(parameter);
}
@Override
public MethodDescription.InDefinedShape getDeclaringMethod() {
Object executable = GET_DECLARING_EXECUTABLE.invoke(parameter);
if (executable instanceof Method) {
return new MethodDescription.ForLoadedMethod((Method) executable);
} else if (executable instanceof Constructor) {
return new MethodDescription.ForLoadedConstructor((Constructor<?>) executable);
} else {
throw new IllegalStateException("Unknown executable type: " + executable);
}
}
@Override
public AnnotationList getDeclaredAnnotations() {
return new AnnotationList.ForLoadedAnnotation((Annotation[]) GET_DECLARED_ANNOTATIONS.invoke(parameter));
}
@Override
public String getName() {
return (String) GET_NAME.invoke(parameter);
}
@Override
public int getIndex() {
return index;
}
@Override
public boolean isNamed() {
return (Boolean) IS_NAME_PRESENT.invoke(parameter);
}
@Override
public int getModifiers() {
return (Integer) GET_MODIFIERS.invoke(parameter);
}
@Override
public boolean hasModifiers() {
// Rational: If a parameter is not named despite the information being attached,
// it is synthetic, i.e. it has non-default modifiers.
return isNamed() || getModifiers() != EMPTY_MASK;
}
/**
* Description of a loaded method's parameter on a virtual machine where {@code java.lang.reflect.Parameter}
* is not available.
*/
protected static class OfLegacyVmMethod extends InDefinedShape.AbstractBase {
/**
* The method that declares this parameter.
*/
private final Method method;
/**
* The index of this parameter.
*/
private final int index;
/**
* The type of this parameter.
*/
private final Class<?> parameterType;
/**
* The annotations of this parameter.
*/
private final Annotation[] parameterAnnotation;
/**
* Creates a legacy representation of a method's parameter.
*
* @param method The method that declares this parameter.
* @param index The index of this parameter.
* @param parameterType The type of this parameter.
* @param parameterAnnotation The annotations of this parameter.
*/
protected OfLegacyVmMethod(Method method, int index, Class<?> parameterType, Annotation[] parameterAnnotation) {
this.method = method;
this.index = index;
this.parameterType = parameterType;
this.parameterAnnotation = parameterAnnotation;
}
@Override
public GenericTypeDescription getType() {
return new TypeDescription.LazyProjection.OfLoadedParameter.OfLegacyVmMethod(method, index, parameterType);
}
@Override
public MethodDescription.InDefinedShape getDeclaringMethod() {
return new MethodDescription.ForLoadedMethod(method);
}
@Override
public int getIndex() {
return index;
}
@Override
public boolean isNamed() {
return false;
}
@Override
public boolean hasModifiers() {
return false;
}
@Override
public AnnotationList getDeclaredAnnotations() {
return new AnnotationList.ForLoadedAnnotation(parameterAnnotation);
}
}
/**
* Description of a loaded constructor's parameter on a virtual machine where {@code java.lang.reflect.Parameter}
* is not available.
*/
protected static class OfLegacyVmConstructor extends InDefinedShape.AbstractBase {
/**
* The method that declares this parameter.
*/
private final Constructor<?> constructor;
/**
* The index of this parameter.
*/
private final int index;
/**
* The type of this parameter.
*/
private final Class<?> parameterType;
/**
* The annotations of this parameter.
*/
private final Annotation[] parameterAnnotation;
/**
* Creates a legacy representation of a method's parameter.
*
* @param constructor The constructor that declares this parameter.
* @param index The index of this parameter.
* @param parameterType The type of this parameter.
* @param parameterAnnotation The annotations of this parameter.
*/
protected OfLegacyVmConstructor(Constructor<?> constructor, int index, Class<?> parameterType, Annotation[] parameterAnnotation) {
this.constructor = constructor;
this.index = index;
this.parameterType = parameterType;
this.parameterAnnotation = parameterAnnotation;
}
@Override
public GenericTypeDescription getType() {
return new TypeDescription.LazyProjection.OfLoadedParameter.OfLegacyVmConstructor(constructor, index, parameterType);
}
@Override
public MethodDescription.InDefinedShape getDeclaringMethod() {
return new MethodDescription.ForLoadedConstructor(constructor);
}
@Override
public int getIndex() {
return index;
}
@Override
public boolean isNamed() {
return false;
}
@Override
public boolean hasModifiers() {
return false;
}
@Override
public AnnotationList getDeclaredAnnotations() {
return new AnnotationList.ForLoadedAnnotation(parameterAnnotation);
}
}
}
/**
* A latent description of a parameter that is not attached to a method or constructor.
*/
class Latent extends InDefinedShape.AbstractBase {
/**
* The method that is declaring the parameter.
*/
private final MethodDescription.InDefinedShape declaringMethod;
/**
* The type of the parameter.
*/
private final GenericTypeDescription parameterType;
/**
* The annotations of the parameter.
*/
private final List<? extends AnnotationDescription> declaredAnnotations;
/**
* The name of the parameter or {@code null} if no name is explicitly defined.
*/
private final String name;
/**
* The modifiers of the parameter or {@code null} if no modifiers are explicitly defined.
*/
private final Integer modifiers;
/**
* The index of the parameter.
*/
private final int index;
/**
* The parameter's offset in the local method variables array.
*/
private final int offset;
/**
* Creates a latent parameter description. All provided types are attached to this instance before they are returned.
*
* @param declaringMethod The method that is declaring the parameter.
* @param token The token describing the shape of the parameter.
* @param index The index of the parameter.
* @param offset The parameter's offset in the local method variables array.
*/
public Latent(MethodDescription.InDefinedShape declaringMethod, Token token, int index, int offset) {
this(declaringMethod,
token.getType(),
token.getAnnotations(),
token.getName(),
token.getModifiers(),
index,
offset);
}
/**
* Creates a new latent parameter descriptions for a parameter without explicit meta data or annotations.
*
* @param declaringMethod The method declaring this parameter.
* @param parameterType The type of the parameter.
* @param index The index of the parameter.
* @param offset The offset of the parameter.
*/
public Latent(MethodDescription.InDefinedShape declaringMethod,
GenericTypeDescription parameterType,
int index,
int offset) {
this(declaringMethod,
parameterType,
Collections.<AnnotationDescription>emptyList(),
Token.NO_NAME,
Token.NO_MODIFIERS,
index,
offset);
}
/**
* Creates a latent parameter description. All provided types are attached to this instance before they are returned.
*
* @param declaringMethod The method that is declaring the parameter.
* @param parameterType The parameter's type.
* @param declaredAnnotations The annotations of the parameter.
* @param name The name of the parameter or {@code null} if no name is explicitly defined.
* @param modifiers The modifiers of the parameter or {@code null} if no modifiers are explicitly defined.
* @param index The index of the parameter.
* @param offset The parameter's offset in the local method variables array.
*/
public Latent(MethodDescription.InDefinedShape declaringMethod,
GenericTypeDescription parameterType,
List<? extends AnnotationDescription> declaredAnnotations,
String name,
Integer modifiers,
int index,
int offset) {
this.declaringMethod = declaringMethod;
this.parameterType = parameterType;
this.declaredAnnotations = declaredAnnotations;
this.name = name;
this.modifiers = modifiers;
this.index = index;
this.offset = offset;
}
@Override
public GenericTypeDescription getType() {
return parameterType.accept(GenericTypeDescription.Visitor.Substitutor.ForAttachment.of(this));
}
@Override
public MethodDescription.InDefinedShape getDeclaringMethod() {
return declaringMethod;
}
@Override
public int getIndex() {
return index;
}
@Override
public int getOffset() {
return offset;
}
@Override
public boolean isNamed() {
return name != null;
}
@Override
public boolean hasModifiers() {
return modifiers != null;
}
@Override
public String getName() {
return isNamed()
? name
: super.getName();
}
@Override
public int getModifiers() {
return hasModifiers()
? modifiers
: super.getModifiers();
}
@Override
public AnnotationList getDeclaredAnnotations() {
return new AnnotationList.Explicit(declaredAnnotations);
}
}
/**
* <p>
* A parameter description that represents a given parameter but with a substituted parameter type.
* </p>
* <p>
* <b>Note</b>: The supplied visitor must assure to not substitute
* </p>
*/
class TypeSubstituting extends AbstractBase {
/**
* The method that declares this type-substituted parameter.
*/
private final MethodDescription declaringMethod;
/**
* The represented parameter.
*/
private final ParameterDescription parameterDescription;
/**
* A visitor that is applied to the parameter type.
*/
private final GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor;
/**
* Creates a new type substituting parameter.
*
* @param declaringMethod The method that declares this type-substituted parameter.
* @param parameterDescription The represented parameter.
* @param visitor A visitor that is applied to the parameter type.
*/
public TypeSubstituting(MethodDescription declaringMethod,
ParameterDescription parameterDescription,
GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) {
this.declaringMethod = declaringMethod;
this.parameterDescription = parameterDescription;
this.visitor = visitor;
}
@Override
public GenericTypeDescription getType() {
return parameterDescription.getType().accept(visitor);
}
@Override
public MethodDescription getDeclaringMethod() {
return declaringMethod;
}
@Override
public int getIndex() {
return parameterDescription.getIndex();
}
@Override
public boolean isNamed() {
return parameterDescription.isNamed();
}
@Override
public boolean hasModifiers() {
return parameterDescription.hasModifiers();
}
@Override
public int getOffset() {
return parameterDescription.getOffset();
}
@Override
public String getName() {
return parameterDescription.getName();
}
@Override
public int getModifiers() {
return parameterDescription.getModifiers();
}
@Override
public AnnotationList getDeclaredAnnotations() {
return parameterDescription.getDeclaredAnnotations();
}
@Override
public InDefinedShape asDefined() {
return parameterDescription.asDefined();
}
}
/**
* A token that describes the shape of a method parameter. A parameter token is equal to another parameter token if
* their explicit names are explicitly defined and equal or if the token is of the same identity.
*/
class Token implements ByteCodeElement.Token<Token> {
/**
* Indicator for a method parameter without an explicit name.
*/
public static final String NO_NAME = null;
/**
* Indicator for a method parameter without explicit modifiers.
*/
public static final Integer NO_MODIFIERS = null;
/**
* The type of the represented parameter.
*/
private final GenericTypeDescription typeDescription;
/**
* A list of parameter annotations.
*/
private final List<? extends AnnotationDescription> annotationDescriptions;
/**
* The name of the parameter or {@code null} if no explicit name is defined.
*/
private final String name;
/**
* The modifiers of the parameter or {@code null} if no explicit modifiers is defined.
*/
private final Integer modifiers;
/**
* Creates a new parameter token without an explicit name, an explicit modifier or annotations.
*
* @param typeDescription The type of the represented parameter.
*/
public Token(GenericTypeDescription typeDescription) {
this(typeDescription, Collections.<AnnotationDescription>emptyList());
}
/**
* Creates a new parameter token without an explicit name or an explicit modifier.
*
* @param typeDescription The type of the represented parameter.
* @param annotationDescriptions The annotations of the parameter.
*/
public Token(GenericTypeDescription typeDescription, List<? extends AnnotationDescription> annotationDescriptions) {
this(typeDescription, annotationDescriptions, NO_NAME, NO_MODIFIERS);
}
/**
* Creates a new parameter token.
*
* @param typeDescription The type of the represented parameter.
* @param annotationDescriptions The annotations of the parameter.
* @param name The name of the parameter or {@code null} if no explicit name is defined.
* @param modifiers The modifiers of the parameter or {@code null} if no explicit modifiers is defined.
*/
public Token(GenericTypeDescription typeDescription,
List<? extends AnnotationDescription> annotationDescriptions,
String name,
Integer modifiers) {
this.typeDescription = typeDescription;
this.annotationDescriptions = annotationDescriptions;
this.name = name;
this.modifiers = modifiers;
}
/**
* Returns the type of the represented method parameter.
*
* @return The type of the represented method parameter.
*/
public GenericTypeDescription getType() {
return typeDescription;
}
/**
* Returns the annotations of the represented method parameter.
*
* @return The annotations of the represented method parameter.
*/
public AnnotationList getAnnotations() {
return new AnnotationList.Explicit(annotationDescriptions);
}
/**
* Returns the name of the represented method parameter.
*
* @return The name of the parameter or {@code null} if no explicit name is defined.
*/
public String getName() {
return name;
}
/**
* Returns the modifiers of the represented method parameter.
*
* @return The modifiers of the parameter or {@code null} if no explicit modifiers is defined.
*/
public Integer getModifiers() {
return modifiers;
}
@Override
public Token accept(GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) {
return new Token(getType().accept(visitor),
getAnnotations(),
getName(),
getModifiers());
}
@Override
public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof Token)) return false;
String name = getName();
return name != null && name.equals(((Token) other).getName());
}
@Override
public int hashCode() {
return name != null
? name.hashCode()
: super.hashCode();
}
@Override
public String toString() {
return "ParameterDescription.Token{" +
"typeDescription=" + typeDescription +
", annotationDescriptions=" + annotationDescriptions +
", name='" + name + '\'' +
", modifiers=" + modifiers +
'}';
}
/**
* A list of types represented as a list of parameter tokens.
*/
public static class TypeList extends AbstractList<Token> {
/**
* The list of types to represent as parameter tokens.
*/
private final List<? extends GenericTypeDescription> typeDescriptions;
/**
* Creates a new list of types that represent parameters.
*
* @param typeDescriptions The types to represent.
*/
public TypeList(List<? extends GenericTypeDescription> typeDescriptions) {
this.typeDescriptions = typeDescriptions;
}
@Override
public Token get(int index) {
return new Token(typeDescriptions.get(index));
}
@Override
public int size() {
return typeDescriptions.size();
}
}
}
}