@@ -16,7 +16,12 @@ abstract private class GeneratedType extends ClassOrInterface {
16
16
}
17
17
18
18
private string stubKeyword ( ) {
19
- this instanceof Interface and result = "interface"
19
+ this instanceof Interface and
20
+ (
21
+ this instanceof AnnotationType and result = "@interface"
22
+ or
23
+ result = "interface"
24
+ )
20
25
or
21
26
this instanceof Class and
22
27
( if this instanceof EnumType then result = "enum" else result = "class" )
@@ -27,19 +32,24 @@ abstract private class GeneratedType extends ClassOrInterface {
27
32
}
28
33
29
34
private string stubStaticModifier ( ) {
30
- if this .isStatic ( ) then result = "static " else result = ""
35
+ if this .( NestedType ) . isStatic ( ) then result = "static " else result = ""
31
36
}
32
37
33
38
private string stubAccessibilityModifier ( ) {
34
39
if this .isPublic ( ) then result = "public " else result = ""
35
40
}
36
41
42
+ private string stubAnnotations ( ) {
43
+ result = concat ( "@" + stubAnnotation ( this .( AnnotationType ) .getAnAnnotation ( ) ) + "\n" )
44
+ }
45
+
37
46
/** Gets the entire Java stub code for this type. */
38
47
final string getStub ( ) {
39
48
result =
40
- this .stubAbstractModifier ( ) + this .stubStaticModifier ( ) + this .stubAccessibilityModifier ( ) +
41
- this .stubKeyword ( ) + " " + this .getName ( ) + stubGenericArguments ( this , true ) +
42
- this .stubBaseTypesString ( ) + "\n{\n" + this .stubMembers ( ) + "}"
49
+ this .stubAnnotations ( ) + this .stubAbstractModifier ( ) + this .stubStaticModifier ( ) +
50
+ this .stubAccessibilityModifier ( ) + this .stubKeyword ( ) + " " + this .getName ( ) +
51
+ stubGenericArguments ( this , true ) + this .stubBaseTypesString ( ) + "\n{\n" + this .stubMembers ( )
52
+ + "}"
43
53
}
44
54
45
55
private RefType getAnInterestingBaseType ( ) {
@@ -60,7 +70,9 @@ abstract private class GeneratedType extends ClassOrInterface {
60
70
else cls = ""
61
71
) and
62
72
(
63
- if exists ( this .getAnInterestingBaseType ( ) .( Interface ) )
73
+ if
74
+ exists ( this .getAnInterestingBaseType ( ) .( Interface ) ) and
75
+ not this instanceof AnnotationType
64
76
then (
65
77
( if this instanceof Class then int_kw = " implements " else int_kw = " extends " ) and
66
78
interface = concat ( stubTypeName ( this .getAnInterestingBaseType ( ) .( Interface ) ) , ", " )
@@ -96,15 +108,14 @@ abstract private class GeneratedType extends ClassOrInterface {
96
108
}
97
109
98
110
final Type getAGeneratedType ( ) {
99
- result = this .getAnInterestingBaseType ( )
100
- or
101
- result = this .getAGeneratedMember ( ) .( Callable ) .getReturnType ( )
102
- or
103
- result = this .getAGeneratedMember ( ) .( Callable ) .getAParameter ( ) .getType ( )
104
- or
105
- result = this .getAGeneratedMember ( ) .( Field ) .getType ( )
106
- or
107
- result = this .getAGeneratedMember ( ) .( NestedType )
111
+ result = this .getAnInterestingBaseType ( ) or
112
+ result = this .getAGeneratedMember ( ) .( Callable ) .getReturnType ( ) or
113
+ result = this .getAGeneratedMember ( ) .( Callable ) .getAParameter ( ) .getType ( ) or
114
+ result = this .getAGeneratedMember ( ) .( Field ) .getType ( ) or
115
+ result = this .getAGeneratedMember ( ) .( NestedType ) or
116
+ result = this .( AnnotationType ) .getAnAnnotation ( ) .getType ( ) or
117
+ result = this .( AnnotationType ) .getAnAnnotation ( ) .getAValue ( ) .getType ( ) or
118
+ result = this .( AnnotationType ) .getAnAnnotation ( ) .getAValue ( ) .( ArrayInit ) .getAnInit ( ) .getType ( )
108
119
}
109
120
}
110
121
@@ -391,6 +402,24 @@ private string stubMember(Member m) {
391
402
)
392
403
}
393
404
405
+ private string stubAnnotation ( Annotation a ) {
406
+ if exists ( a .getAValue ( ) )
407
+ then result = a .toString ( ) + "(" + concat ( stubAnnotationValue ( a .getAValue ( ) ) , "," ) + ")"
408
+ else result = a .toString ( )
409
+ }
410
+
411
+ private string stubAnnotiationSimpleValue ( Expr value ) {
412
+ result = value .( FieldAccess ) .getField ( ) .getQualifiedName ( ) or
413
+ result = value .( Literal ) .toString ( )
414
+ }
415
+
416
+ private string stubAnnotationValue ( Expr value ) {
417
+ result = stubAnnotiationSimpleValue ( value )
418
+ or
419
+ value instanceof ArrayInit and
420
+ result = "{" + concat ( stubAnnotiationSimpleValue ( value .( ArrayInit ) .getAnInit ( ) ) , "," ) + "}"
421
+ }
422
+
394
423
bindingset [ s]
395
424
private string indent ( string s ) { result = " " + s .replaceAll ( "\n" , "\n " ) + "\n" }
396
425
0 commit comments