@@ -24,75 +24,75 @@ trait SignatureBuilder extends ScalaSignatureUtils {
2424 def memberName (name : String , dri : DRI ) = text(name)
2525
2626 def list [E ](
27- elements : Seq [E ],
28- prefix : String = " " ,
29- suffix : String = " " ,
30- separator : String = " , " ,
31- forcePrefixAndSuffix : Boolean = false
32- )(
33- elemOp : (SignatureBuilder , E ) => SignatureBuilder
34- ): SignatureBuilder = elements match {
35- case Nil => if forcePrefixAndSuffix then this .text(prefix + suffix) else this
36- case head :: tail =>
37- tail.foldLeft(elemOp(text(prefix), head))((b, e) => elemOp(b.text(separator), e)).text(suffix)
38- }
27+ elements : Seq [E ],
28+ prefix : String = " " ,
29+ suffix : String = " " ,
30+ separator : String = " , " ,
31+ forcePrefixAndSuffix : Boolean = false
32+ )(
33+ elemOp : (SignatureBuilder , E ) => SignatureBuilder
34+ ): SignatureBuilder = elements match {
35+ case Nil => if forcePrefixAndSuffix then this .text(prefix + suffix) else this
36+ case head :: tail =>
37+ tail.foldLeft(elemOp(text(prefix), head))((b, e) => elemOp(b.text(separator), e)).text(suffix)
38+ }
3939
4040 def annotationsBlock (d : Member ): SignatureBuilder =
41- d.annotations.foldLeft(this ){ (bdr, annotation) => bdr.buildAnnotation(annotation)}
42-
43- def annotationsInline (d : Parameter ): SignatureBuilder =
44- d.annotations.foldLeft(this ){ (bdr, annotation) => bdr.buildAnnotation(annotation) }
41+ d.annotations.foldLeft(this ){ (bdr, annotation) => bdr.buildAnnotation(annotation)}
4542
46- def annotationsInline (t : TypeParameter ): SignatureBuilder =
47- t .annotations.foldLeft(this ){ (bdr, annotation) => bdr.buildAnnotation(annotation) }
43+ def annotationsInline (d : Parameter ): SignatureBuilder =
44+ d .annotations.foldLeft(this ){ (bdr, annotation) => bdr.buildAnnotation(annotation) }
4845
49- private def buildAnnotation ( a : Annotation ): SignatureBuilder =
50- text( " @ " ).driLink(a.dri.location.split( '.' ).last, a.dri).buildAnnotationParams(a).text( " " )
46+ def annotationsInline ( t : TypeParameter ): SignatureBuilder =
47+ t.annotations.foldLeft( this ){ (bdr, annotation) => bdr.buildAnnotation(annotation) }
5148
52- private def buildAnnotationParams (a : Annotation ): SignatureBuilder =
53- if ! a.params.isEmpty then
54- val params = a.params.filterNot {
55- case Annotation .LinkParameter (_, _, text) => text == " _"
56- case _ => false
57- }
58- list(params, " (" , " )" , " , " ){ (bdr, param) => bdr.buildAnnotationParameter(param)}
59- else this
49+ private def buildAnnotation (a : Annotation ): SignatureBuilder =
50+ text(" @" ).driLink(a.dri.location.split('.' ).last, a.dri).buildAnnotationParams(a).text(" " )
6051
61- private def addParameterName (txt : Option [String ]): SignatureBuilder = txt match {
62- case Some (name) => this .text(s " $name = " )
63- case _ => this
52+ private def buildAnnotationParams (a : Annotation ): SignatureBuilder =
53+ if ! a.params.isEmpty then
54+ val params = a.params.filterNot {
55+ case Annotation .LinkParameter (_, _, text) => text == " _"
56+ case _ => false
6457 }
58+ list(params, " (" , " )" , " , " ){ (bdr, param) => bdr.buildAnnotationParameter(param)}
59+ else this
6560
66- private def buildAnnotationParameter (a : Annotation .AnnotationParameter ): SignatureBuilder = a match {
67- case Annotation .PrimitiveParameter (name, value) =>
68- addParameterName(name).text(value)
69- case Annotation .LinkParameter (name, dri, text) =>
70- addParameterName(name).driLink(text, dri)
71- case Annotation .UnresolvedParameter (name, value) =>
72- addParameterName(name).text(value)
73- }
61+ private def addParameterName (txt : Option [String ]): SignatureBuilder = txt match {
62+ case Some (name) => this .text(s " $name = " )
63+ case _ => this
64+ }
7465
75- def modifiersAndVisibility (t : Member , kind : String ) =
76- val (prefixMods, suffixMods) = t.modifiers.partition(_.prefix)
77- val all = prefixMods.map(_.name) ++ Seq (t.visibility.asSignature) ++ suffixMods.map(_.name)
66+ private def buildAnnotationParameter (a : Annotation .AnnotationParameter ): SignatureBuilder = a match {
67+ case Annotation .PrimitiveParameter (name, value) =>
68+ addParameterName(name).text(value)
69+ case Annotation .LinkParameter (name, dri, text) =>
70+ addParameterName(name).driLink(text, dri)
71+ case Annotation .UnresolvedParameter (name, value) =>
72+ addParameterName(name).text(value)
73+ }
7874
79- text(all.toSignatureString()).text(kind + " " )
75+ def modifiersAndVisibility (t : Member , kind : String ) =
76+ val (prefixMods, suffixMods) = t.modifiers.partition(_.prefix)
77+ val all = prefixMods.map(_.name) ++ Seq (t.visibility.asSignature) ++ suffixMods.map(_.name)
8078
81- def generics (on : Seq [TypeParameter ]) = list(on.toList, " [" , " ]" ){ (bdr, e) =>
82- bdr.annotationsInline(e).text(e.variance).memberName(e.name, e.dri).signature(e.signature)
83- }
79+ text(all.toSignatureString()).text(kind + " " )
8480
85- def functionParameters (params : Seq [ParametersList ]) =
86- if params.isEmpty then this .text(" " )
87- else if params.size == 1 && params(0 ).parameters == Nil then this .text(" ()" )
88- else this .list(params, separator = " " ){ (bld, pList) =>
89- bld.list(pList.parameters, s " ( ${pList.modifiers}" , " )" , forcePrefixAndSuffix = true ){ (bld, p) =>
90- val annotationsAndModifiers = bld.annotationsInline(p)
91- .text(p.modifiers)
92- val name = p.name.fold(annotationsAndModifiers)(annotationsAndModifiers.memberName(_, p.dri).text(" : " ))
93- name.signature(p.signature)
94- }
81+ def generics (on : Seq [TypeParameter ]) = list(on.toList, " [" , " ]" ){ (bdr, e) =>
82+ bdr.annotationsInline(e).text(e.variance).memberName(e.name, e.dri).signature(e.signature)
83+ }
84+
85+ def functionParameters (params : Seq [ParametersList ]) =
86+ if params.isEmpty then this .text(" " )
87+ else if params.size == 1 && params(0 ).parameters == Nil then this .text(" ()" )
88+ else this .list(params, separator = " " ) { (bld, pList) =>
89+ bld.list(pList.parameters, s " ( ${pList.modifiers}" , " )" , forcePrefixAndSuffix = true ) { (bld, p) =>
90+ val annotationsAndModifiers = bld.annotationsInline(p)
91+ .text(p.modifiers)
92+ val name = p.name.fold(annotationsAndModifiers)(annotationsAndModifiers.memberName(_, p.dri).text(" : " ))
93+ name.signature(p.signature)
9594 }
95+ }
9696}
9797
9898trait ScalaSignatureUtils :
0 commit comments