Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize Symbol member methods in reflection API #13314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3588,21 +3588,17 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def declaredFields: List[Symbol]

/** Get named non-private fields declared or inherited */
// TODO: deprecate in 3.1.0 and remove @experimental from fieldMember
// @deprecated("Use fieldMember", "3.1")
@deprecated("Use fieldMember", "3.1.0")
def memberField(name: String): Symbol

/** Get named non-private fields declared or inherited */
@experimental
def fieldMember(name: String): Symbol

/** Get all non-private fields declared or inherited */
// TODO: deprecate in 3.1.0 and remove @experimental from fieldMembers
// @deprecated("Use fieldMembers", "3.1")
@deprecated("Use fieldMembers", "3.1.0")
def memberFields: List[Symbol]

/** Get all non-private fields declared or inherited */
@experimental
def fieldMembers: List[Symbol]

/** Get non-private named methods defined directly inside the class */
Expand All @@ -3612,21 +3608,17 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def declaredMethods: List[Symbol]

/** Get named non-private methods declared or inherited */
// TODO: deprecate in 3.1.0 and remove @experimental from methodMember
// @deprecated("Use methodMember", "3.1")
@deprecated("Use methodMember", "3.1.0")
def memberMethod(name: String): List[Symbol]

/** Get named non-private methods declared or inherited */
@experimental
def methodMember(name: String): List[Symbol]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do both methodMember and methodMembers return a List[Symbol] ? Shouldn't methodMember return a Symbol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the overloads


/** Get all non-private methods declared or inherited */
// TODO: deprecate in 3.1.0 and remove @experimental from methodMembers
// @deprecated("Use methodMembers", "3.1")
@deprecated("Use methodMembers", "3.1.0")
def memberMethods: List[Symbol]

/** Get all non-private methods declared or inherited */
@experimental
def methodMembers: List[Symbol]

/** Get non-private named methods defined directly inside the class */
Expand All @@ -3636,21 +3628,17 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def declaredTypes: List[Symbol]

/** Type member with the given name directly declared in the class */
// TODO: deprecate in 3.1.0 and remove @experimental from typeMember
// @deprecated("Use typeMember", "3.1")
@deprecated("Use typeMember", "3.1.0")
def memberType(name: String): Symbol

/** Type member with the given name directly declared in the class */
@experimental
def typeMember(name: String): Symbol

/** Type member directly declared in the class */
// TODO: deprecate in 3.1.0 and remove @experimental from typeMembers
// @deprecated("Use typeMembers", "3.1")
@deprecated("Use typeMembers", "3.1.0")
def memberTypes: List[Symbol]

/** Type member directly declared in the class */
@experimental
def typeMembers: List[Symbol]

/** All members directly declared in the class */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ trait ClassLikeSupport:
}
// TODO check given methods?
case dd: DefDef if !dd.symbol.isHiddenByVisibility && dd.symbol.isGiven && !dd.symbol.isArtifact =>
Some(dd.symbol.owner.memberType(dd.name))
Some(dd.symbol.owner.typeMember(dd.name))
.filterNot(_.exists)
.map { _ =>
parseMethod(c, dd.symbol, specificKind =
Expand Down Expand Up @@ -312,7 +312,7 @@ trait ClassLikeSupport:
case vd: ValDef if !isSyntheticField(vd.symbol) && (!vd.symbol.flags.is(Flags.Case) || !vd.symbol.flags.is(Flags.Enum)) =>
Some(parseValDef(c, vd))

case c: ClassDef if c.symbol.owner.memberMethod(c.name).exists(_.flags.is(Flags.Given)) =>
case c: ClassDef if c.symbol.owner.methodMember(c.name).exists(_.flags.is(Flags.Given)) =>
Some(parseGivenClasslike(c))

case c: ClassDef if c.symbol.shouldDocumentClasslike && !c.symbol.isGiven =>
Expand Down Expand Up @@ -348,7 +348,7 @@ trait ClassLikeSupport:
def inheritance = Some(InheritedFrom(s.symbol.owner.normalizedName, s.symbol.dri))
processTreeOpt(s)(s match
case c: ClassDef if c.symbol.shouldDocumentClasslike && !c.symbol.isGiven => Some(parseClasslike(c, signatureOnly = true))
case c: ClassDef if c.symbol.owner.memberMethod(c.name).exists(_.flags.is(Flags.Given)) => Some(parseGivenClasslike(c))
case c: ClassDef if c.symbol.owner.methodMember(c.name).exists(_.flags.is(Flags.Given)) => Some(parseGivenClasslike(c))
case other => {
val parsed = parseMember(c)(other)
parsed.map(p =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import dotty.tools.scaladoc.tasty.TastyParser
class CommentExpanderTests {
def check(using Quotes)(): Unit =
assertCommentEquals(
reflect.Symbol.requiredClass("tests.B").memberMethod("otherMethod").head,
reflect.Symbol.requiredClass("tests.B").methodMember("otherMethod").head,
"/** This is my foo: Bar, actually. */",
)
assertCommentEquals(
reflect.Symbol.requiredClass("tests.C"),
"/** This is foo: Foo expanded. */",
)
assertCommentEquals(
reflect.Symbol.requiredModule("tests.O").memberMethod("method").head,
reflect.Symbol.requiredModule("tests.O").methodMember("method").head,
"/** This is foo: O's foo. */",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) {
if s.flags.is(q.reflect.Flags.Module) then s.moduleClass else s
Sym(hackResolveModule(symbol.declaredField(name)))
def fun(name: String) =
val List(sym) = symbol.memberMethod(name)
val List(sym) = symbol.methodMember(name)
Sym(sym)
def tpe(name: String) = Sym(symbol.memberType(name))
def tpe(name: String) = Sym(symbol.typeMember(name))
}

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