com.sap.cds.reflect.impl.CdsActionBuilder Maven / Gradle / Ivy
/*********************************************************************
* (C) 2020 SAP SE or an SAP affiliate company. All rights reserved. *
*********************************************************************/
package com.sap.cds.reflect.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import com.sap.cds.reflect.CdsAction;
import com.sap.cds.reflect.CdsAnnotation;
import com.sap.cds.reflect.CdsParameter;
import com.sap.cds.reflect.CdsType;
public class CdsActionBuilder extends CdsDefinitionBuilder {
private final List parameters = new ArrayList<>(); // ordered
private CdsTypeBuilder> returnType = null; // optional
private CdsActionImpl impl = null;
public CdsActionBuilder(List> annotations, String qualifiedName) {
super(annotations, qualifiedName);
}
@Override
public CdsAction build() {
if (impl == null) {
impl = new CdsActionImpl(annotations, qualifiedName);
parameters.stream().filter(pb -> !pb.toBeIgnored(qualifiedName + "." + pb.getName()))
.forEach(p -> impl.parameters.add(p.build()));
if (returnType != null) {
impl.returnType = this.returnType.build();
}
}
return impl;
}
void addParameter(CdsParameterBuilder p) {
this.parameters.add(p);
}
void addParameters(List params) {
params.forEach(this::addParameter);
}
void setReturnType(CdsTypeBuilder> returnType) {
this.returnType = returnType;
}
private static class CdsActionImpl extends CdsDefinitionImpl implements CdsAction {
private final List parameters = new ArrayList<>(); // ordered
private CdsType returnType; // optional
private CdsActionImpl(Collection> annotations, String qualifiedName) {
super(annotations, qualifiedName);
}
@Override
public Stream parameters() {
return parameters.stream();
}
@Override
public Optional returnType() {
return Optional.ofNullable(returnType);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy