-
Notifications
You must be signed in to change notification settings - Fork 15
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
Adds support for Java enum generation #158
Merged
desaikd
merged 10 commits into
amazon-ion:new-model-changes
from
desaikd:java-enums-impl
Oct 24, 2024
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3daf3d1
adds changes for enum support
desaikd 7d03d77
adds tests for enum generation
desaikd 6d169ff
Adds changes for requiring symbol values in `valid_values` for enum
desaikd 6c281ad
Adds suggested changes
desaikd 238f479
Adds changes for placeholder Rust enum template
desaikd e4cfd64
Adds tests changes for enums
desaikd d3acfcb
Fixes bug for Rust namepsace in generated code
desaikd 6e122ee
Fixes bug for Rust namespace in generated code
desaikd 04888c6
Adds suggested changes
desaikd 6317b94
Add minor doc comment change
desaikd 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
1 change: 1 addition & 0 deletions
1
code-gen-projects/input/bad/enum_type/invalid_case_enum_varaint.ion
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 @@ | ||
FoobarBaz // expected FooBarBaz, found FoobarBaz |
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 @@ | ||
hello // expected (foo, bar, baz or FooBarBaz) found hello |
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 @@ | ||
"foo" // expected a symbol value foo for enum, found string "foo" |
7 changes: 7 additions & 0 deletions
7
code-gen-projects/input/bad/struct_with_enum_fields/mismatched_sequence_element_type.ion
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,7 @@ | ||
// struct with mismatched sequence element | ||
{ | ||
A: "hello", | ||
B: 12, | ||
C: (1 2 3), // expected sexpression of strings | ||
D: 10e2 | ||
} |
7 changes: 7 additions & 0 deletions
7
code-gen-projects/input/bad/struct_with_enum_fields/mismatched_sequence_type.ion
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,7 @@ | ||
// simple struct with type mismatched sequence type | ||
{ | ||
A: "hello", | ||
B: 12, | ||
C: ["foo", "bar", "baz"], // expected sexp | ||
D: 10e2 | ||
} |
7 changes: 7 additions & 0 deletions
7
code-gen-projects/input/bad/struct_with_enum_fields/mismatched_type.ion
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,7 @@ | ||
// simple struct with type mismatched fields | ||
{ | ||
A: "hello", | ||
B: false, // expected field type: int | ||
C: ("foo" "bar" "baz"), | ||
D: 10e2 | ||
} |
7 changes: 7 additions & 0 deletions
7
code-gen-projects/input/bad/struct_with_enum_fields/missing_required_fields.ion
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,7 @@ | ||
// simple struct with all valid fields | ||
{ | ||
A: "hello", | ||
B: 12, | ||
// C: ("foo" "bar" "baz"), // since `C` is a required field, this is an invalid struct | ||
D: 10e2 | ||
} |
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 @@ | ||
foo |
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 @@ | ||
bar |
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 @@ | ||
baz |
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 @@ | ||
FooBarBaz |
7 changes: 7 additions & 0 deletions
7
code-gen-projects/input/good/struct_with_enum_fields/empty_values.ion
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,7 @@ | ||
// struct with empty list, empty string and zeros | ||
{ | ||
C: (), | ||
A: "", | ||
B: 0, | ||
D: 0e0, | ||
} |
8 changes: 8 additions & 0 deletions
8
code-gen-projects/input/good/struct_with_enum_fields/valid_fields.ion
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,8 @@ | ||
// simple struct with all valid fields | ||
{ | ||
A: "hello", | ||
B: 12, | ||
C: ("foo" "bar" "baz"), | ||
D: 10e2, | ||
E: foo | ||
} |
8 changes: 8 additions & 0 deletions
8
code-gen-projects/input/good/struct_with_enum_fields/valid_optional_fields.ion
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,8 @@ | ||
// simple struct with all valid fields | ||
{ | ||
A: "hello", | ||
B: 12, | ||
C: ("foo" "bar" "baz"), | ||
// D: 10e2, // since `D` is optional field, this is a valid struct | ||
E: foo, | ||
} |
8 changes: 8 additions & 0 deletions
8
code-gen-projects/input/good/struct_with_enum_fields/valid_unordered_fields.ion
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,8 @@ | ||
// struct with unordered fields | ||
{ | ||
C: ("foo" "bar" "baz"), | ||
A: "hello", | ||
B: 12, | ||
E: foo, | ||
D: 10e2, | ||
} |
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,4 @@ | ||
type::{ | ||
name: enum_type, | ||
valid_values: [foo, bar, baz, FooBarBaz] | ||
} |
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,12 @@ | ||
type::{ | ||
name: struct_with_enum_fields, | ||
type: struct, | ||
fields: { | ||
A: string, | ||
B: int, | ||
C: { element: string, type: sexp, occurs: required }, | ||
D: float, | ||
E: { valid_values: [foo, bar, baz] } | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
The way this is implemented, if I defined something like this, it would fail because it's not a supported way of defining an enum, even though a user would expect this to be a perfectly valid scalar.
In order to classify something as an enum, it must have a
valid_values
constraint, and all of its valid values should be symbols so that we don't incorrectly classify something such as this example. (I would be inclined to limit it specifically to symbols unless we specifically get a request to allow other things.)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.
Made changes to allow only
symbol
withvalid_values
for enum generation.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.
I'm not sure I explained myself well enough. The way you have implemented this, the categorization (i.e. this
if
condition) is overly broad. That means it could catch other type definitions that are not intended to be enums in the first place.In order to even be categorized as an enum, it should have a
valid_values
constraint with only symbols. Checking for symbols in thevalid_values
constraint needs to happen here, or else the enum code will reject things likeI believe it should be something like this (although this is quite long for an
if
condition, and should probably be extracted to a helper function).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.
I did have this check inside the
build_enum_from_constraints
. But I understand that adding it here keeps the generation separate from these checks. I will change this.