private void buildFields() {
    for (Field field : clazz.getDeclaredFields()) {
      FieldMetadata metadata = field.getAnnotation(FieldMetadata.class);
      if (metadata == null) continue;

      FieldInfo fieldInfo = new FieldInfo();
      fieldInfo.setParent(spec);
      fieldInfo.setReflection(field);
      fieldInfo.setName(metadata.name());
      fieldInfo.setOrdinal(metadata.ordinal());
      fieldInfo.setLine(metadata.line());
      fieldInfo.setHasInitializer(metadata.initializer());
      spec.addField(fieldInfo);
    }

    spec.getFields().sort(comparingInt(FieldInfo::getOrdinal));
  }
Builds a SpecInfo from a Class instance.

@author Peter Niederwieser
spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java