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

Added [Feature]: a toString() method for enumerated values in Java #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

subhajit20
Copy link
Contributor

@subhajit20 subhajit20 commented Mar 31, 2024

Closes accordproject/concerto#100

Changes

  • override the toString method inside the javavisitor enumDeclaration function
  • Updated snapshots for required changes
  • Added test for the changes

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

Signed-off-by: Subhajit Ghosh <subhajitstd07@gmail.com>
Signed-off-by: Subhajit Ghosh <subhajitstd07@gmail.com>
Signed-off-by: Subhajit Ghosh <subhajitstd07@gmail.com>
@subhajit20
Copy link
Contributor Author

hey @mttrbrts @sanketshevkar can you please review and give some feedback

Signed-off-by: Subhajit Ghosh <subhajitstd07@gmail.com>
@coveralls
Copy link

coveralls commented Mar 31, 2024

Coverage Status

coverage: 98.739% (+0.001%) from 98.738%
when pulling 7c14d70 on subhajit20:feature/javavisitor_enumDeclaration_toString
into a2463e0 on accordproject:main.

@@ -1196,6 +1208,10 @@ import com.fasterxml.jackson.annotation.*;
public enum LaptopMake {
Apple,
Microsoft,
@Override
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if enums in java store functions.

Copy link
Contributor Author

@subhajit20 subhajit20 Apr 1, 2024

Choose a reason for hiding this comment

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

Yes it does, because I have created one java program where I declared a enum and inside it defined the toString function and it worked totally final without any issue

Copy link
Member

Choose a reason for hiding this comment

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

Okay, thanks for clarification. I'm not much proficient in Java. @mttrbrts can you please review this?

Copy link
Contributor Author

@subhajit20 subhajit20 Apr 1, 2024

Choose a reason for hiding this comment

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

Here is a sample code snippet

public class Main{
    public enum State {
        MA,
        NY,
        CO,
    
        // Override the toString() method for the entire enum type
        @Override
        public String toString() {
            return name();
        }
    }
    public static void main(String[] args) {
        // Using the enum constants
        State state1 = State.MA;
        State state2 = State.NY;
        String ma = state1.toString();  // This will call the overridden toString() method
        
        // Printing the enum constants
        System.out.println("State 1: " + ma);
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @sanketshevkar Have one question, How can I pass extra parameters like parameters.filewriter as show in the code.. I mean to say can we pass other parameter like this parameters.x ?

parameters.fileWriter.writeLine(0, 'public enum ' + enumDeclaration.getName() + ' {' );
enumDeclaration.getOwnProperties().forEach((property) => {
property.accept(this, parameters);
});

Copy link
Member

Choose a reason for hiding this comment

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

yes, you can. it is an options object on the visitor. (answered by @dselman on the Tech WG call)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you can. it is an options object on the visitor. (answered by @dselman on the Tech WG call)

Okay ... I am assuming is that something like this parameters.options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! is there any update or any feedback on this pr? @dselman @mttrbrts

@subhajit20 subhajit20 force-pushed the feature/javavisitor_enumDeclaration_toString branch from 18522a9 to 7c14d70 Compare April 3, 2024 03:09
@DianaLease DianaLease requested a review from dselman April 3, 2024 12:16
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.

[Feature] Provide a toString() method for enumerated values in Java
4 participants