Java Code Examples for com.google.protobuf.DescriptorProtos.FieldDescriptorProto#Builder
The following examples show how to use
com.google.protobuf.DescriptorProtos.FieldDescriptorProto#Builder .
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: DescriptorGenerator.java From api-compiler with Apache License 2.0 | 5 votes |
private FieldDescriptorProto generateField(Field field) { FieldDescriptorProto.Builder builder = FieldDescriptorProto.newBuilder(); builder.setName(getFieldName(field)); builder.setNumber(field.getNumber()); builder.setLabel(toLabel(field.getCardinality())); builder.setType(toType(field.getKind())); if (field.getKind() == Kind.TYPE_ENUM || field.getKind() == Kind.TYPE_MESSAGE || field.getKind() == Kind.TYPE_GROUP) { builder.setTypeName(getTypeName(field.getTypeUrl())); } // NOTE: extendee not supported // NOTE: default_value not supported if (field.getOneofIndex() != 0) { // Index in the containing type's oneof_decl is zero-based. // Index in google.protobuf.type.Field.oneof_index is one-based. builder.setOneofIndex(field.getOneofIndex() - 1); } if (!Strings.isNullOrEmpty(field.getDefaultValue())) { builder.setDefaultValue(field.getDefaultValue()); } FieldOptions options = getFieldOptions(field); if (!options.equals(FieldOptions.getDefaultInstance())) { builder.setOptions(options); } return builder.build(); }
Example 2
Source File: BuilderVisitor.java From api-compiler with Apache License 2.0 | 5 votes |
protected void addFieldToMessageAncestor( int generationsToSkip, FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) { BuilderVisitorNodeInfo ancestorInfo = getAncestorInfo(generationsToSkip); if (ancestorInfo instanceof MessageNodeInfo) { ((MessageNodeInfo) ancestorInfo).addNewField(fieldDesc, location); setModified(true); } else { throw new RuntimeException( String.format( "Tried to add a field to a %s, but can only add to %s", ancestorInfo.node().getClass(), DescriptorProto.Builder.class)); } }
Example 3
Source File: MessageDefinition.java From protobuf-dynamic with Apache License 2.0 | 5 votes |
private void addField(FieldDescriptorProto.Label label, String type, String name, int num, String defaultVal, OneofBuilder oneofBuilder) { FieldDescriptorProto.Builder fieldBuilder = FieldDescriptorProto.newBuilder(); fieldBuilder.setLabel(label); FieldDescriptorProto.Type primType = sTypeMap.get(type); if (primType != null) fieldBuilder.setType(primType); else fieldBuilder.setTypeName(type); fieldBuilder.setName(name).setNumber(num); if (defaultVal != null) fieldBuilder.setDefaultValue(defaultVal); if (oneofBuilder != null) fieldBuilder.setOneofIndex(oneofBuilder.getIdx()); mMsgTypeBuilder.addField(fieldBuilder.build()); }
Example 4
Source File: BuilderVisitor.java From api-compiler with Apache License 2.0 | 4 votes |
protected void addFieldToMessageParent(FieldDescriptorProto.Builder fieldDesc) { addFieldToMessageAncestor(0, fieldDesc, null); }
Example 5
Source File: BuilderVisitor.java From api-compiler with Apache License 2.0 | 4 votes |
protected void addFieldToMessageParent( FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) { addFieldToMessageAncestor(0, fieldDesc, location); }
Example 6
Source File: BuilderVisitor.java From api-compiler with Apache License 2.0 | 4 votes |
protected void addFieldToMessageAncestor( int generationsToSkip, FieldDescriptorProto.Builder fieldDesc) { addFieldToMessageAncestor(generationsToSkip, fieldDesc, null); }
Example 7
Source File: BuilderVisitor.java From api-compiler with Apache License 2.0 | 4 votes |
@Accepts protected void accept(FieldDescriptorProto.Builder field) { pushParent(BuilderVisitorNodeInfo.create(field, currentFile)); visit(field.getOptionsBuilder()); popExpectedParent(field); }
Example 8
Source File: MessageNodeInfo.java From api-compiler with Apache License 2.0 | 4 votes |
public void addNewField( FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) { toBeAddedFields.add(FieldLocation.create(fieldDesc, location)); }
Example 9
Source File: FieldLocation.java From api-compiler with Apache License 2.0 | 4 votes |
public static FieldLocation create( FieldDescriptorProto.Builder fieldDescriptor, SourceCodeInfo.Location location) { return new AutoValue_FieldLocation(fieldDescriptor, location); }
Example 10
Source File: FieldLocation.java From api-compiler with Apache License 2.0 | votes |
public abstract FieldDescriptorProto.Builder fieldDescriptor();