当前位置: 首页>>代码示例>>Java>>正文


Java FieldDescriptorProto.Builder方法代码示例

本文整理汇总了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;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:21,代码来源:Misc.java

示例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);
    }
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:19,代码来源:ProtoFileParser.java

示例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();
    }
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:19,代码来源:Misc.java

示例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);
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:24,代码来源:OptionResolver.java

示例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));
    }
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:26,代码来源:ProtoFileParser.java

示例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();
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:28,代码来源:DescriptorGenerator.java

示例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));
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:16,代码来源:BuilderVisitor.java

示例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());
}
 
开发者ID:os72,项目名称:protobuf-dynamic,代码行数:10,代码来源:MessageDefinition.java

示例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);
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:16,代码来源:ProtoFileParser.java

示例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());
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:9,代码来源:ProtoFileParser.java

示例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;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:14,代码来源:Scopes.java

示例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);
    }
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:14,代码来源:Scopes.java

示例13: addFieldToMessageParent

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
protected void addFieldToMessageParent(FieldDescriptorProto.Builder fieldDesc) {
  addFieldToMessageAncestor(0, fieldDesc, null);
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:4,代码来源:BuilderVisitor.java

示例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);
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:7,代码来源:BuilderVisitor.java

示例15: addNewField

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入方法依赖的package包/类
public void addNewField(
    FieldDescriptorProto.Builder fieldDesc, SourceCodeInfo.Location location) {
  toBeAddedFields.add(FieldLocation.create(fieldDesc, location));
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:5,代码来源:MessageNodeInfo.java


注:本文中的com.google.protobuf.DescriptorProtos.FieldDescriptorProto.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。