Skip to content

Commit

Permalink
omit empty block with initialization of annotation default values
Browse files Browse the repository at this point in the history
  • Loading branch information
elucash committed Dec 30, 2014
1 parent 46aa1b5 commit 798a7a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions value-fixture/src/org/immutables/fixture/annotation/An.java
Expand Up @@ -19,17 +19,23 @@
import java.lang.annotation.RetentionPolicy;
import org.immutables.value.Value;

@interface NoDefault {
int value();

String otherValue();
}

@Retention(RetentionPolicy.RUNTIME)
@Value.Immutable
@interface An {
@Value.Parameter
int value();

Be[] bees() default { @Be, @Be };
Be[] bees() default {@Be, @Be};
}

@Retention(RetentionPolicy.SOURCE)
@Value.Immutable
@interface Be {
Class<? extends Number>[] cl() default { Integer.class };
Class<? extends Number>[] cl() default {Integer.class};
}
Expand Up @@ -1120,13 +1120,15 @@ public [v.implementationType] [if v.boolean]is[else]get[/if][toUpper v.name]() {
[/template]

[template defaultAnnotationValues Type type]
[for a in type.implementedAttributes if a.generateDefault]
[for defaults = type.defaultAttributes]
[if defaults]
[for a in defaults]
private static final [a.type] DEFAULT_VALUE_[toConstant a.name];
[/for]

static {
try {
[for a in type.implementedAttributes if a.generateDefault]
[for a in defaults]
DEFAULT_VALUE_[toConstant a.name] =
cast([type.typeAbstract.relative].class.getDeclaredMethod("[a.name]").getDefaultValue());
[/for]
Expand All @@ -1139,6 +1141,8 @@ static {
private static <T> T cast(Object object) {
return (T) object;
}
[/if]
[/for]
[/template]

[template forwardingEnclosingFactoryMethods Type type]
Expand Down
Expand Up @@ -544,6 +544,16 @@ public List<ValueAttribute> getPrimitiveDefaultAttributes() {
return builder.build();
}

public List<ValueAttribute> getDefaultAttributes() {
ImmutableList.Builder<ValueAttribute> builder = ImmutableList.builder();
for (ValueAttribute attribute : getImplementedAttributes()) {
if (attribute.isGenerateDefault) {
builder.add(attribute);
}
}
return builder.build();
}

public List<ValueAttribute> getImplementedAttributes() {
if (implementedAttributes == null) {
implementedAttributes = attributes()
Expand Down

0 comments on commit 798a7a7

Please sign in to comment.