Skip to content

Commit

Permalink
Exclude Groovy autogenerated MAX_VALUE and MIN_VALUE from enum (#6763)
Browse files Browse the repository at this point in the history
Fixes #6760
  • Loading branch information
ilopmar authored and yawkat committed Jan 21, 2022
1 parent 59c59d6 commit a14c80f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -55,7 +55,11 @@ class GroovyEnumElement extends GroovyClassElement implements EnumElement {
@Override
public List<String> values() {
ClassNode cn = (ClassNode) getNativeType();
List<String> values = cn.getFields().stream().filter(fn -> fn.getType().equals(cn)).map(FieldNode::getName).collect(Collectors.toList());
List<String> values = cn.getFields().stream()
.filter((fn -> !fn.getName().equals("MAX_VALUE") && !fn.getName().equals("MIN_VALUE")))
.filter(fn -> fn.getType().equals(cn))
.map(FieldNode::getName)
.collect(Collectors.toList());
return Collections.unmodifiableList(values);
}

Expand Down
Expand Up @@ -35,4 +35,18 @@ class Foo {
expect:
element.getEnclosedElement(ElementQuery.of(ClassElement.class)).get().getPrimaryConstructor().get().getDeclaringType().isEnum()
}

void "exclude Groovy autogenerated MAX_VALUE and MIN_VALUE"() {
given:
def element = (GroovyEnumElement) buildClassElement("""
package test
enum MyEnum {
A, B
}
""")
expect:
!element.values().contains('MAX_VALUE')
!element.values().contains('MIN_VALUE')
}
}

0 comments on commit a14c80f

Please sign in to comment.