com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Label Java Examples
The following examples show how to use
com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Label.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrintMessageFile.java From saluki with Apache License 2.0 | 5 votes |
@Override protected List<String> collectFileData() { String sourePackageName = super.getSourcePackageName(); String className = super.getClassName(); String packageName = sourePackageName.toLowerCase(); List<String> fileData = Lists.newArrayList(); fileData.add("package " + packageName + ";"); fileData.add(System.getProperty("line.separator")); fileData.add("import io.github.saluki.serializer.ProtobufAttribute;"); fileData.add("import io.github.saluki.serializer.ProtobufEntity;"); fileData.add(System.getProperty("line.separator")); fileData.add("@ProtobufEntity(" + sourePackageName + "." + className + ".class)"); fileData.add("public class " + className + "{"); for (int i = 0; i < messageFields.size(); i++) { FieldDescriptorProto messageField = messageFields.get(i); String javaType = findJavaType(packageName, sourceMessageDesc, messageField); if (messageField.getLabel() == Label.LABEL_REPEATED && javaType != null) { if (!javaType.contains("java.util.Map")) { javaType = "java.util.ArrayList<" + javaType + ">"; } } String fieldName = messageField.getName(); fileData.add(System.getProperty("line.separator")); fileData.add(" @ProtobufAttribute"); fileData.add(" private " + javaType + " " + fieldName + ";"); fileData.add(System.getProperty("line.separator")); fileData.add(" public " + javaType + " get" + captureName(fieldName) + "(){"); fileData.add(" return this." + fieldName + ";"); fileData.add("}"); fileData.add(System.getProperty("line.separator")); fileData.add( " public void set" + captureName(fieldName) + "(" + javaType + " " + fieldName + "){"); fileData.add(" this." + fieldName + "=" + fieldName + ";"); fileData.add("}"); fileData.add(System.getProperty("line.separator")); } fileData.add("}"); return fileData; }
Example #2
Source File: TypesBuilderFromDescriptor.java From api-compiler with Apache License 2.0 | 5 votes |
/** * TODO (guptasu): only needed to create hard coded Types (Struct, ListValue, and Value). Check * if this can be removed. Create the Protobuf.Type instance from descriptorProto. */ private static Type createType(String typeName, DescriptorProto descriptorProto, String fileName) { Type.Builder coreTypeBuilder = Type.newBuilder().setName(typeName); int count = 1; for (FieldDescriptorProto fieldProto : descriptorProto.getFieldList()) { Field.Kind fieldKind = Field.Kind.valueOf(fieldProto.getType().getNumber()); Cardinality cardinality = Cardinality.CARDINALITY_OPTIONAL; if (fieldProto.getLabel() == Label.LABEL_REPEATED) { cardinality = Cardinality.CARDINALITY_REPEATED; } Field.Builder coreFieldBuilder = Field .newBuilder() .setName(fieldProto.getName()) .setNumber(count++) .setKind(fieldKind) .setCardinality(cardinality); if (fieldKind == Kind.TYPE_MESSAGE || fieldKind == Kind.TYPE_ENUM) { String typeFullName = fieldProto.getTypeName().startsWith(".") ? fieldProto.getTypeName().substring(1) : fieldProto.getTypeName(); coreFieldBuilder.setTypeUrl(TYPE_SERVICE_BASE_URL + typeFullName); } coreTypeBuilder.addFields(coreFieldBuilder.build()); } coreTypeBuilder.setSourceContext(SourceContext.newBuilder().setFileName(fileName)); coreTypeBuilder.setSyntax(Syntax.SYNTAX_PROTO3); return coreTypeBuilder.build(); }
Example #3
Source File: AISToProtobuf.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
protected void addColumn(Column column) { String fieldName = uniqueIdent(ident(column.getName(), false), fieldNames); fieldBuilder = messageBuilder.addFieldBuilder(); fieldBuilder.setName(fieldName); fieldBuilder.setLabel(Label.LABEL_OPTIONAL); FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder(); ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder(); if (!fieldName.equals(column.getName())) { columnOptions.setName(column.getName()); } columnOptions.setSqlType(column.getTypeDescription().toUpperCase()); columnOptions.setUuid(column.getUuid().toString()); priorField = null; if (priorMessage != null) { for (FieldDescriptorProto field : priorMessage.getFieldList()) { FieldOptions options = field.getOptions(); if ((options != null) && (options.hasExtension(ColumnOptions.fdbsql))) { ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql); if (coptions.getUuid().equals(columnOptions.getUuid())) { priorField = field; break; } } } } setColumnType(column, columnOptions); setFieldNumber(); fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build()); fieldBuilder.setOptions(fieldBuilderOptions); if (column.getNullable() && ((column.getDefaultValue() != null) || (column.getDefaultFunction() != null))) { addNullForField(column.getName(), fieldBuilder.getNumber()); } }
Example #4
Source File: AISToProtobuf.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
protected void addNullForField(String columnName, int forField) { String fieldName = uniqueIdent("_" + ident(columnName, false) + "_is_null", fieldNames); fieldBuilder = messageBuilder.addFieldBuilder(); fieldBuilder.setName(fieldName); fieldBuilder.setType(Type.TYPE_BOOL); fieldBuilder.setLabel(Label.LABEL_OPTIONAL); FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder(); ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder(); columnOptions.setNullForField(forField); priorField = null; if (priorMessage != null) { for (FieldDescriptorProto field : priorMessage.getFieldList()) { FieldOptions options = field.getOptions(); if ((options != null) && (options.hasExtension(ColumnOptions.fdbsql))) { ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql); if (coptions.hasNullForField() && (coptions.getNullForField() == forField)) { priorField = field; break; } } } } setFieldNumber(); fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build()); fieldBuilder.setOptions(fieldBuilderOptions); }
Example #5
Source File: AISToProtobuf.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
protected void addChildTable(Table table) { String fieldName = uniqueIdent(ident(table.getName().getTableName(), false), fieldNames); fieldBuilder = messageBuilder.addFieldBuilder(); fieldBuilder.setName(fieldName); fieldBuilder.setLabel(Label.LABEL_REPEATED); fieldBuilder.setType(Type.TYPE_MESSAGE); fieldBuilder.setTypeName(tableMessageNames.get(table)); FieldOptions.Builder fieldBuilderOptions = FieldOptions.newBuilder(); ColumnOptions.Builder columnOptions = ColumnOptions.newBuilder(); columnOptions.setUuid(table.getUuid().toString()); priorField = null; if (priorMessage != null) { for (FieldDescriptorProto field : priorMessage.getFieldList()) { FieldOptions options = field.getOptions(); if ((options != null) && (options.hasExtension(ColumnOptions.fdbsql))) { ColumnOptions coptions = options.getExtension(ColumnOptions.fdbsql); if (coptions.getUuid().equals(columnOptions.getUuid())) { priorField = field; break; } } } } setFieldNumber(); fieldBuilderOptions.setExtension(ColumnOptions.fdbsql, columnOptions.build()); fieldBuilder.setOptions(fieldBuilderOptions); }
Example #6
Source File: DescriptorGenerator.java From api-compiler with Apache License 2.0 | 4 votes |
private Label toLabel(Cardinality cardinality) { return Label.valueOf(cardinality.getNumber()); }