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

Java Frontend: EnumDeclarations do not get any content other than entries #1445

Closed
robinmaisch opened this issue Mar 4, 2024 · 5 comments · Fixed by #1450
Closed

Java Frontend: EnumDeclarations do not get any content other than entries #1445

robinmaisch opened this issue Mar 4, 2024 · 5 comments · Fixed by #1450

Comments

@robinmaisch
Copy link
Contributor

Hello CPG team,
the de.fraunhofer.aisec.cpg.frontends.java.DeclarationHandler ignores the members of enumDecl in the method handleEnumDeclaration, so any new EnumDeclaration does not get any fields, methods, constructors that it may need.
Import statements are also not considered, unlike for records.

I copied and adapted the relevant parts of handleClassOrInterfaceDeclaration (lines ~227-303) over to handleEnumDeclaration, and that seemed to work quite well as a start, but I could not get it to work completely in the end.
I hope you can have a look into it.

@konradweiss
Copy link
Collaborator

Hi :) Thanks for reporting the Issue. I will look into it and find out what the best option is there. I assume you mean in the Java language Frontend?

@konradweiss
Copy link
Collaborator

If you have a specific piece of code that shows the issue I'd love to test it out.

@robinmaisch
Copy link
Contributor Author

Yes, here's a sample class. For me, the resulting EnumDeclaration has no methods or fields, only the two entries are present.

GitHub wouldn't let me upload a .java file, so here's the file zipped.
Enums.zip

Here's the content:

public enum Enums {

    VALUE_ONE(1),
    VALUE_TWO(2);

    private int value;
    public static final String NAME = "Enums";

    Enums(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
    public static void main(String[] args) {
        Enums e = Enums.VALUE_ONE;
        Enums e2 = Enums.VALUE_TWO;
    }
}

@konradweiss
Copy link
Collaborator

Thanks for that :) if you already have something that is not finished but shows an approach that you would follow you can submit a draft PR and signal what is missing or still not working.

@robinmaisch
Copy link
Contributor Author

It turned out my approach did work, it was only my test that was wrong. Have a look :)

@oxisto oxisto linked a pull request Mar 8, 2024 that will close this issue
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 a pull request may close this issue.

2 participants