-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Symbol.allMembers to reflection API #13391
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3756,6 +3756,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => | |
/** All members directly declared in the class */ | ||
def declarations: List[Symbol] | ||
|
||
/** All members declared or inherited */ | ||
def allMembers: List[Symbol] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like in the documentation of Type#allMembers, we should mention that this can be slow to compute. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need then to update other methods documentation that use in their implementation Type#allMembers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even better would be to fix these methods to not call allMembers :) Instead, we should be able to use memberDenots in most cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make this an iterator. We already do this for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should also be marked as |
||
|
||
/** The symbols of each type parameter list and value parameter list of this | ||
* method, or Nil if this isn't a method. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
List(java.lang.Object.eq, scala.Any.hashCode, java.lang.Object.synchronized, scala.Any.$isInstanceOf$, scala.Any.$asInstanceOf$, java.lang.Object.notifyAll, java.lang.Object.clone, scala.Any.!=, scala.Any.getClass, java.lang.Object.finalize, scala.Any.toString, java.lang.Object.wait, java.lang.Object.wait, java.lang.Object.wait, java.lang.Object.notify, java.lang.Object.ne, scala.Any.##, scala.Any.equals, scala.Any.isInstanceOf, scala.Any.asInstanceOf, scala.Any.==) | ||
List(A.foo, java.lang.Object.eq, scala.Any.hashCode, java.lang.Object.synchronized, scala.Any.$isInstanceOf$, A.x, scala.Any.$asInstanceOf$, java.lang.Object.notifyAll, java.lang.Object.clone, A.X, scala.Any.!=, scala.Any.getClass, java.lang.Object.finalize, scala.Any.toString, java.lang.Object.wait, java.lang.Object.wait, java.lang.Object.wait, java.lang.Object.notify, java.lang.Object.ne, scala.Any.##, scala.Any.equals, scala.Any.isInstanceOf, scala.Any.asInstanceOf, scala.Any.==) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.quoted.* | ||
|
||
inline def allMembers[T]: List[String] = | ||
${ allMembersExpr[T] } | ||
|
||
private def allMembersExpr[T: Type](using Quotes): Expr[List[String]] = | ||
import quotes.reflect.* | ||
Expr(TypeRepr.of[T].typeSymbol.allMembers.map(_.fullName).toList) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class A: | ||
type X | ||
val x: Int = 1 | ||
def foo: Int = 1 | ||
@main def Test: Unit = | ||
println(allMembers[Object]) | ||
println(allMembers[A]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the test I added, the order of the members is not deterministic.