Skip to content
Snippets Groups Projects
Commit 3b2c5591 authored by Patrick Rohr's avatar Patrick Rohr
Browse files

Add @Computed annotation to Struct

@Computed will ignore "computed" fields from struct parsing. Fields
cannot both be annotated by @Computed and @Field (though there
currently is no check for this).

Test: builds
Change-Id: I29fe506c5e3be4cc50fdaf3a07fc5e922111165b
parent dc6c70fd
No related branches found
No related tags found
No related merge requests found
......@@ -146,6 +146,14 @@ public class Struct {
int arraysize() default 0;
}
/**
* Indicates that this field contains a computed value and is ignored for the purposes of Struct
* parsing.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Computed {}
private static class FieldInfo {
@NonNull
public final Field annotation;
......@@ -533,6 +541,7 @@ public class Struct {
final FieldInfo[] annotationFields = new FieldInfo[getAnnotationFieldCount(clazz)];
for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {
if (Modifier.isStatic(field.getModifiers())) continue;
if (field.getAnnotation(Computed.class) != null) continue;
final Field annotation = field.getAnnotation(Field.class);
if (annotation == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment