-
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
Java enums #6629
Merged
Merged
Java enums #6629
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ mixin-forwarder-overload | |
t8905 | ||
t10889 | ||
i5257.scala | ||
enum-java |
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,44 @@ | ||
API Test A | ||
compareTo greater:-1 | ||
compareTo lesser: 1 | ||
compareTo self: 0 | ||
equals other: false | ||
equals self: true | ||
getDeclaringClass:class A | ||
name: MONDAY | ||
ordinal: 0 | ||
toString: MONDAY | ||
|
||
API Test B | ||
compareTo greater:-1 | ||
compareTo lesser: 1 | ||
compareTo self: 0 | ||
equals other: false | ||
equals self: true | ||
getDeclaringClass:class B | ||
name: EARTH | ||
ordinal: 0 | ||
toString: EARTH | ||
|
||
Module Test | ||
Values class: class [LA; | ||
MONDAY : 0 | ||
TUESDAY : 1 | ||
SATURDAY : 2 | ||
By-name value: MONDAY | ||
Correctly failed to retrieve illegal name, message: key not found: stuff | ||
|
||
Collections Test | ||
Retrieving Monday: workday | ||
Contains Tuesday: false | ||
All days: | ||
MONDAY | ||
TUESDAY | ||
SATURDAY | ||
|
||
Switch Test | ||
Saw tuesday | ||
Jup | ||
|
||
Misc Tests | ||
Gravity on Earth: 9.8 |
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,10 @@ | ||
enum A extends java.lang.Enum[A] { | ||
case MONDAY, TUESDAY, SATURDAY | ||
} | ||
|
||
enum B(val gravity: Double) extends java.lang.Enum[B] { | ||
case EARTH extends B(9.8) | ||
case JUPITER extends B(100) | ||
case MOON extends B(4.3) | ||
case Foo extends B(10) | ||
} |
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,88 @@ | ||
public class Test { | ||
public static void log(String x) { System.out.println(x); } | ||
public static void check(Boolean p, String message) { | ||
if (!p) throw new RuntimeException("Assertion failed: " + message); | ||
} | ||
|
||
public static <E extends java.lang.Enum<E>> void apiTest(E t1, E t2) { | ||
log("compareTo greater:" + t1.compareTo(t2) ); | ||
log("compareTo lesser: " + t2.compareTo(t1) ); | ||
log("compareTo self: " + t1.compareTo(t1) ); | ||
log("equals other: " + t1.equals(t2) ); | ||
log("equals self: " + t1.equals(t1) ); | ||
log("getDeclaringClass:" + t1.getDeclaringClass() ); | ||
log("name: " + t1.name() ); | ||
log("ordinal: " + t1.ordinal() ); | ||
log("toString: " + t1.toString() ); | ||
} | ||
|
||
public static void moduleTest() { | ||
A[] values = A.values(); | ||
log("Values class: " + values.getClass()); | ||
for (A v: values) log(v.name() + " : " + v.ordinal()); | ||
log("By-name value: " + A.valueOf("MONDAY")); | ||
try { | ||
A.valueOf("stuff"); | ||
} | ||
catch (IllegalArgumentException e) { | ||
log("Correctly failed to retrieve illegal name, message: " + e.getMessage()); | ||
} | ||
} | ||
|
||
public static void collectionsTest() { | ||
java.util.EnumMap<A, String> days = new java.util.EnumMap<A, String>(A.class); | ||
days.put(A.MONDAY, "workday"); | ||
days.put(A.SATURDAY, "weekend"); | ||
|
||
log("Retrieving Monday: " + days.get(A.MONDAY)); | ||
log("Contains Tuesday: " + days.containsKey(A.TUESDAY)); | ||
|
||
java.util.EnumSet<A> allDays = java.util.EnumSet.allOf(A.class); | ||
log("All days:"); | ||
for (A d : allDays) log(d.toString()); | ||
} | ||
|
||
public static void switchTest() { | ||
A a = A.TUESDAY; | ||
switch(a) { | ||
case MONDAY: | ||
log("Saw monday"); | ||
break; | ||
case TUESDAY: | ||
log("Saw tuesday"); | ||
break; | ||
} | ||
|
||
B b = B.JUPITER; | ||
switch (b) { | ||
case JUPITER: log("Jup"); break; | ||
case EARTH: log("Earth"); break; | ||
} | ||
} | ||
|
||
public static void miscTests() { | ||
log("Gravity on Earth: " + B.EARTH.gravity()); | ||
check(A.class.isEnum(), "A class must be enum"); | ||
check(B.class.isEnum(), "B class must be enum"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
log("API Test A"); | ||
apiTest(A.MONDAY, A.TUESDAY); | ||
|
||
log("\nAPI Test B"); | ||
apiTest(B.EARTH, B.JUPITER); | ||
|
||
log("\nModule Test"); | ||
moduleTest(); | ||
|
||
log("\nCollections Test"); | ||
collectionsTest(); | ||
|
||
log("\nSwitch Test"); | ||
switchTest(); | ||
|
||
log("\nMisc Tests"); | ||
miscTests(); | ||
} | ||
} |
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.
Should this go into a
SymTransformer
?