Search in sources :

Example 1 with HttpMethodSelectorView

use of com.google.api.codegen.viewmodel.HttpMethodSelectorView in project toolkit by googleapis.

the class ApiCallableTransformer method populateMethodSelectors.

private List<HttpMethodSelectorView> populateMethodSelectors(SurfaceNamer namer, List<FieldSelector> selectors) {
    ImmutableList.Builder<HttpMethodSelectorView> paramSelectors = ImmutableList.builder();
    for (FieldSelector fs : selectors) {
        HttpMethodSelectorView.Builder methodSelectorView = HttpMethodSelectorView.newBuilder();
        methodSelectorView.fullyQualifiedName(Name.anyLower(fs.toString()).toLowerCamel());
        ImmutableList.Builder<String> gettersChain = ImmutableList.builder();
        ImmutableList.Builder<String> gettersHasChain = ImmutableList.builder();
        ProtoField pf = null;
        for (Field f : fs.getFields()) {
            if (pf != null) {
                gettersHasChain.add(namer.getFieldGetFunctionName(pf));
            }
            pf = new ProtoField(f);
            gettersChain.add(namer.getFieldGetFunctionName(pf));
        }
        methodSelectorView.gettersChain(gettersChain.build());
        if (pf != null && pf.getProtoField().getProto().getProto3Optional()) {
            gettersHasChain.add(namer.getFieldHasFunctionName(pf));
            methodSelectorView.gettersHasChain(gettersHasChain.build());
        } else {
            methodSelectorView.gettersHasChain(ImmutableList.of());
        }
        paramSelectors.add(methodSelectorView.build());
    }
    return paramSelectors.build();
}
Also used : Field(com.google.api.tools.framework.model.Field) ProtoField(com.google.api.codegen.config.ProtoField) ProtoField(com.google.api.codegen.config.ProtoField) ImmutableList(com.google.common.collect.ImmutableList) HttpMethodSelectorView(com.google.api.codegen.viewmodel.HttpMethodSelectorView) FieldSelector(com.google.api.tools.framework.model.FieldSelector)

Aggregations

ProtoField (com.google.api.codegen.config.ProtoField)1 HttpMethodSelectorView (com.google.api.codegen.viewmodel.HttpMethodSelectorView)1 Field (com.google.api.tools.framework.model.Field)1 FieldSelector (com.google.api.tools.framework.model.FieldSelector)1 ImmutableList (com.google.common.collect.ImmutableList)1