use of com.google.api.tools.framework.model.ProtoContainerElement in project toolkit by googleapis.
the class ModelTypeNameConverterTestUtil method getTestType.
public static TypeRef getTestType(TemporaryFolder tempDir, String... path) {
String fileName = "library.proto";
TestDataLocator locator = TestDataLocator.create(CodegenTestUtil.class);
locator.addTestDataSource(CodegenTestUtil.class, "testsrc");
Model model = CodegenTestUtil.readModel(locator, tempDir, new String[] { fileName }, new String[] { "library.yaml" });
ProtoContainerElement container = getElementWithName(model.getFiles(), fileName);
if (container == null) {
throw new IllegalStateException("file not found: " + fileName);
}
for (int i = 0; i < path.length; i++) {
String pathElement = path[i];
MessageType messageType = getElementWithName(container.getMessages(), pathElement);
EnumType enumType = getElementWithName(container.getEnums(), pathElement);
if (messageType != null) {
container = messageType;
} else if (enumType != null && i == path.length - 1) {
return TypeRef.of(enumType);
} else if (enumType != null) {
throw new IllegalStateException("enum type cannot contain further elements: " + enumType);
} else {
throw new IllegalStateException("element not found: " + pathElement);
}
}
if (container instanceof MessageType) {
return TypeRef.of((MessageType) container);
}
throw new IllegalStateException("not a type: " + container);
}
Aggregations