Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7
    • Component/s: Java API
    • Labels:
      None
    • Number of attachments :
      2

      Description

      Following on from QDOX-74, Java 5 enums should be accessible through the model.

      Ponder - do we create a JavaEnum class, or maybe just add some methods to JavaClass?

      1. EnumsModelTest.java
        7 kB
        Andrew Mickish
      2. parser.y.diff
        1 kB
        Andrew Mickish

        Activity

        Hide
        Daniel Serodio added a comment -

        Any news on this? It's been almost a year since the bug was reported and no one touched it yet.

        Show
        Daniel Serodio added a comment - Any news on this? It's been almost a year since the bug was reported and no one touched it yet.
        Hide
        Ted Bergeron added a comment -

        It's been close to 2.5 years now. Is this a dead project?

        Show
        Ted Bergeron added a comment - It's been close to 2.5 years now. Is this a dead project?
        Hide
        Libor Tvrdík added a comment -

        I use 1.6.3 and 1.7-20070527.154641-2 version.

        This is stack trace:

        Exception in thread "main" com.thoughtworks.qdox.parser.ParseException: 
            syntax error @[35,20] in file:/...myclass.....java
        	at com.thoughtworks.qdox.parser.impl.Parser.yyerror(Parser.java:716)
        	at com.thoughtworks.qdox.parser.impl.Parser.yyparse(Parser.java:826)
        	at com.thoughtworks.qdox.parser.impl.Parser.parse(Parser.java:697)
                ... my class
        
        Show
        Libor Tvrdík added a comment - I use 1.6.3 and 1.7-20070527.154641-2 version. This is stack trace: Exception in thread "main" com.thoughtworks.qdox.parser.ParseException: syntax error @[35,20] in file:/...myclass.....java at com.thoughtworks.qdox.parser.impl.Parser.yyerror(Parser.java:716) at com.thoughtworks.qdox.parser.impl.Parser.yyparse(Parser.java:826) at com.thoughtworks.qdox.parser.impl.Parser.parse(Parser.java:697) ... my class
        Hide
        Andrew Mickish added a comment -

        Since this issue has not been fully addressed, I modified my personal build of QDox to get enums working for my own needs.

        The problem is that while QDox 1.7 successfully parses enums, the parser doesn't add them to the model. From a top-level application's perspective, QDox appears to ignore the enums.

        My fix was to modify QDox's parser.y grammar to add each enum's member as a field. Consequently, my top-level application is able to iterate over the members of an enum like fields in a class.

        // ----- ENUM

        enum: enum_definition BRACEOPEN enum_body BRACECLOSE

        { builder.endClass(); fieldType = null; modifiers.clear(); }

        ;

        enum_definition: modifiers ENUM IDENTIFIER opt_implements

        { cls.lineNumber = line; cls.modifiers.addAll(modifiers); cls.name = $3; cls.type = ClassDef.ENUM; builder.beginClass(cls); cls = new ClassDef(); fieldType = new TypeDef($3, 0); }

        ;

        enum_body: enum_values | enum_values SEMI members;

        enum_values: | enum_value | enum_value COMMA enum_values;

        enum_value:
        javadoc enum_constructor |
        opt_annotations enum_constructor;

        enum_constructor:
        IDENTIFIER

        { makeField(new TypeDef($1, 0), ""); } |
        IDENTIFIER CODEBLOCK { makeField(new TypeDef($1, 0), ""); }

        |
        IDENTIFIER PARENBLOCK

        { makeField(new TypeDef($1, 0), ""); } |
        IDENTIFIER PARENBLOCK CODEBLOCK { makeField(new TypeDef($1, 0), ""); }

        ;

        I have attached a patch file.

        Show
        Andrew Mickish added a comment - Since this issue has not been fully addressed, I modified my personal build of QDox to get enums working for my own needs. The problem is that while QDox 1.7 successfully parses enums, the parser doesn't add them to the model. From a top-level application's perspective, QDox appears to ignore the enums. My fix was to modify QDox's parser.y grammar to add each enum's member as a field. Consequently, my top-level application is able to iterate over the members of an enum like fields in a class. // ----- ENUM enum: enum_definition BRACEOPEN enum_body BRACECLOSE { builder.endClass(); fieldType = null; modifiers.clear(); } ; enum_definition: modifiers ENUM IDENTIFIER opt_implements { cls.lineNumber = line; cls.modifiers.addAll(modifiers); cls.name = $3; cls.type = ClassDef.ENUM; builder.beginClass(cls); cls = new ClassDef(); fieldType = new TypeDef($3, 0); } ; enum_body: enum_values | enum_values SEMI members; enum_values: | enum_value | enum_value COMMA enum_values; enum_value: javadoc enum_constructor | opt_annotations enum_constructor; enum_constructor: IDENTIFIER { makeField(new TypeDef($1, 0), ""); } | IDENTIFIER CODEBLOCK { makeField(new TypeDef($1, 0), ""); } | IDENTIFIER PARENBLOCK { makeField(new TypeDef($1, 0), ""); } | IDENTIFIER PARENBLOCK CODEBLOCK { makeField(new TypeDef($1, 0), ""); } ; I have attached a patch file.
        Hide
        Andrew Mickish added a comment -

        Expose enum members to the model as fields

        Show
        Andrew Mickish added a comment - Expose enum members to the model as fields
        Andrew Mickish made changes -
        Field Original Value New Value
        Attachment parser.y.diff [ 32673 ]
        Hide
        Paul Hammant added a comment -

        Andrew. Thanks for the patch.

        If you can also supply a unit test that illustrates/proves the enum case, then we'll apply it

        • Paul
        Show
        Paul Hammant added a comment - Andrew. Thanks for the patch. If you can also supply a unit test that illustrates/proves the enum case, then we'll apply it Paul
        Hide
        Andrew Mickish added a comment -

        EnumsModelTest.java is a sequel to EnumsTest.java, showing that parsed enums are accessed like fields in the QDox model.

        Show
        Andrew Mickish added a comment - EnumsModelTest.java is a sequel to EnumsTest.java, showing that parsed enums are accessed like fields in the QDox model.
        Andrew Mickish made changes -
        Attachment EnumsModelTest.java [ 32799 ]
        Hide
        Arnaud Vandyck added a comment -

        Hi,

        Have those patches been applied? I'd like to use this feature in a project. Which release can I get to use this?

        Many thanks for your cool project!

        Show
        Arnaud Vandyck added a comment - Hi, Have those patches been applied? I'd like to use this feature in a project. Which release can I get to use this? Many thanks for your cool project!
        Hide
        Paul Hammant added a comment -

        Unfortunately the tests fail for the patch and unit test above :

        -------------------------------------------------------------------------------
        Test set: com.thoughtworks.qdox.EnumsModelTest
        -------------------------------------------------------------------------------
        Tests run: 6, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec <<< FAILURE!
        testAddEnumWithAnnotationToModel(com.thoughtworks.qdox.EnumsModelTest) Time elapsed: 0.008 sec <<< FAILURE!
        junit.framework.AssertionFailedError: expected:<1> but was:<0>
        at junit.framework.Assert.fail(Assert.java:47)
        at junit.framework.Assert.failNotEquals(Assert.java:282)
        at junit.framework.Assert.assertEquals(Assert.java:64)
        at junit.framework.Assert.assertEquals(Assert.java:201)
        at junit.framework.Assert.assertEquals(Assert.java:207)
        at com.thoughtworks.qdox.EnumsModelTest.testAddEnumWithAnnotationToModel(EnumsModelTest.java:113)

        testAddEnumWithFieldAndConstructorsToModel(com.thoughtworks.qdox.EnumsModelTest) Time elapsed: 0.002 sec <<< FAILURE!
        junit.framework.AssertionFailedError: expected:<1> but was:<0>
        at junit.framework.Assert.fail(Assert.java:47)
        at junit.framework.Assert.failNotEquals(Assert.java:282)
        at junit.framework.Assert.assertEquals(Assert.java:64)
        at junit.framework.Assert.assertEquals(Assert.java:201)
        at junit.framework.Assert.assertEquals(Assert.java:207)
        at com.thoughtworks.qdox.EnumsModelTest.testAddEnumWithFieldAndConstructorsToModel(EnumsModelTest.java:162)

        Show
        Paul Hammant added a comment - Unfortunately the tests fail for the patch and unit test above : ------------------------------------------------------------------------------- Test set: com.thoughtworks.qdox.EnumsModelTest ------------------------------------------------------------------------------- Tests run: 6, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.031 sec <<< FAILURE! testAddEnumWithAnnotationToModel(com.thoughtworks.qdox.EnumsModelTest) Time elapsed: 0.008 sec <<< FAILURE! junit.framework.AssertionFailedError: expected:<1> but was:<0> at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.failNotEquals(Assert.java:282) at junit.framework.Assert.assertEquals(Assert.java:64) at junit.framework.Assert.assertEquals(Assert.java:201) at junit.framework.Assert.assertEquals(Assert.java:207) at com.thoughtworks.qdox.EnumsModelTest.testAddEnumWithAnnotationToModel(EnumsModelTest.java:113) testAddEnumWithFieldAndConstructorsToModel(com.thoughtworks.qdox.EnumsModelTest) Time elapsed: 0.002 sec <<< FAILURE! junit.framework.AssertionFailedError: expected:<1> but was:<0> at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.failNotEquals(Assert.java:282) at junit.framework.Assert.assertEquals(Assert.java:64) at junit.framework.Assert.assertEquals(Assert.java:201) at junit.framework.Assert.assertEquals(Assert.java:207) at com.thoughtworks.qdox.EnumsModelTest.testAddEnumWithFieldAndConstructorsToModel(EnumsModelTest.java:162)
        Andrew Mickish made changes -
        Attachment EnumsModelTest.java [ 32799 ]
        Hide
        Andrew Mickish added a comment -

        These tests verify that we can access enum fields in the model.
        This is a sequel to EnumsTest.java.

        Show
        Andrew Mickish added a comment - These tests verify that we can access enum fields in the model. This is a sequel to EnumsTest.java.
        Andrew Mickish made changes -
        Attachment EnumsModelTest.java [ 38048 ]
        Hide
        Andrew Mickish added a comment -

        The first version of EnumsModelTest.java that I submitted was too ambitious. It illustrated continued failure to associate annotations with enums.

        However, despite not being able to annotate enums, the rest of the test was successful.

        I have resubmitted a new version of EnumsModelTest.java that tests all the same things, except for the annotation of enums. It passes all tests.

        The parser.y.diff patch is unchanged.

        Show
        Andrew Mickish added a comment - The first version of EnumsModelTest.java that I submitted was too ambitious. It illustrated continued failure to associate annotations with enums. However, despite not being able to annotate enums, the rest of the test was successful. I have resubmitted a new version of EnumsModelTest.java that tests all the same things, except for the annotation of enums. It passes all tests. The parser.y.diff patch is unchanged.
        Andrew Mickish made changes -
        Attachment parser.y.diff [ 32673 ]
        Hide
        Andrew Mickish added a comment -

        By request, I have re-created the patch from the same directory as the pom.xml.

        Show
        Andrew Mickish added a comment - By request, I have re-created the patch from the same directory as the pom.xml.
        Andrew Mickish made changes -
        Attachment parser.y.diff [ 38049 ]
        Hide
        Mauro Talevi added a comment -

        Applied patch - which now passes all unit tests. Thanks!

        Show
        Mauro Talevi added a comment - Applied patch - which now passes all unit tests. Thanks!
        Mauro Talevi made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Hide
        Paul Hammant added a comment -

        yay!

        Show
        Paul Hammant added a comment - yay!

          People

          • Assignee:
            Unassigned
            Reporter:
            Joe Walnes
          • Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: