use of com.vaadin.flow.templatemodel.Include in project flow by vaadin.
the class TemplateModelUtil method getFilterFromIncludeExclude.
/**
* Gets a filter based on any <code>@Include</code> and/or
* <code>@Exclude</code> annotations present on the given method.
*
* @param method
* the method to check
* @return a filter based on the given annotations
*/
public static Predicate<String> getFilterFromIncludeExclude(Method method) {
Exclude exclude = method.getAnnotation(Exclude.class);
Include include = method.getAnnotation(Include.class);
Set<String> toExclude = new HashSet<>();
Set<String> toInclude = new HashSet<>();
if (exclude != null) {
Collections.addAll(toExclude, exclude.value());
}
if (include != null) {
for (String includeProperty : include.value()) {
toInclude.add(includeProperty);
// If "some.bean.value" is included,
// we should automatically include "some" and "some.bean"
String property = includeProperty;
int dotLocation = property.lastIndexOf('.');
while (dotLocation != -1) {
property = property.substring(0, dotLocation);
toInclude.add(property);
dotLocation = property.lastIndexOf('.');
}
}
}
return propertyName -> {
if (toExclude.contains(propertyName)) {
return false;
}
if (!toInclude.isEmpty()) {
return toInclude.contains(propertyName);
}
return true;
};
}
Aggregations