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

Eric Milles commented on GROOVY-8116:
-------------------------------------

Interesting.  No mention of it here: 
https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9  Guess 
I'll need to update my static analysis rules to look for this case since final 
is not implicit but almost always intended.

> Property generation for enum is incorrect
> -----------------------------------------
>
>                 Key: GROOVY-8116
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8116
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>
> When creating a simple enum, I noticed that content assist was giving some 
> strange results.  It appears as though there is no special case handling for 
> properties in an enum.
> {code}
> enum Suit {
>   CLUBS(1),  SPADES(1), HEARTS(2), DIAMONDS(2);
>   int color
>   Suit(int color) {
>     this.color = color
>   }
> }
> {code}
> Since this is an enum, the final modifier on color should not be necessary -- 
> it is implied.  Java does not require it.  However the generated field does 
> not indicate final in the AST and a setter setColor is created.  I checked 
> this in the Groovy Console.
> {code}
> final public class Suit implements groovy.lang.GroovyObject extends 
> java.lang.Enum<Suit> { 
>     final public static Suit HEARTS 
>     final public static Suit DIAMONDS 
>     final public static Suit SPADES 
>     final public static Suit CLUBS 
>     private int color
>     ...
>     public int getColor() {
>     }
>     public void setColor(int value) {
>     }
> }
> {code}
> The method setColor is coming up in my IDE's content assist, since it is 
> generated by the Verifier.visitProperty method.  I think if the generated 
> fields are indicated as final for enums then Verifier will not generate 
> setters.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to