@Override public TypeModel makeOptional() { return create(getProtoType().makeOptional()); }
@Override public FieldModel getField(String key) { for (FieldModel field : getFields()) { if (field.getSimpleName().equals(key)) { return field; } } return null; }
@Override public String getFullNameForElementType(TypeModel type) { return typeFormatter.getFullNameForElementType(((ProtoTypeRef) type).getProtoType()); }
private static String getEnumTypeClassName(MethodContext context, TypeModel type) { checkArgument( type instanceof ProtoTypeRef, "%s: type %s is not a proto type", context.getMethodModel().getSimpleName(), type); checkArgument( ((ProtoTypeRef) type).isEnum(), "%s: type %s is not an enum type", context.getMethodModel().getSimpleName(), type); TypeRef protoType = ((ProtoTypeRef) type).getProtoType(); ProtoElement t = protoType.getEnumType(); List<String> names = new ArrayList<>(); while (!(t instanceof ProtoFile)) { names.add(t.getSimpleName()); t = t.getParent(); } names.add("enums"); StringBuilder builder = new StringBuilder(); for (String name : Lists.reverse(names)) { builder.append(name).append("."); } return builder.substring(0, builder.length() - 1); } }
@Override public String getEnumValue(TypeModel type, String value) { return getEnumValue(((ProtoTypeRef) type).getProtoType(), value); }
public ProtoField(Field protoField) { Preconditions.checkNotNull(protoField); this.protoField = protoField; this.protoTypeRef = ProtoTypeRef.create(protoField.getType()); }
@Override public boolean isEnum() { return getProtoType().isEnum(); }
@Override public TypeModel getMapKeyType() { return create(getProtoType().getMapKeyField().getType()); }
@Test public void testScopeTablePut() { TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string")); assertThat(parent.put("str", stringTypeModel, "String")).isTrue(); }
@Override public boolean isDoubleType() { return getProtoType().getKind() == DescriptorProtos.FieldDescriptorProto.Type.TYPE_DOUBLE; }
@Override public TypeModel getMapValueType() { return create(getProtoType().getMapValueField().getType()); }
@Test public void testScopeTablePutFail() { TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string")); assertThat(parent.put("str", stringTypeModel, "String")).isTrue(); assertThat(parent.put("str", stringTypeModel, "String")).isFalse(); }
@Override public boolean isRepeated() { return getProtoType().isRepeated(); }
private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodConfig methodConfig) { String returnTypeDoc = ""; if (methodConfig.isPageStreaming()) { returnTypeDoc = "Array of "; FieldModel resourcesType = methodConfig.getPageStreaming().getResourcesField(); if (resourcesType.isMessage()) { returnTypeDoc += commentReformatter.getLinkedElementName( ((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType()); } else if (resourcesType.isEnum()) { returnTypeDoc += commentReformatter.getLinkedElementName( ((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType()); } else { // Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter. returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase(); } } else if (methodConfig.isLongRunningOperation()) { returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object"; } else { returnTypeDoc = getTypeNameDoc(typeTable, ProtoTypeRef.create(methodConfig.getMethod().getOutputType())); } return returnTypeDoc; }
/** Apply {@code sampleParamConfig} to a resource path entity. */ private void resolveSampleParamConfig( InitCodeContext context, String entityName, SampleParameterConfig sampleParamConfig) { Preconditions.checkArgument( !sampleParamConfig.readFromFile(), "cannot configure a resource name entity to read from file"); if (!sampleParamConfig.isSampleArgument()) { return; } Name entityIdentifier = identifierFromSampleArgumentName(context, sampleParamConfig.sampleArgumentName()); addChildNodeForSampleParameter( context, entityName, ProtoTypeRef.create(TypeRef.fromPrimitiveName("string")), entityIdentifier, InitValueConfig.createWithValue( initValueConfig.getResourceNameBindingValues().get(entityName))); initValueConfig = initValueConfig.withUpdatedInitialCollectionValue( entityName, InitValue.createVariable(entityIdentifier.toLowerUnderscore())); }
@Override public boolean isPrimitive() { return getProtoType().isPrimitive(); }
.getTypeTable() .renderPrimitiveValue( ProtoTypeRef.create(TypeRef.fromPrimitiveName("string")), initValue.getValue()); break;
@Override public boolean isEmptyType() { return ServiceMessages.s_isEmptyType(getProtoType()); }
@Test public void testScopeTableGetTypeModel() { TypeModel stringTypeModel = ProtoTypeRef.create(TypeRef.fromPrimitiveName("string")); assertThat(parent.put("str", stringTypeModel, "String")).isTrue(); assertThat(parent.getTypeModel("str")).isEqualTo(stringTypeModel); assertThat(parent.getTypeName("str")).isEqualTo("String"); assertThat(parent.getTypeModel("book")).isNull(); assertThat(parent.getTypeName("book")).isNull(); }