本文整理汇总了Java中com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptorProto.Builder方法的具体用法?Java FieldDescriptorProto.Builder怎么用?Java FieldDescriptorProto.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.DescriptorProtos.FieldDescriptorProto
的用法示例。
在下文中一共展示了FieldDescriptorProto.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeProtoRefsRelative
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
@SuppressWarnings("null")
public static FileDescriptorProto.Builder makeProtoRefsRelative(final FileDescriptorProto proto,
final FieldTypeRefsMode fieldTypeRefsMode) {
if (fieldTypeRefsMode == FieldTypeRefsMode.AS_IS) {
return FileDescriptorProto.newBuilder(proto);
}
final FileDescriptorProto.Builder protoBuilder = FileDescriptorProto.newBuilder(proto);
final String packagePath = "." + proto.getPackage();
for (final FieldDescriptorProto.Builder field : protoBuilder.getExtensionBuilderList()) {
makeFieldRefsRelative(packagePath, field, fieldTypeRefsMode, packagePath);
}
for (final DescriptorProto.Builder message : protoBuilder.getMessageTypeBuilderList()) {
makeMessageRefsRelative(packagePath, message, fieldTypeRefsMode, packagePath);
}
return protoBuilder;
}
示例2: exitStringFieldOption
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
@Override
public void exitStringFieldOption(final StringFieldOptionContext ctx) {
// TODO: what to do about '\?'
if (ctx.getChildCount() == 3) {
verifyOptionNameUnique("default", ctx.getStart());
final FieldDescriptorProto.Builder fieldBuilder =
FieldDescriptorProto.Builder.class.cast(scopes.getProtoBuilder());
final String input = ctx.getChild(2).getText();
try {
final String result =
unescapeText(input.substring(1, input.length() - 1).replaceAll("\\\\[?]", "?"));
fieldBuilder.setDefaultValue(result);
} catch (final InvalidEscapeSequenceException e) {
contextLookup.reportInvalidDefaultValue((ParserRuleContext) ctx.getChild(2), e);
}
}
}
示例3: makeFieldRefsRelative
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
@SuppressWarnings("null")
private static void makeFieldRefsRelative(final String packagePath,
final FieldDescriptorProto.Builder field, final FieldTypeRefsMode fieldTypeRefsMode,
final String parentFullName) {
if (field.hasExtendee() && field.getExtendee().startsWith(".")) {
field.setExtendee(getRelativeName(packagePath, field.getExtendee(), fieldTypeRefsMode,
parentFullName));
}
if (field.hasTypeName() && field.getTypeName().startsWith(".")) {
field.setTypeName(getRelativeName(packagePath, field.getTypeName(), fieldTypeRefsMode,
parentFullName));
if (field.hasType()) {
field.clearType();
}
}
}
示例4: buildAllOptions
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
private void buildAllOptions(final FileDescriptorProto.Builder proto) {
if (!buildOptions(proto.getOptionsBuilder())) {
proto.clearOptions();
}
for (final FieldDescriptorProto.Builder extensionProto : proto.getExtensionBuilderList()) {
if (!buildOptions(extensionProto.getOptionsBuilder())) {
extensionProto.clearOptions();
}
}
for (final EnumDescriptorProto.Builder enumProto : proto.getEnumTypeBuilderList()) {
buildAllOptions(enumProto);
}
for (final ServiceDescriptorProto.Builder serviceProto : proto.getServiceBuilderList()) {
buildAllOptions(serviceProto);
}
for (final DescriptorProto.Builder messageProto : proto.getMessageTypeBuilderList()) {
buildAllOptions(messageProto);
}
}
示例5: ParsedContext
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
private ParsedContext(final FileDescriptorProto.Builder proto,
final List<FieldDescriptorProto.Builder> unresolved, final ContextLookup lookup) {
this.proto = proto;
if ((unresolved == null) || unresolved.isEmpty()) {
this.unresolved = Collections.emptyList();
} else {
if (lookup == null) {
throw new NullPointerException();
}
this.unresolved = new ArrayList<Map.Entry<FieldDescriptorProto.Builder, FieldContext>>();
for (final FieldDescriptorProto.Builder field : unresolved) {
final FieldContext context = (FieldContext) lookup.getContext(field, false);
if (context == null) {
throw new IllegalStateException("field context must not be null");
}
this.unresolved.add(new SimpleEntry<FieldDescriptorProto.Builder, FieldContext>(field,
context));
}
}
}
示例6: generateField
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
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();
}
示例7: addFieldToMessageAncestor
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
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));
}
}
示例8: addField
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
private void addField(FieldDescriptorProto.Label label, String type, String name, int num, String defaultVal) {
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);
mMsgTypeBuilder.addField(fieldBuilder.build());
}
示例9: exitGroup
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
@Override
public void exitGroup(final GroupContext ctx) {
scopes.popScope();
final String groupName = ctx.groupIdentifier().getText();
// add group's field
final FieldDescriptorProto.Builder fieldBuilder = scopes.addField();
setFieldBuilder(fieldBuilder, groupName.toLowerCase(), ctx.fieldNumber().getText(),
ctx.label().getText(), FieldDescriptorProto.Type.TYPE_GROUP).setTypeName(groupName);
scopes.popScope();
contextLookup.addGroup(fieldBuilder, ctx);
scopes.addIfUnresolved(fieldBuilder);
scopes.verifyField(fieldBuilder);
}
示例10: setFieldDefaultValue
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
private void setFieldDefaultValue(final ParserRuleContext ctx) {
if (ctx.getChildCount() == 3) {
verifyOptionNameUnique("default", ctx.getStart());
final FieldDescriptorProto.Builder fieldBuilder =
FieldDescriptorProto.Builder.class.cast(scopes.getProtoBuilder());
fieldBuilder.setDefaultValue(ctx.getChild(2).getText());
}
}
示例11: addField
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
public FieldDescriptorProto.Builder addField() {
FieldDescriptorProto.Builder builder = null;
// FIXME and then remove try!
try {
builder = currentScope.addField();
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
pushScope(new FieldScope(builder, currentScope));
return builder;
}
示例12: verifyField
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
public void verifyField(final FieldDescriptorProto.Builder field) {
if (currentScope instanceof MessageScope) {
final MessageScope scope = (MessageScope) currentScope;
if (!scope.verifyFieldNameUnique(field.getName())) {
contextLookup.reportNonUniqueFieldNameError(field, false);
}
if (!scope.verifyFieldNumberUnique(field.getNumber())) {
contextLookup.reportNonUniqueFieldNumberError(field, false);
}
}
}
示例13: addFieldToMessageParent
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
protected void addFieldToMessageParent(FieldDescriptorProto.Builder fieldDesc) {
addFieldToMessageAncestor(0, fieldDesc, null);
}
示例14: accept
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
@Accepts
protected void accept(FieldDescriptorProto.Builder field) {
pushParent(BuilderVisitorNodeInfo.create(field, currentFile));
visit(field.getOptionsBuilder());
popExpectedParent(field);
}
示例15: addNewField
import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
public void addNewField(
FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) {
toBeAddedFields.add(FieldLocation.create(fieldDesc, location));
}