use of org.mapstruct.ap.internal.util.accessor.FieldElementAccessor in project mapstruct by mapstruct.
the class Type method getAlternativeTargetAccessors.
/**
* Alternative accessors could be a getter for a collection. By means of the
* {@link java.util.Collection#addAll(java.util.Collection) } this getter can still
* be used as targetAccessor. JAXB XJC tool generates such constructs.
*
* This method can be extended when new cases come along.
*
* @return an unmodifiable list of alternative target accessors.
*/
private List<Accessor> getAlternativeTargetAccessors() {
if (alternativeTargetAccessors != null) {
return alternativeTargetAccessors;
}
if (isRecord()) {
alternativeTargetAccessors = Collections.emptyList();
}
if (alternativeTargetAccessors == null) {
List<Accessor> result = new ArrayList<>();
List<Accessor> setterMethods = getSetters();
List<Accessor> readAccessors = new ArrayList<>(getPropertyReadAccessors().values());
// All the fields are also alternative accessors
readAccessors.addAll(filters.fieldsIn(getAllFields(), FieldElementAccessor::new));
// (assuming it is initialized)
for (Accessor readAccessor : readAccessors) {
if (isCollectionOrMapOrStream(readAccessor) && !correspondingSetterMethodExists(readAccessor, setterMethods)) {
result.add(readAccessor);
} else if (readAccessor.getAccessorType() == AccessorType.FIELD && !correspondingSetterMethodExists(readAccessor, setterMethods)) {
result.add(readAccessor);
}
}
alternativeTargetAccessors = Collections.unmodifiableList(result);
}
return alternativeTargetAccessors;
}
Aggregations