-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnnotationUtilsTestMacro.test.scala
More file actions
42 lines (35 loc) · 1.1 KB
/
AnnotationUtilsTestMacro.test.scala
File metadata and controls
42 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.encalmo.utils
import AnnotationUtils.*
import scala.quoted.*
object AnnotationUtilsTestMacro {
inline def testComputeFieldAnnotations[A](entity: A, inline fieldName: String): List[String] = {
${ testComputeFieldAnnotationsImpl[A]('{ entity }, '{ fieldName }) }
}
def testComputeFieldAnnotationsImpl[A: Type](entityExpr: Expr[A], fieldNameExpr: Expr[String])(using
Quotes
): Expr[List[String]] = {
given StatementsCache = new StatementsCache
testComputeFieldAnnotations2Impl[A](entityExpr, fieldNameExpr.valueOrAbort)
}
def testComputeFieldAnnotations2Impl[A: Type](using
cache: StatementsCache
)(
entityExpr: Expr[A],
fieldName: String
): Expr[List[String]] = {
given cache.quotes.type = cache.quotes
import cache.quotes.reflect.*
Expr.ofList(
TypeRepr
.of[A]
.dealias
.typeSymbol
.caseFields
.find(_.name == fieldName)
.map(fields => computeFieldAnnotations(TypeRepr.of[A], fieldName).map(_.toString))
.getOrElse(Set.empty[String])
.map(Expr(_))
.toList
)
}
}