class ReferringCodeGenerator {

    String generateEndingReferringBodyWhenChaining(ReferMetadata referMetadata) {
        Type referType = referMetadata.getRefType();
        String ref = referMetadata.getRef();
        return isCollection(referType) && referMetadata.getPathPart().contains("[*]")
                ? generateEndingLoop(getCollectionGeneric(referType).getTypeName(), ref)
                : generateEndingAssignment(getRawType(referType).getTypeName(), ref, "result.add(%s(%s));");
    }

}