@@ -16,7 +16,12 @@ abstract private class GeneratedType extends ClassOrInterface {
1616 }
1717
1818 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+ )
2025 or
2126 this instanceof Class and
2227 ( if this instanceof EnumType then result = "enum" else result = "class" )
@@ -27,19 +32,24 @@ abstract private class GeneratedType extends ClassOrInterface {
2732 }
2833
2934 private string stubStaticModifier ( ) {
30- if this .isStatic ( ) then result = "static " else result = ""
35+ if this .( NestedType ) . isStatic ( ) then result = "static " else result = ""
3136 }
3237
3338 private string stubAccessibilityModifier ( ) {
3439 if this .isPublic ( ) then result = "public " else result = ""
3540 }
3641
42+ private string stubAnnotations ( ) {
43+ result = concat ( "@" + stubAnnotation ( this .( AnnotationType ) .getAnAnnotation ( ) ) + "\n" )
44+ }
45+
3746 /** Gets the entire Java stub code for this type. */
3847 final string getStub ( ) {
3948 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+ + "}"
4353 }
4454
4555 private RefType getAnInterestingBaseType ( ) {
@@ -60,7 +70,9 @@ abstract private class GeneratedType extends ClassOrInterface {
6070 else cls = ""
6171 ) and
6272 (
63- if exists ( this .getAnInterestingBaseType ( ) .( Interface ) )
73+ if
74+ exists ( this .getAnInterestingBaseType ( ) .( Interface ) ) and
75+ not this instanceof AnnotationType
6476 then (
6577 ( if this instanceof Class then int_kw = " implements " else int_kw = " extends " ) and
6678 interface = concat ( stubTypeName ( this .getAnInterestingBaseType ( ) .( Interface ) ) , ", " )
@@ -96,15 +108,14 @@ abstract private class GeneratedType extends ClassOrInterface {
96108 }
97109
98110 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 ( )
108119 }
109120}
110121
@@ -391,6 +402,24 @@ private string stubMember(Member m) {
391402 )
392403}
393404
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+
394423bindingset [ s]
395424private string indent ( string s ) { result = " " + s .replaceAll ( "\n" , "\n " ) + "\n" }
396425
0 commit comments