@@ -16,7 +16,8 @@ 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
+ ( if this instanceof AnnotationType then result = "@interface" else result = "interface" )
20
21
or
21
22
this instanceof Class and
22
23
( if this instanceof EnumType then result = "enum" else result = "class" )
@@ -27,19 +28,29 @@ abstract private class GeneratedType extends ClassOrInterface {
27
28
}
28
29
29
30
private string stubStaticModifier ( ) {
30
- if this .isStatic ( ) then result = "static " else result = ""
31
+ if this .( NestedType ) . isStatic ( ) then result = "static " else result = ""
31
32
}
32
33
33
34
private string stubAccessibilityModifier ( ) {
34
35
if this .isPublic ( ) then result = "public " else result = ""
35
36
}
36
37
38
+ private string stubAnnotations ( ) {
39
+ result =
40
+ concat ( Annotation an |
41
+ this .( AnnotationType ) .getAnAnnotation ( ) = an
42
+ |
43
+ stubAnnotation ( an ) , "\n" order by an .getType ( ) .getQualifiedName ( )
44
+ )
45
+ }
46
+
37
47
/** Gets the entire Java stub code for this type. */
38
48
final string getStub ( ) {
39
49
result =
40
- this .stubAbstractModifier ( ) + this .stubStaticModifier ( ) + this .stubAccessibilityModifier ( ) +
41
- this .stubKeyword ( ) + " " + this .getName ( ) + stubGenericArguments ( this , true ) +
42
- this .stubBaseTypesString ( ) + "\n{\n" + this .stubMembers ( ) + "}"
50
+ this .stubAnnotations ( ) + this .stubAbstractModifier ( ) + this .stubStaticModifier ( ) +
51
+ this .stubAccessibilityModifier ( ) + this .stubKeyword ( ) + " " + this .getName ( ) +
52
+ stubGenericArguments ( this , true ) + this .stubBaseTypesString ( ) + "\n{\n" + this .stubMembers ( )
53
+ + "}"
43
54
}
44
55
45
56
private RefType getAnInterestingBaseType ( ) {
@@ -60,7 +71,9 @@ abstract private class GeneratedType extends ClassOrInterface {
60
71
else cls = ""
61
72
) and
62
73
(
63
- if exists ( this .getAnInterestingBaseType ( ) .( Interface ) )
74
+ if
75
+ exists ( this .getAnInterestingBaseType ( ) .( Interface ) ) and
76
+ not this instanceof AnnotationType
64
77
then (
65
78
( if this instanceof Class then int_kw = " implements " else int_kw = " extends " ) and
66
79
interface = concat ( stubTypeName ( this .getAnInterestingBaseType ( ) .( Interface ) ) , ", " )
@@ -96,15 +109,14 @@ abstract private class GeneratedType extends ClassOrInterface {
96
109
}
97
110
98
111
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 )
112
+ result = this .getAnInterestingBaseType ( ) or
113
+ result = this .getAGeneratedMember ( ) .( Callable ) .getReturnType ( ) or
114
+ result = this .getAGeneratedMember ( ) .( Callable ) .getAParameter ( ) .getType ( ) or
115
+ result = this .getAGeneratedMember ( ) .( Field ) .getType ( ) or
116
+ result = this .getAGeneratedMember ( ) .( NestedType ) or
117
+ result = this .( AnnotationType ) .getAnAnnotation ( ) .getType ( ) or
118
+ result = this .( AnnotationType ) .getAnAnnotation ( ) .getValue ( _) .getType ( ) or
119
+ result = this .( AnnotationType ) .getAnAnnotation ( ) .getAnArrayValue ( _) .getType ( )
108
120
}
109
121
}
110
122
@@ -391,6 +403,47 @@ private string stubMember(Member m) {
391
403
)
392
404
}
393
405
406
+ language [ monotonicAggregates]
407
+ private string stubAnnotation ( Annotation a ) {
408
+ if exists ( a .getValue ( _) )
409
+ then
410
+ result =
411
+ "@" + a .getType ( ) .getName ( ) + "(" +
412
+ concat ( string name , Expr value |
413
+ value = a .getValue ( name )
414
+ |
415
+ name + "=" + stubAnnotationValue ( value ) , ","
416
+ ) + ")"
417
+ else result = "@" + a .getType ( ) .getName ( )
418
+ }
419
+
420
+ language [ monotonicAggregates]
421
+ private string stubAnnotationValue ( Expr value ) {
422
+ result = value .( FieldAccess ) .getField ( ) .getQualifiedName ( )
423
+ or
424
+ (
425
+ value instanceof Literal or
426
+ value instanceof CompileTimeConstantExpr
427
+ ) and
428
+ if value instanceof StringLiteral
429
+ then result = "\"\""
430
+ else result = stubDefaultValue ( value .getType ( ) )
431
+ or
432
+ result = stubAnnotation ( value )
433
+ or
434
+ result = value .( TypeLiteral ) .getReferencedType ( ) .getName ( ) + ".class"
435
+ or
436
+ value instanceof ArrayInit and
437
+ result =
438
+ "{" +
439
+ concat ( int i , Expr arrayElement |
440
+ i >= 0 and
441
+ arrayElement = value .( ArrayInit ) .getInit ( i )
442
+ |
443
+ stubAnnotationValue ( arrayElement ) , "," order by i
444
+ ) + "}"
445
+ }
446
+
394
447
bindingset [ s]
395
448
private string indent ( string s ) { result = " " + s .replaceAll ( "\n" , "\n " ) + "\n" }
396
449
0 commit comments