use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class NodeJSGapicSurfaceDocTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
Model model = ((ProtoApiModel) apiModel).getProtoModel();
ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
for (ProtoFile file : new ProtoFileView().getElementIterable(model)) {
surfaceDocs.add(generateDoc(file, productConfig));
}
return surfaceDocs.build();
}
use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class PhpModelTypeNameConverter method getTypeNameString.
/**
* This function determines the type name as follows: If the proto type name is in TYPE_NAME_MAP,
* return that value. Else, split on ".", prepend '\' and capitalize each component of the
* namespace except the message name
*/
private static String getTypeNameString(ProtoElement elem) {
String fullName = elem.getFullName();
if (TYPE_NAME_MAP.containsKey(fullName)) {
return TYPE_NAME_MAP.get(fullName);
}
String[] components = fullName.split("\\.");
String shortName = components[components.length - 1];
StringBuilder builder = new StringBuilder();
ProtoElement parentElem = elem.getParent();
if (parentElem != null && parentElem instanceof ProtoFile) {
ProtoFile protoFile = (ProtoFile) parentElem;
String namespace = protoFile.getProto().getOptions().getPhpNamespace();
if (Strings.isNullOrEmpty(namespace)) {
for (int index = 0; index < components.length - 1; index++) {
builder.append('\\').append(components[index].substring(0, 1).toUpperCase()).append(components[index].substring(1));
}
} else {
builder.append('\\').append(CharMatcher.is('\\').trimFrom(namespace));
}
}
builder.append('\\').append(shortName);
return builder.toString();
}
use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class RubyGapicSurfaceDocTransformer method transform.
@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
for (ProtoFile file : new ProtoFileView().getElementIterable(((ProtoApiModel) model).getProtoModel())) {
surfaceDocs.add(generateDoc(file, productConfig));
}
surfaceDocs.add(generateOverview(model, productConfig));
return surfaceDocs.build();
}
use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class InitCodeTransformer method createInitValueView.
private InitValueView createInitValueView(MethodContext context, FieldConfig fieldConfig, SurfaceNamer namer, ImportTypeTable typeTable, InitCodeNode item, boolean convertToString) {
SingleResourceNameConfig singleResourceNameConfig;
switch(fieldConfig.getResourceNameType()) {
case ANY:
singleResourceNameConfig = Iterables.get(context.getProductConfig().getSingleResourceNameConfigs(), 0);
InterfaceModel interfaceModel = context.getInterfaceModel();
if (interfaceModel instanceof ProtoInterfaceModel) {
ProtoFile protoFile = ((ProtoInterfaceModel) interfaceModel).getInterface().getFile();
singleResourceNameConfig = singleResourceNameConfig.toBuilder().setAssignedProtoFile(protoFile).build();
}
FieldConfig anyResourceNameFieldConfig = fieldConfig.withResourceNameConfig(singleResourceNameConfig);
return createResourceNameInitValueView(context, anyResourceNameFieldConfig, item).convertToString(convertToString).build();
case FIXED:
throw new UnsupportedOperationException("entity name invalid");
case ONEOF:
return createResourceNameOneofInitValueView(context, fieldConfig, item, convertToString);
case SINGLE:
return createResourceNameInitValueView(context, fieldConfig, item).convertToString(convertToString).build();
case NONE:
// Fall-through
default:
throw new UnsupportedOperationException("unexpected entity name type '" + fieldConfig.getResourceNameType() + "'");
}
}
use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.
the class ProtoFiles method getFilesForMessage.
private static Set<ProtoFile> getFilesForMessage(MessageType messageType, boolean messageOnly) {
Set<ProtoFile> files = newFileSet();
files.add(messageType.getFile());
if (messageOnly) {
return files;
}
for (Field field : messageType.getFields()) {
TypeRef type = field.getType();
if (type.isMessage()) {
files.addAll(getFilesForMessage(type.getMessageType(), type.isCyclic()));
}
}
return files;
}
Aggregations