Search in sources :

Example 1 with ProtoField

use of com.google.api.codegen.config.ProtoField in project toolkit by googleapis.

the class JavaModelTypeNameConverter method getResourceNamePackage.

private static String getResourceNamePackage(FieldConfig fieldConfig) {
    String commonResourceName = fieldConfig.getResourceNameConfig().getCommonResourceName();
    if (commonResourceName != null) {
        // Common resource name is fully-qualified.
        int p = commonResourceName.lastIndexOf(".");
        if (p >= 0) {
            commonResourceName = commonResourceName.substring(0, p);
        }
        return commonResourceName;
    }
    ResourceNameType resourceNameType = fieldConfig.getResourceNameConfig().getResourceNameType();
    switch(resourceNameType) {
        case ANY:
            return "com.google.api.resourcenames";
        case FIXED:
        case SINGLE:
        case ONEOF:
            ProtoFile assignedProtoFile = fieldConfig.getResourceNameConfig().getAssignedProtoFile();
            if (assignedProtoFile == null) {
                FieldModel fm = fieldConfig.getField();
                assignedProtoFile = ((ProtoField) fm).getProtoField().getFile();
            }
            return getJavaPackage(assignedProtoFile);
        case NONE:
        default:
            throw new IllegalArgumentException("Unexpected ResourceNameType: " + resourceNameType);
    }
}
Also used : ProtoField(com.google.api.codegen.config.ProtoField) ProtoFile(com.google.api.tools.framework.model.ProtoFile) ResourceNameType(com.google.api.codegen.config.ResourceNameType) FieldModel(com.google.api.codegen.config.FieldModel)

Example 2 with ProtoField

use of com.google.api.codegen.config.ProtoField 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)

Example 3 with ProtoField

use of com.google.api.codegen.config.ProtoField in project toolkit by googleapis.

the class HeaderRequestParamTransformer method generateHeaderRequestParam.

private HeaderRequestParamView generateHeaderRequestParam(String headerRequestParam, MessageType inputMessageType, SurfaceNamer namer) {
    String[] fieldNameTokens = headerRequestParam.split("\\.");
    ImmutableList.Builder<String> gettersChain = ImmutableList.builder();
    MessageType subMessageType = inputMessageType;
    for (String fieldNameToken : fieldNameTokens) {
        Field matchingField = subMessageType.lookupField(fieldNameToken);
        if (matchingField == null) {
            throw new IllegalArgumentException("Unknown field name token '" + fieldNameToken + "' in header request param '" + headerRequestParam + "'");
        }
        String matchingFieldGetter = namer.getFieldGetFunctionName(new ProtoField(matchingField));
        gettersChain.add(matchingFieldGetter);
        if (matchingField.getType() != null && matchingField.getType().isMessage()) {
            subMessageType = matchingField.getType().getMessageType();
        }
    }
    HeaderRequestParamView.Builder headerParam = HeaderRequestParamView.newBuilder().fullyQualifiedName(headerRequestParam).gettersChain(gettersChain.build());
    return headerParam.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) MessageType(com.google.api.tools.framework.model.MessageType) HeaderRequestParamView(com.google.api.codegen.viewmodel.HeaderRequestParamView)

Aggregations

ProtoField (com.google.api.codegen.config.ProtoField)3 Field (com.google.api.tools.framework.model.Field)2 ImmutableList (com.google.common.collect.ImmutableList)2 FieldModel (com.google.api.codegen.config.FieldModel)1 ResourceNameType (com.google.api.codegen.config.ResourceNameType)1 HeaderRequestParamView (com.google.api.codegen.viewmodel.HeaderRequestParamView)1 HttpMethodSelectorView (com.google.api.codegen.viewmodel.HttpMethodSelectorView)1 FieldSelector (com.google.api.tools.framework.model.FieldSelector)1 MessageType (com.google.api.tools.framework.model.MessageType)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1