-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support records in JavaParsers #16762
Merged
TheElectronWill
merged 4 commits into
scala:main
from
TheElectronWill:parse-java-records
May 21, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
68e720c
Support records in JavaParsers
TheElectronWill ed126d9
Fix record's constructor
TheElectronWill d1df3ee
Add more record tests and only run them on java >= 16
TheElectronWill da4996a
Remove synthetic record constructor if the user has written one manually
TheElectronWill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
object C: | ||
def useR1: Unit = | ||
// constructor signature | ||
val r = R1(123, "hello") | ||
|
||
// accessors | ||
val i: Int = r.i | ||
val s: String = r.s | ||
|
||
// methods | ||
val iRes: Int = r.getInt() | ||
val sRes: String = r.getString() | ||
|
||
// supertype | ||
val record: java.lang.Record = r | ||
|
||
def useR2: Unit = | ||
// constructor signature | ||
val r2 = R2.R(123, "hello") | ||
|
||
// accessors signature | ||
val i: Int = r2.i | ||
val s: String = r2.s | ||
|
||
// method | ||
val i2: Int = r2.getInt | ||
|
||
// supertype | ||
val isIntLike: IntLike = r2 | ||
val isRecord: java.lang.Record = r2 | ||
|
||
def useR3 = | ||
// constructor signature | ||
val r3 = R3(123, 42L, "hi") | ||
new R3("hi", 123) | ||
// accessors signature | ||
val i: Int = r3.i | ||
val l: Long = r3.l | ||
val s: String = r3.s | ||
// method | ||
val l2: Long = r3.l(43L, 44L) | ||
// supertype | ||
val isRecord: java.lang.Record = r3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
trait IntLike: | ||
def getInt: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public record R1(int i, String s) { | ||
public String getString() { | ||
return s + i; | ||
} | ||
|
||
public int getInt() { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class R2 { | ||
final record R(int i, String s) implements IntLike { | ||
public int getInt() { | ||
return i; | ||
} | ||
|
||
// Canonical constructor | ||
public R(int i, java.lang.String s) { | ||
this.i = i; | ||
this.s = s.intern(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
public record R3(int i, long l, String s) { | ||
|
||
// User-specified accessor | ||
public int i() { | ||
return i + 1; // evil >:) | ||
} | ||
|
||
// Not an accessor - too many parameters | ||
public long l(long a1, long a2) { | ||
return a1 + a2; | ||
} | ||
|
||
// Secondary constructor | ||
public R3(String s, int i) { | ||
this(i, 42L, s); | ||
} | ||
|
||
// Compact constructor | ||
public R3 { | ||
s = s.intern(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this when it became necessary to report bots on github?