Eric Milles created GROOVY-8116:
-----------------------------------
Summary: 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)