Search in sources :

Example 1 with EnumType

use of com.google.api.tools.framework.model.EnumType 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);
}
Also used : EnumType(com.google.api.tools.framework.model.EnumType) Model(com.google.api.tools.framework.model.Model) ProtoContainerElement(com.google.api.tools.framework.model.ProtoContainerElement) TestDataLocator(com.google.api.tools.framework.model.testing.TestDataLocator) MessageType(com.google.api.tools.framework.model.MessageType)

Example 2 with EnumType

use of com.google.api.tools.framework.model.EnumType in project toolkit by googleapis.

the class GrpcElementDocTransformer method generateEnumDocs.

public List<GrpcElementDocView> generateEnumDocs(ModelTypeTable typeTable, SurfaceNamer namer, ProtoContainerElement containerElement) {
    ImmutableList.Builder<GrpcElementDocView> enumDocs = ImmutableList.builder();
    for (EnumType enumElement : containerElement.getEnums()) {
        if (!enumElement.isReachable()) {
            continue;
        }
        GrpcEnumDocView.Builder doc = GrpcEnumDocView.newBuilder();
        doc.name(namer.getEnumTypeName(typeTable, enumElement));
        doc.lines(namer.getDocLines(GapicParser.getDocString(enumElement)));
        doc.values(generateEnumValueDocs(namer, enumElement));
        doc.packageName(enumElement.getFile().getFullName());
        enumDocs.add(doc.build());
    }
    return enumDocs.build();
}
Also used : GrpcEnumDocView(com.google.api.codegen.viewmodel.GrpcEnumDocView) ImmutableList(com.google.common.collect.ImmutableList) EnumType(com.google.api.tools.framework.model.EnumType) GrpcElementDocView(com.google.api.codegen.viewmodel.GrpcElementDocView)

Aggregations

EnumType (com.google.api.tools.framework.model.EnumType)2 GrpcElementDocView (com.google.api.codegen.viewmodel.GrpcElementDocView)1 GrpcEnumDocView (com.google.api.codegen.viewmodel.GrpcEnumDocView)1 MessageType (com.google.api.tools.framework.model.MessageType)1 Model (com.google.api.tools.framework.model.Model)1 ProtoContainerElement (com.google.api.tools.framework.model.ProtoContainerElement)1 TestDataLocator (com.google.api.tools.framework.model.testing.TestDataLocator)1 ImmutableList (com.google.common.collect.ImmutableList)1