[ 
https://issues.apache.org/jira/browse/GROOVY-10886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17652335#comment-17652335
 ] 

Paul King commented on GROOVY-10886:
------------------------------------

Is that supposed to be "TaggableClasses" in your enum? When I change that to 
"ExampleEnum" your script seems to compile fine. I haven't used your startup 
code yet, just confirming the example worked first.
I tried:
{code}
@interface API {}

@API
enum ExampleEnum implements Serializable {
    @API
    ITEM1(1),
    @API
    ITEM2(2),
    @API
    ITEM3(3)

    Integer value

    ExampleEnum(Integer value) {
        this.value = value
    }
}

assert ExampleEnum.ITEM2.toString() == 'ITEM2'
assert ExampleEnum.ITEM2.value == 2
{code}
It ran fine on 2.5.20, 3.0.14 and 4.0.7.

> Error in Groovy enums parsing using GroovyRecognizer
> ----------------------------------------------------
>
>                 Key: GROOVY-10886
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10886
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, parser
>    Affects Versions: 2.5.15, 3.0.9
>         Environment: Java SDK 11
> Gradle 7.4.1
> Groovy 2.5.15 ( This is version of our project, but parser and all the 
> required entities are imported from gradle -> groovy 3.0.9)
>            Reporter: Dmitry
>            Priority: Blocker
>
> We recently upgraded to gradle version 7.4.1 and ran into problem with 
> parsing groovy enums.
> Environment:
>  * Java SDK 11
>  * Gradle 7.4.1
>  * Groovy 2.5.15 ( This is version of our project, but parser and all the 
> required entities are imported from gradle -> groovy 3.0.9)
> We try parse groovy enums using GroovyRecognizer. Groovy code:
> {code:java}
> SourceBuffer sourceBuffer = new SourceBuffer()
> UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(new 
> StringReader(‘ExampleEnum.groovy'), sourceBuffer)
> GroovyLexer lexer = new GroovyLexer(unicodeReader)
> unicodeReader.setLexer(lexer)
> parser = GroovyRecognizer.make(lexer)
> parser.setSourceBuffer(sourceBuffer)
> parser.compilationUnit()
> {code}
> Enum example:
> {code:java}
> @API
> public enum ExampleEnum implements Serializable {
>       @API
>       ITEM1(1),
>       @API
>       ITEM2(2),
>       @API
>       ITEM3(3);
>       
>       private Integer value;
>       public TaggableClasses(Integer value) {
>               this.value = value;
>       }
>       public Integer getValue() {
>               return this.value;
> }
> {code}
> {{.compilationUnit()}} method throws an exception "Parsing failed for 
> 'ExampleEnum.groovy' due to: unexpected token: 2"
> Token is value of ITEM2.
> Groovy class and interfaces parsing work correctly.
> My colleague created a test project that reproduces the issue.
> [https://github.com/KeyrisXdSnow/GradleReproducer.git]
> We discussed the issue with gradle team, they said it is not on their 
> (gradle) side. https://github.com/gradle/gradle/issues/20244
> Could you please advise how we can solve this problem?
> Thanks.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to