@@ -178,14 +178,14 @@ object Macro:
178
178
179
179
private val tpe : TypeRepr = TypeRepr .of[T ]
180
180
181
- def anns : Expr [List [Any ]] =
181
+ def anns : Expr [List [scala.annotation. Annotation ]] =
182
182
Expr .ofList {
183
183
tpe.typeSymbol.annotations
184
184
.filter(filterAnnotation)
185
- .map(_.asExpr.asInstanceOf [Expr [Any ]])
185
+ .map(_.asExpr.asInstanceOf [Expr [scala.annotation. Annotation ]])
186
186
}
187
187
188
- def inheritedAnns : Expr [List [Any ]] =
188
+ def inheritedAnns : Expr [List [scala.annotation. Annotation ]] =
189
189
Expr .ofList {
190
190
tpe.baseClasses
191
191
.filterNot(isObjectOrScala)
@@ -194,10 +194,10 @@ object Macro:
194
194
} // skip self
195
195
.flatten
196
196
.filter(filterAnnotation)
197
- .map(_.asExpr.asInstanceOf [Expr [Any ]])
197
+ .map(_.asExpr.asInstanceOf [Expr [scala.annotation. Annotation ]])
198
198
}
199
199
200
- def typeAnns : Expr [List [Any ]] = {
200
+ def typeAnns : Expr [List [scala.annotation. Annotation ]] = {
201
201
202
202
def getAnnotations (t : TypeRepr ): List [Term ] = t match
203
203
case AnnotatedType (inner, ann) => ann :: getAnnotations(inner)
@@ -212,28 +212,28 @@ object Macro:
212
212
.collect { case t : TypeTree => t.tpe }
213
213
.flatMap(getAnnotations)
214
214
.filter(filterAnnotation)
215
- .map(_.asExpr.asInstanceOf [Expr [Any ]])
215
+ .map(_.asExpr.asInstanceOf [Expr [scala.annotation. Annotation ]])
216
216
case _ =>
217
217
// Best effort in case whe -Yretain-trees is not used
218
218
// Does not support class parent annotations (in the extends clouse)
219
219
tpe.baseClasses
220
220
.map(tpe.baseType(_))
221
221
.flatMap(getAnnotations(_))
222
222
.filter(filterAnnotation)
223
- .map(_.asExpr )
223
+ .map(_.asExprOf[scala.annotation. Annotation ] )
224
224
}
225
225
}
226
226
}
227
227
228
- def paramAnns : Expr [List [(String , List [Any ])]] =
228
+ def paramAnns : Expr [List [(String , List [scala.annotation. Annotation ])]] =
229
229
Expr .ofList {
230
230
groupByParamName {
231
231
(fromConstructor(tpe.typeSymbol) ++ fromDeclarations(tpe.typeSymbol))
232
232
.filter { case (_, anns) => anns.nonEmpty }
233
233
}
234
234
}
235
235
236
- def inheritedParamAnns : Expr [List [(String , List [Any ])]] =
236
+ def inheritedParamAnns : Expr [List [(String , List [scala.annotation. Annotation ])]] =
237
237
Expr .ofList {
238
238
groupByParamName {
239
239
tpe.baseClasses
@@ -248,25 +248,25 @@ object Macro:
248
248
}
249
249
}
250
250
251
- private def fromConstructor (from : Symbol ): List [(String , List [Expr [Any ]])] =
251
+ private def fromConstructor (from : Symbol ): List [(String , List [Expr [scala.annotation. Annotation ]])] =
252
252
from.primaryConstructor.paramSymss.flatten.map { field =>
253
253
field.name -> field.annotations
254
254
.filter(filterAnnotation)
255
- .map(_.asExpr.asInstanceOf [Expr [Any ]])
255
+ .map(_.asExpr.asInstanceOf [Expr [scala.annotation. Annotation ]])
256
256
}
257
257
258
258
private def fromDeclarations (
259
259
from : Symbol ,
260
260
inherited : Boolean = false
261
- ): List [(String , List [Expr [Any ]])] =
261
+ ): List [(String , List [Expr [scala.annotation. Annotation ]])] =
262
262
from.fieldMembers.collect { case field : Symbol =>
263
263
val annotations = if (! inherited) field.annotations else field.allOverriddenSymbols.flatMap(_.annotations).toList
264
264
field.name -> annotations
265
265
.filter(filterAnnotation)
266
- .map(_.asExpr.asInstanceOf [Expr [Any ]])
266
+ .map(_.asExpr.asInstanceOf [Expr [scala.annotation. Annotation ]])
267
267
}
268
268
269
- private def groupByParamName (anns : List [(String , List [Expr [Any ]])]) =
269
+ private def groupByParamName (anns : List [(String , List [Expr [scala.annotation. Annotation ]])]) =
270
270
anns
271
271
.groupBy { case (name, _) => name }
272
272
.toList
@@ -277,7 +277,8 @@ object Macro:
277
277
bc.name.contains(" java.lang.Object" ) || bc.fullName.startsWith(" scala." )
278
278
279
279
private def filterAnnotation (a : Term ): Boolean =
280
- a.tpe.typeSymbol.maybeOwner.isNoSymbol ||
281
- (a.tpe.typeSymbol.owner.fullName != " scala.annotation.internal" &&
282
- a.tpe.typeSymbol.owner.fullName != " jdk.internal" )
280
+ scala.util.Try (a.tpe <:< TypeRepr .of[scala.annotation.Annotation ]).toOption.contains(true ) &&
281
+ (a.tpe.typeSymbol.maybeOwner.isNoSymbol ||
282
+ (a.tpe.typeSymbol.owner.fullName != " scala.annotation.internal" &&
283
+ a.tpe.typeSymbol.owner.fullName != " jdk.internal" ))
283
284
}
0 commit comments