Skip to content

Commit

Permalink
Pass GenerationOptions down to Children
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpartsch committed Mar 21, 2022
1 parent 83e0226 commit 03705ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '1.4.0-alpha.23'
version = '1.4.0-alpha.24'

sourceCompatibility = "17"
targetCompatibility = "17"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.docutools.jocument.impl;

import com.docutools.jocument.CustomPlaceholderRegistry;
import com.docutools.jocument.GenerationOptions;
import com.docutools.jocument.GenerationOptionsBuilder;
import com.docutools.jocument.PlaceholderData;
import com.docutools.jocument.PlaceholderMapper;
import com.docutools.jocument.PlaceholderResolver;
Expand Down Expand Up @@ -60,7 +62,7 @@ public ReflectionResolver(Object value) {
}

public ReflectionResolver(Object value, CustomPlaceholderRegistry customPlaceholderRegistry) {
this(value, customPlaceholderRegistry, null);
this(value, customPlaceholderRegistry, GenerationOptionsBuilder.buildDefaultOptions(), null);
}

/**
Expand All @@ -70,10 +72,11 @@ public ReflectionResolver(Object value, CustomPlaceholderRegistry customPlacehol
* @param customPlaceholderRegistry The custom placeholder registry to check for custom placeholders
* @param parent The parent registry
*/
public ReflectionResolver(Object value, CustomPlaceholderRegistry customPlaceholderRegistry, PlaceholderResolver parent) {
public ReflectionResolver(Object value, CustomPlaceholderRegistry customPlaceholderRegistry, GenerationOptions options, PlaceholderResolver parent) {
this.bean = value;
this.customPlaceholderRegistry = customPlaceholderRegistry;
this.parent = parent;
setOptions(options);
}

protected static boolean isFieldAnnotatedWith(Class<?> clazz, String fieldName, Class<? extends Annotation> annotation) {
Expand Down Expand Up @@ -269,17 +272,17 @@ public Optional<PlaceholderData> doReflectiveResolve(String placeholderName, Loc
logger.debug("Placeholder {} resolved to collection", placeholderName);
List<PlaceholderResolver> list = collection.stream()
// cast is needed for `.toList()`
.map(object -> (PlaceholderResolver) new ReflectionResolver(object, customPlaceholderRegistry, this))
.map(object -> (PlaceholderResolver) new ReflectionResolver(object, customPlaceholderRegistry, options, this))
.toList();
return Optional.of(new IterablePlaceholderData(list, list.size()));
}
if (bean.equals(property)) {
logger.debug("Placeholder {} resolved to the parent object", placeholderName);
return Optional.of(new IterablePlaceholderData(List.of(new ReflectionResolver(bean, customPlaceholderRegistry, this)), 1));
return Optional.of(new IterablePlaceholderData(List.of(new ReflectionResolver(bean, customPlaceholderRegistry, options, this)), 1));
} else {
var value = getBeanProperty(placeholderName);
logger.debug("Resolved placeholder {} to the bean property {}", placeholderName, value);
return Optional.of(new IterablePlaceholderData(List.of(new ReflectionResolver(value, customPlaceholderRegistry, this)), 1));
return Optional.of(new IterablePlaceholderData(List.of(new ReflectionResolver(value, customPlaceholderRegistry, options, this)), 1));
}
}
} catch (NoSuchMethodException | IllegalArgumentException e) {
Expand Down

0 comments on commit 03705ec

Please sign in to comment.