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

Generate code for enums in definition blocks #31

Merged
merged 3 commits into from
May 24, 2022

Conversation

Eric-Warehime
Copy link
Contributor

This updates the generator to address #19 --it generates enums in the Enums.java file which include any enums listed in the definitions section. The template generator was also updated to ignore these since the go sdk generated using the template generator does not have a concept of enums really.

@Eric-Warehime Eric-Warehime changed the title Duplicate enum Generate code for enums in definition blocks May 20, 2022
Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple questions

@@ -291,6 +291,9 @@ public void terminate() {
public void onEvent(Publisher.Events event, TypeDef type) {
switch(event) {
case NEW_PROPERTY:
if (type.isOfType("enum")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, could we change the go templates to skip over enums?

Ideally we would use the template approach for all SDKs, so at least the JavaSDK would need this event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the go SDK still need this, but use "string"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would use the template approach for all SDKs, so at least the JavaSDK would need this event.

I see your point...I'll take a look and see if it's easy to configure enum-specific behavior in the templates.

From what I can tell both the JS and Go Sdks just use string fields for enums so there is no need to take an action in addition to those we're already taking when generating paths, models, etc. like we are in Java.

Copy link
Contributor

@algonautshant algonautshant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Great!

Copy link
Contributor

@michaeldiamant michaeldiamant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Warehime Approving based on the evidence provided by downstream PRs generating expected diffs. Thank you for tackling the problem and for finding a way to restore the code generation process! ☕

Aside with a few caveats: Perhaps in a future iteration, tests can be added here to defend against regressions and/or behavior changes.

  • Since we have proof the changes work, I don't think the remark ought to hold up the PR.
  • As a reviewer, I feel obligated to consider testing in my review. Admittedly, I am unfamiliar with the repo's conventions + practices. And a cursory review of recent PRs does not reveal tests.

@@ -118,6 +118,9 @@ public void onEvent(Events event, TypeDef type) {
case BODY_CONTENT:
javaQueryWriter.addQueryProperty(type, false, false, true);
break;
case ENUM_DEFINITION:
this.storeEnumDefinition(type);
Copy link
Contributor

@winder winder May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On closer inspection, I think we can add this check without changing the parser. This would go in the TypeDef event:

         case NEW_PROPERTY:
             javaModelWriter.newProperty(type);
+            if (type.enumValues != null && type.enumValues.size() > 0) {
+                 this.storeEnumDefinition(type);
+            }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work. The reason we have to change the parser is because generateAlgodIndexerObjects is the only method which is looking at the definitions block, and the following code block ensure that objects in that block are skipped if they don't have properties defined, which enums do not have.

if (!hasProperties(cls.getValue())) {
    // If it has no properties, no class is needed for this type.
    continue;
}

So in that case we wouldn't ever enter the NEW_PROPERTY event block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, as an aside, enums implicity defined in the Parameters section are omitted from the generated code (Format)

@Eric-Warehime Eric-Warehime merged commit d8fbe4e into algorand:master May 24, 2022
@Eric-Warehime Eric-Warehime deleted the duplicate-enum branch May 24, 2022 19:18
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.

None yet

5 participants