@@ -103,87 +103,70 @@ object Example extends AutoPlugin {
103103 DocToken (tagKind : DocToken .TagKind , Some (name), Some (description)),
104104 (codeAccumulator, trailingAccumulator, tagAccumulator)
105105 ) =>
106- val tag = if (codeAccumulator.nonEmpty) {
107- q """
106+ if (codeAccumulator.nonEmpty) {
107+ val tag = q """
108108 ${Lit .String (s " ${tagKind.label} $name" )}.in(try {
109109 this.markup( $description)
110110 .. $codeAccumulator
111111 } finally {
112112 .. $trailingAccumulator
113113 })
114114 """
115+ (Nil , Nil , tag :: tagAccumulator)
115116 } else {
116- q """
117- ${Lit .String (s " ${tagKind.label} $name" )} - {
118- this.markup( $description)
119- .. $trailingAccumulator
120- }
121- """
117+ (Nil , Nil , tagAccumulator)
122118 }
123- (Nil , Nil , tag :: tagAccumulator)
124119 case (
125120 DocToken (tagKind : DocToken .TagKind , None , Some (body)),
126121 (codeAccumulator, trailingAccumulator, tagAccumulator)
127122 ) =>
128- val tag = if (codeAccumulator.nonEmpty) {
129- q """
123+ if (codeAccumulator.nonEmpty) {
124+ val tag = q """
130125 ${Lit .String (s " ${tagKind.label} $body" )}.in(try {
131126 .. $codeAccumulator
132127 } finally {
133128 .. $trailingAccumulator
134129 })
135130 """
131+ (Nil , Nil , tag :: tagAccumulator)
136132 } else {
137- q """
138- ${Lit .String (s " ${tagKind.label} $body" )} - {
139- .. $trailingAccumulator
140- }
141- """
133+ (Nil , Nil , tagAccumulator)
142134 }
143- (Nil , Nil , tag :: tagAccumulator)
144135 case (
145136 token @ DocToken (_ : DocToken .TagKind , _, None ),
146137 (codeAccumulator, trailingAccumulator, tagAccumulator)
147138 ) =>
148- val tag = if (codeAccumulator.nonEmpty) {
149- q """
139+ if (codeAccumulator.nonEmpty) {
140+ val tag = q """
150141 ${Lit .String (token.toString)}.in(try {
151142 .. $codeAccumulator
152143 } finally {
153144 .. $trailingAccumulator
154145 })
155146 """
147+ (Nil , Nil , tag :: tagAccumulator)
156148 } else {
157- q """
158- ${Lit .String (token.toString)} - {
159- .. $trailingAccumulator
160- }
161- """
149+ (Nil , Nil , tagAccumulator)
162150 }
163- (Nil , Nil , tag :: tagAccumulator)
164151 case (
165152 DocToken (DocToken .Description , None , Some (text)),
166153 (codeAccumulator, trailingAccumulator, tagAccumulator)
167154 ) if text.startsWith(" @" ) =>
168155 logger.warn(
169156 s " Invalid Scaladoc tag detected at ${comment.pos} (missing parameters for the tag?): \n\t $text"
170157 )
171- val tag = if (codeAccumulator.nonEmpty) {
172- q """
158+ if (codeAccumulator.nonEmpty) {
159+ val tag = q """
173160 ${Lit .String (text)}.in(try {
174161 .. $codeAccumulator
175162 } finally {
176163 .. $trailingAccumulator
177164 })
178165 """
166+ (Nil , Nil , tag :: tagAccumulator)
179167 } else {
180- q """
181- ${Lit .String (text)} - {
182- .. $trailingAccumulator
183- }
184- """
168+ (Nil , Nil , tagAccumulator)
185169 }
186- (Nil , Nil , tag :: tagAccumulator)
187170 case (DocToken (DocToken .Paragraph , None , None ), accumulators) =>
188171 accumulators
189172 case (otherToken, (codeAccumulator, trailingAccumulator, tagAccumulator)) =>
@@ -221,20 +204,29 @@ object Example extends AutoPlugin {
221204 (codeAccumulator, markup :: trailingAccumulator, tagAccumulator)
222205 }
223206 }
224- code ::: trailing ::: tags
207+ if (tags.nonEmpty || code.nonEmpty) {
208+ code ::: trailing ::: tags
209+ } else {
210+ Nil
211+ }
225212 }
226213 }
227214 }
228215
229216 def testTree (tree : Tree ): Seq [Stat ] = {
230217 def templateTestTree (name : Name , template : Template ) = {
231- import template ._
232218 val title = name.syntax
233- q """ $title - {
234- .. ${scaladocTestTree(comments.leading(tree))}
235- .. ${template.early.flatMap(testTree)}
236- .. ${template.stats.flatMap(testTree)}
237- } """ :: Nil
219+ val trees =
220+ scaladocTestTree(comments.leading(tree)) :::
221+ template.early.flatMap(testTree) :::
222+ template.stats.flatMap(testTree)
223+ if (trees.isEmpty) {
224+ Nil
225+ } else {
226+ q """ $title - {
227+ .. $trees
228+ } """ :: Nil
229+ }
238230 }
239231 def leafTestTree (name : Name ) = {
240232 val title = name.syntax
@@ -243,17 +235,21 @@ object Example extends AutoPlugin {
243235 Nil
244236 } else {
245237 q """ $title - {
246- .. $trees
247- } """ :: Nil
238+ .. $trees
239+ } """ :: Nil
248240 }
249241 }
250242 tree match {
251243 case Pkg (termRef, children) =>
252244 val packageName = termRef.toString
253- q """ $packageName - {
254- .. ${scaladocTestTree(comments.leading(tree))}
255- .. ${children.flatMap(testTree)}
245+ val trees = scaladocTestTree(comments.leading(tree)) ::: children.flatMap(testTree)
246+ if (trees.isEmpty) {
247+ Nil
248+ } else {
249+ q """ $packageName - {
250+ .. $trees
256251 } """ :: Nil
252+ }
257253 case Pkg .Object (_, name, template : Template ) =>
258254 templateTestTree(name, template)
259255 case Defn .Object (_, name, template : Template ) =>
0 commit comments