Skip to content

Commit 44dd297

Browse files
committed
Update reflect Symbol declarations API
1 parent 7a0b8ef commit 44dd297

File tree

12 files changed

+61
-45
lines changed

12 files changed

+61
-45
lines changed

community-build/src/scala/dotty/communitybuild/FieldsImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ object FieldsImpl:
99
def fieldsImpl[V: Type, T: Type](from: Expr[V])(using Quotes): Expr[Seq[T]] =
1010
import quotes.reflect._
1111
val retType = TypeTree.of[T].tpe
12-
def isProjectField(s: Symbol) =
12+
def isProjectField(s: Symbol) =
1313
s.isValDef && s.tree.asInstanceOf[ValDef].tpt.tpe <:< retType
1414
val projectsTree = Term.of(from)
15-
val symbols = TypeTree.of[V].symbol.members.filter(isProjectField)
15+
val symbols = TypeTree.of[V].symbol.memberMethods.filter(isProjectField)
1616
val selects = symbols.map(Select(projectsTree, _).asExprOf[T])
1717
'{ println(${Expr(retType.show)}); ${Varargs(selects)} }

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,35 +2338,45 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
23382338
val sym = self.unforcedDecls.find(sym => sym.name == name.toTermName)
23392339
if (isField(sym)) sym else dotc.core.Symbols.NoSymbol
23402340

2341-
def classMethod(name: String): List[Symbol] =
2341+
def declaredMethod(name: String): List[Symbol] =
23422342
self.typeRef.decls.iterator.collect {
23432343
case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm
23442344
}.toList
23452345

2346-
def classMethods: List[Symbol] =
2346+
def declaredMethods: List[Symbol] =
23472347
self.typeRef.decls.iterator.collect {
23482348
case sym if isMethod(sym) => sym.asTerm
23492349
}.toList
23502350

2351-
def members: List[Symbol] =
2352-
self.typeRef.info.decls.toList
2353-
2354-
def typeMembers: List[Symbol] =
2355-
self.unforcedDecls.filter(_.isType)
2356-
2357-
def typeMember(name: String): Symbol =
2358-
self.unforcedDecls.find(sym => sym.name == name.toTypeName)
2359-
2360-
def method(name: String): List[Symbol] =
2351+
def memberMethod(name: String): List[Symbol] =
23612352
appliedTypeRef(self).allMembers.iterator.map(_.symbol).collect {
23622353
case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm
23632354
}.toList
23642355

2365-
def methods: List[Symbol] =
2356+
def memberMethods: List[Symbol] =
23662357
appliedTypeRef(self).allMembers.iterator.map(_.symbol).collect {
23672358
case sym if isMethod(sym) => sym.asTerm
23682359
}.toList
23692360

2361+
def declaredType(name: String): List[Symbol] =
2362+
self.typeRef.decls.iterator.collect {
2363+
case sym if sym.isType && sym.name.toString == name => sym.asType
2364+
}.toList
2365+
2366+
def declaredTypes: List[Symbol] =
2367+
self.typeRef.decls.iterator.collect {
2368+
case sym if sym.isType => sym.asType
2369+
}.toList
2370+
2371+
def memberType(name: String): Symbol =
2372+
self.unforcedDecls.find(sym => sym.name == name.toTypeName)
2373+
2374+
def memberTypes: List[Symbol] =
2375+
self.unforcedDecls.filter(_.isType)
2376+
2377+
def declarations: List[Symbol] =
2378+
self.typeRef.info.decls.toList
2379+
23702380
def paramSymss: List[List[Symbol]] = self.denot.paramSymss
23712381
def primaryConstructor: Symbol = self.denot.primaryConstructor
23722382
def allOverriddenSymbols: Iterator[Symbol] = self.denot.allOverriddenSymbols

library/src/scala/quoted/Quotes.scala

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,25 +3149,31 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
31493149
def field(name: String): Symbol
31503150

31513151
/** Get non-private named methods defined directly inside the class */
3152-
def classMethod(name: String): List[Symbol]
3152+
def declaredMethod(name: String): List[Symbol]
31533153

31543154
/** Get all non-private methods defined directly inside the class, exluding constructors */
3155-
def classMethods: List[Symbol]
3155+
def declaredMethods: List[Symbol]
31563156

3157-
/** Type member directly declared in the class */
3158-
def typeMembers: List[Symbol]
3157+
/** Get named non-private methods declared or inherited */
3158+
def memberMethod(name: String): List[Symbol]
31593159

3160-
/** Type member with the given name directly declared in the class */
3161-
def typeMember(name: String): Symbol
3160+
/** Get all non-private methods declared or inherited */
3161+
def memberMethods: List[Symbol]
31623162

3163-
/** All members directly declared in the class */
3164-
def members: List[Symbol]
3163+
/** Get non-private named methods defined directly inside the class */
3164+
def declaredType(name: String): List[Symbol]
31653165

3166-
/** Get named non-private methods declared or inherited */
3167-
def method(name: String): List[Symbol]
3166+
/** Get all non-private methods defined directly inside the class, exluding constructors */
3167+
def declaredTypes: List[Symbol]
31683168

3169-
/** Get all non-private methods declared or inherited */
3170-
def methods: List[Symbol]
3169+
/** Type member with the given name directly declared in the class */
3170+
def memberType(name: String): Symbol
3171+
3172+
/** Type member directly declared in the class */
3173+
def memberTypes: List[Symbol]
3174+
3175+
/** All members directly declared in the class */
3176+
def declarations: List[Symbol]
31713177

31723178
/** The symbols of each type parameter list and value parameter list of this
31733179
* method, or Nil if this isn't a method.

scala3doc/src/dotty/dokka/tasty/ClassLikeSupport.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ trait ClassLikeSupport:
120120
}
121121
// TODO check given methods?
122122
case dd: DefDef if !dd.symbol.isHiddenByVisibility && dd.symbol.isGiven =>
123-
Some(dd.symbol.owner.typeMember(dd.name))
123+
Some(dd.symbol.owner.memberType(dd.name))
124124
.filterNot(_.exists)
125125
.map { _ =>
126126
parseMethod(dd.symbol, kind = Kind.Given(getGivenInstance(dd).map(_.asSignature), None))
@@ -156,7 +156,7 @@ trait ClassLikeSupport:
156156
case vd: ValDef if !isSyntheticField(vd.symbol) && (!vd.symbol.flags.is(Flags.Case) || !vd.symbol.flags.is(Flags.Enum)) =>
157157
Some(parseValDef(vd))
158158

159-
case c: ClassDef if c.symbol.owner.method(c.name).exists(_.flags.is(Flags.Given)) =>
159+
case c: ClassDef if c.symbol.owner.memberMethod(c.name).exists(_.flags.is(Flags.Given)) =>
160160
Some(parseGivenClasslike(c))
161161

162162
case c: ClassDef if c.symbol.shouldDocumentClasslike && !c.symbol.isGiven =>

scala3doc/src/dotty/dokka/tasty/SymOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class SymOps[Q <: Quotes](val q: Q):
101101
else
102102
val pointsTo =
103103
if (!sym.isTypeDef) PointingToDeclaration.INSTANCE
104-
else PointingToGenericParameters(sym.owner.typeMembers.indexOf(sym))
104+
else PointingToGenericParameters(sym.owner.memberTypes.indexOf(sym))
105105

106106
val method =
107107
if (sym.isDefDef) Some(sym)

scala3doc/test/dotty/dokka/tasty/comments/CommentExpanderTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import dotty.dokka.tasty.TastyParser
1010
class CommentExpanderTests {
1111
def check(using quoted.Quotes)(): Unit =
1212
assertCommentEquals(
13-
qr.Symbol.requiredClass("tests.B").method("otherMethod").head,
13+
qr.Symbol.requiredClass("tests.B").memberMethod("otherMethod").head,
1414
"/** This is my foo: Bar, actually. */",
1515
)
1616
assertCommentEquals(
1717
qr.Symbol.requiredClass("tests.C"),
1818
"/** This is foo: Foo expanded. */",
1919
)
2020
assertCommentEquals(
21-
qr.Symbol.requiredModule("tests.O").method("method").head,
21+
qr.Symbol.requiredModule("tests.O").memberMethod("method").head,
2222
"/** This is foo: O's foo. */",
2323
)
2424

scala3doc/test/dotty/dokka/tasty/comments/MemberLookupTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) {
8989
if s.flags.is(q.reflect.Flags.Module) then s.moduleClass else s
9090
Sym(hackResolveModule(symbol.field(name)))
9191
def fun(name: String) =
92-
val List(sym) = symbol.method(name)
92+
val List(sym) = symbol.memberMethod(name)
9393
Sym(sym)
94-
def tpe(name: String) = Sym(symbol.typeMember(name))
94+
def tpe(name: String) = Sym(symbol.memberType(name))
9595
}
9696

9797
def cls(fqn: String) = Sym(q.reflect.Symbol.classSymbol(fqn))

tests/run-custom-args/tasty-interpreter/interpreter/jvm/Interpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Interpreter[Q <: Quotes & Singleton](using q0: Q) extends TreeInterpreter[
2929
}
3030

3131
// println(method)
32-
val symbol = sym.methods.find(_.name == method.getName).get
32+
val symbol = sym.memberMethods.find(_.name == method.getName).get
3333

3434
if (symbol.isDefinedInCurrentRun) {
3535
val argsList = if (args == null) Nil else args.toList

tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ object TypeToolbox {
5858
inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl[T]('mem)}
5959
private def methodInImpl[T: Type](mem: Expr[String])(using Quotes) : Expr[Seq[String]] = {
6060
import quotes.reflect._
61-
Expr(TypeTree.of[T].symbol.classMethod(mem.valueOrError).map(_.name))
61+
Expr(TypeTree.of[T].symbol.declaredMethod(mem.valueOrError).map(_.name))
6262
}
6363

6464
inline def methodsIn[T]: Seq[String] = ${methodsInImpl[T]}
6565
private def methodsInImpl[T: Type](using Quotes) : Expr[Seq[String]] = {
6666
import quotes.reflect._
67-
Expr(TypeTree.of[T].symbol.classMethods.map(_.name))
67+
Expr(TypeTree.of[T].symbol.declaredMethods.map(_.name))
6868
}
6969

7070
inline def method[T](inline mem: String): Seq[String] = ${methodImpl[T]('mem)}
7171
private def methodImpl[T: Type](mem: Expr[String])(using Quotes) : Expr[Seq[String]] = {
7272
import quotes.reflect._
73-
Expr(TypeTree.of[T].symbol.method(mem.valueOrError).map(_.name))
73+
Expr(TypeTree.of[T].symbol.memberMethod(mem.valueOrError).map(_.name))
7474
}
7575

7676
inline def methods[T]: Seq[String] = ${methodsImpl[T]}
7777
private def methodsImpl[T: Type](using Quotes) : Expr[Seq[String]] = {
7878
import quotes.reflect._
79-
Expr(TypeTree.of[T].symbol.methods.map(_.name))
79+
Expr(TypeTree.of[T].symbol.memberMethods.map(_.name))
8080
}
8181

8282
inline def typeTag[T](x: T): String = ${typeTagImpl[T]}

tests/run-macros/i6518/Macro_1.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ object Macros {
77
private def testImpl(using Quotes) : Expr[String] = {
88
import quotes.reflect._
99
val classSym = TypeRepr.of[Function1].classSymbol.get
10-
classSym.classMethod("apply")
11-
classSym.classMethods
12-
classSym.method("apply")
13-
Expr(classSym.methods.map(_.name).sorted.mkString("\n"))
10+
classSym.declaredMethod("apply")
11+
classSym.declaredMethods
12+
classSym.memberMethod("apply")
13+
Expr(classSym.memberMethods.map(_.name).sorted.mkString("\n"))
1414
}
1515

1616
}

tests/run-macros/i8520/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def testExpr[T[_]: Type](using Quotes): Expr[Unit] = {
88
if f.is(Flags.Covariant) then "+"
99
else if f.is(Flags.Contravariant) then "-"
1010
else " "
11-
val t = TypeRepr.of[T].typeSymbol.typeMembers.map(x => (x.name, variance(x.flags)))
11+
val t = TypeRepr.of[T].typeSymbol.memberTypes.map(x => (x.name, variance(x.flags)))
1212
'{ println(${Expr(t.toString)}) }
1313
}

tests/run-macros/inferred-repeated-result/test_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Macros {
88
val tree = Term.of(expr)
99

1010
val methods =
11-
tree.tpe.classSymbol.get.classMethods.map { m =>
11+
tree.tpe.classSymbol.get.declaredMethods.map { m =>
1212
val name = m.show
1313
m.tree match
1414
case ddef: DefDef =>

0 commit comments

Comments
 (0)