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);
}
}
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();
}
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();
}
Aggregations