diff --git a/value-fixture/src/org/immutables/fixture/annotation/An.java b/value-fixture/src/org/immutables/fixture/annotation/An.java index 7cca4c54b..38769ccf1 100644 --- a/value-fixture/src/org/immutables/fixture/annotation/An.java +++ b/value-fixture/src/org/immutables/fixture/annotation/An.java @@ -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[] cl() default { Integer.class }; + Class[] cl() default {Integer.class}; } diff --git a/value-processor/src/org/immutables/value/processor/Immutables.generator b/value-processor/src/org/immutables/value/processor/Immutables.generator index dffa1f74a..518757665 100644 --- a/value-processor/src/org/immutables/value/processor/Immutables.generator +++ b/value-processor/src/org/immutables/value/processor/Immutables.generator @@ -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] @@ -1139,6 +1141,8 @@ static { private static T cast(Object object) { return (T) object; } +[/if] +[/for] [/template] [template forwardingEnclosingFactoryMethods Type type] diff --git a/value-processor/src/org/immutables/value/processor/meta/ValueType.java b/value-processor/src/org/immutables/value/processor/meta/ValueType.java index 77f002078..4cbec97f4 100644 --- a/value-processor/src/org/immutables/value/processor/meta/ValueType.java +++ b/value-processor/src/org/immutables/value/processor/meta/ValueType.java @@ -544,6 +544,16 @@ public List getPrimitiveDefaultAttributes() { return builder.build(); } + public List getDefaultAttributes() { + ImmutableList.Builder builder = ImmutableList.builder(); + for (ValueAttribute attribute : getImplementedAttributes()) { + if (attribute.isGenerateDefault) { + builder.add(attribute); + } + } + return builder.build(); + } + public List getImplementedAttributes() { if (implementedAttributes == null) { implementedAttributes = attributes()