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

Better way to get product elements #264

Merged
merged 2 commits into from
Oct 24, 2023
Merged

Conversation

honnix
Copy link
Member

@honnix honnix commented Oct 23, 2023

TL;DR

Prefer using Scala 2.13's way to get product element names

Type

  • Bug Fix
  • Feature
  • Plugin

Are all requirements met?

  • Code completed
  • Smoke tested
  • Unit tests added (covered by IT)
  • Code documentation added
  • Any pending items have an associated Issue

Complete description

Since most users should have been on Scala 2.13, we can have a better way to get product element names, with fallback to Java's way.

getDeclaredFields from Java is less reliable, and it doesn't get super classes' declared fields. We could do that ourselves, but it is impossible to get the correct order.

For case class like:

class B(val a: String, val b: String)

case class A(override val a: String, c: String, override val b: String) extends B(a, b)

productElementNames can correctly get [a, c, b] for instance of A, but getDeclaredFields can only get c for instance of A. It won't work if we try to recursively go up to get all declared fields, because we would not be able to put up a correct order where c appears between a and b.

Tracking Issue

NA

Follow-up issue

NA

Signed-off-by: Hongxin Liang <[email protected]>
@andresgomezfrr andresgomezfrr merged commit 54d2410 into master Oct 24, 2023
3 checks passed
@andresgomezfrr andresgomezfrr deleted the get-all-declared-fields branch October 24, 2023 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants