@@ -16,7 +16,8 @@ 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+ ( if this instanceof AnnotationType then result = "@interface" else result = "interface" )
2021 or
2122 this instanceof Class and
2223 ( if this instanceof EnumType then result = "enum" else result = "class" )
@@ -27,19 +28,29 @@ abstract private class GeneratedType extends ClassOrInterface {
2728 }
2829
2930 private string stubStaticModifier ( ) {
30- if this .isStatic ( ) then result = "static " else result = ""
31+ if this .( NestedType ) . isStatic ( ) then result = "static " else result = ""
3132 }
3233
3334 private string stubAccessibilityModifier ( ) {
3435 if this .isPublic ( ) then result = "public " else result = ""
3536 }
3637
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+
3747 /** Gets the entire Java stub code for this type. */
3848 final string getStub ( ) {
3949 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+ + "}"
4354 }
4455
4556 private RefType getAnInterestingBaseType ( ) {
@@ -60,7 +71,9 @@ abstract private class GeneratedType extends ClassOrInterface {
6071 else cls = ""
6172 ) and
6273 (
63- if exists ( this .getAnInterestingBaseType ( ) .( Interface ) )
74+ if
75+ exists ( this .getAnInterestingBaseType ( ) .( Interface ) ) and
76+ not this instanceof AnnotationType
6477 then (
6578 ( if this instanceof Class then int_kw = " implements " else int_kw = " extends " ) and
6679 interface = concat ( stubTypeName ( this .getAnInterestingBaseType ( ) .( Interface ) ) , ", " )
@@ -96,15 +109,14 @@ abstract private class GeneratedType extends ClassOrInterface {
96109 }
97110
98111 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 ( )
108120 }
109121}
110122
@@ -391,6 +403,47 @@ private string stubMember(Member m) {
391403 )
392404}
393405
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+
394447bindingset [ s]
395448private string indent ( string s ) { result = " " + s .replaceAll ( "\n" , "\n " ) + "\n" }
396449
0 commit comments