Source:
private void inspectFieldsAndMethods() { ServiceLoader<ChildEntityDefinition> childEntityDefinitions = ServiceLoader.load(ChildEntityDefinition.class, inspectedType.getClassLoader()); ArrayList<Member> entityIdMembers = new ArrayList<>(); ArrayList<Member> persistenceIdMembers = new ArrayList<>(); ArrayList<Member> aggregateVersionMembers = new ArrayList<>(); for (Class<?> type : handlerInspector.getAllHandlers().keySet()) { for (Field field : ReflectionUtils.fieldsOf(type)) { childEntityDefinitions.forEach(def -> def.createChildDefinition(field, this).ifPresent(child -> { children.add(child); child.commandHandlers().forEach(handler -> addHandler(allCommandHandlers, type, handler)); })); AnnotationUtils.findAnnotationAttributes(field, EntityId.class) .ifPresent(attributes -> entityIdMembers.add(field)); AnnotationUtils.findAnnotationAttributes(field, JAVAX_PERSISTENCE_ID) .ifPresent(attributes -> persistenceIdMembers.add(field)); AnnotationUtils.findAnnotationAttributes(field, AggregateVersion.class) .ifPresent(attributes -> aggregateVersionMembers.add(field)); } for (Method method : ReflectionUtils.methodsOf(type)) { childEntityDefinitions.forEach(def -> def.createChildDefinition(method, this).ifPresent(child -> { children.add(child); child.commandHandlers().forEach(handler -> addHandler(allCommandHandlers, type, handler)); })); AnnotationUtils.findAnnotationAttributes(method, EntityId.class) .ifPresent(attributes -> { assertValidValueProvidingMethod(method); entityIdMembers.add(method); }); AnnotationUtils.findAnnotationAttributes(method, JAVAX_PERSISTENCE_ID) .ifPresent(attributes -> { assertValidValueProvidingMethod(method); persistenceIdMembers.add(method); }); AnnotationUtils.findAnnotationAttributes(method, AggregateVersion.class) .ifPresent(attributes -> { assertValidValueProvidingMethod(method); aggregateVersionMembers.add(method); }); } } findIdentifierMember(distinct(entityIdMembers), distinct(persistenceIdMembers)) .ifPresent(this::setIdentifierAndRoutingKey); if (!aggregateVersionMembers.isEmpty()) { setVersionMember(aggregateVersionMembers.get(0)); } assertIdentifierValidity(identifierMember); }

Target:
private void inspectFieldsAndMethods() { ServiceLoader<ChildEntityDefinition> childEntityDefinitions = ServiceLoader.load(ChildEntityDefinition.class, inspectedType.getClassLoader()); List<Member> entityIdMembers = new ArrayList<>(); List<Member> persistenceIdMembers = new ArrayList<>(); List<Member> aggregateVersionMembers = new ArrayList<>(); for (Class<?> handlerType : handlerInspector.getAllHandlers().keySet()) { for (Field field : ReflectionUtils.fieldsOf(handlerType)) { createChildDefinitionsAndAddHandlers(childEntityDefinitions, handlerType, field); findAnnotationAttributes(field, EntityId.class).ifPresent(attributes -> entityIdMembers.add(field)); findAnnotationAttributes(field, JAVAX_PERSISTENCE_ID).ifPresent( attributes -> persistenceIdMembers.add(field) ); findAnnotationAttributes(field, AggregateVersion.class).ifPresent( attributes -> aggregateVersionMembers.add(field) ); } for (Method method : ReflectionUtils.methodsOf(handlerType)) { createChildDefinitionsAndAddHandlers(childEntityDefinitions, handlerType, method); findAnnotationAttributes(method, EntityId.class).ifPresent(attributes -> { assertValidValueProvidingMethod(method, EntityId.class.getSimpleName()); entityIdMembers.add(method); }); findAnnotationAttributes(method, JAVAX_PERSISTENCE_ID).ifPresent(attributes -> { assertValidValueProvidingMethod(method, JAVAX_PERSISTENCE_ID); persistenceIdMembers.add(method); }); findAnnotationAttributes(method, AggregateVersion.class).ifPresent(attributes -> { assertValidValueProvidingMethod(method, AggregateVersion.class.getSimpleName()); aggregateVersionMembers.add(method); }); } } findIdentifierMember(distinct(entityIdMembers), distinct(persistenceIdMembers)) .ifPresent(this::setIdentifierAndRoutingKey); setVersionMember(aggregateVersionMembers); assertIdentifierValidity(identifierMember); }