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


Java FieldDescriptorProto类代码示例

本文整理汇总了Java中com.google.protobuf.DescriptorProtos.FieldDescriptorProto的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptorProto类的具体用法?Java FieldDescriptorProto怎么用?Java FieldDescriptorProto使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FieldDescriptorProto类属于com.google.protobuf.DescriptorProtos包,在下文中一共展示了FieldDescriptorProto类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMessageJavaType

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
private String getMessageJavaType(String packageName, DescriptorProto sourceMessageDesc,
    FieldDescriptorProto field) {
  String fieldType = CommonUtils.findNotIncludePackageType(field.getTypeName());
  Map<String, Pair<DescriptorProto, List<FieldDescriptorProto>>> nestedFieldType =
      transform(sourceMessageDesc);
  // isMap
  if (nestedFieldType.containsKey(fieldType)) {
    Pair<DescriptorProto, List<FieldDescriptorProto>> nestedFieldPair =
        nestedFieldType.get(fieldType);
    if (nestedFieldPair.getRight().size() == 2) {
      DescriptorProto mapSourceMessageDesc = nestedFieldPair.getLeft();
      List<FieldDescriptorProto> mapFieldList = nestedFieldPair.getRight();
      String nestedJavaType =
          "java.util.Map<" + findJavaType(packageName, mapSourceMessageDesc, mapFieldList.get(0))
              + "," + findJavaType(packageName, mapSourceMessageDesc, mapFieldList.get(1)) + ">";
      return nestedJavaType;
    } else {
      return null;
    }
  } else {
    return CommonUtils.findPojoTypeFromCache(field.getTypeName(), pojoTypeCache);
  }
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:24,代码来源:PrintMessageFile.java

示例2: resolveType

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
/**
 * Resolves a type based on the given partial name. This does not assume that the name, as
 * obtained from the descriptor, is in absolute form.
 */
private TypeRef resolveType(Location location, FieldDescriptorProto.Type kind, String name) {
  TypeRef type;
  switch (kind) {
    case TYPE_MESSAGE:
    case TYPE_ENUM:
    case TYPE_GROUP:
      type = symbolTable.resolveType(namespaces.peek(), name);
      break;
    default:
      type = TypeRef.of(kind);
  }
  if (type == null) {
    model.getDiagReporter().report(Diag.error(location, "Unresolved type '%s'", name));
  }
  return type;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:21,代码来源:ReferenceResolver.java

示例3: checkCyclic

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
private boolean checkCyclic(Set<MessageType> visited, MessageType message) {
  if (!visited.add(this)) {
    return false;
  }
  for (Field field : fields) {
    TypeRef type = field.getType();
    if (type.getKind() == FieldDescriptorProto.Type.TYPE_MESSAGE) {
      if (message == type.getMessageType()) {
        return true;
      }
      if (type.getMessageType().checkCyclic(visited, message)) {
        // If there is a cycle to message via this, then this is also cyclic. That's the nature
        // of a cycle.
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:20,代码来源:MessageType.java

示例4: add

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
private void add(List<FieldDescriptorProto> extensions) {
  for (int i = 0; i < extensions.size(); i++) {
    pathSegments.push(i);
    FieldDescriptorProto extensionProto = extensions.get(i);
    String extendee = resolve(extensionProto.getExtendee());
    Multimap<String, Extension> messageExtensions = builder.get(extendee);
    if (messageExtensions == null) {
      messageExtensions = ArrayListMultimap.create();
      builder.put(extendee, messageExtensions);
    }
    String path = DOT_JOINER.join(pathSegments.descendingIterator());
    DescriptorProtos.SourceCodeInfo.Location location = locationMap.get(path).get(0);
    // Since paths are only unique within a file, we need a synthetic path to make them unique,
    // given that paths are used to uniquely identify elements in a ProtoFile, and we're
    // stuffing elements from another file into it.
    path = currentFile.getName() + ":" + path;
    Location fileLocation = new SimpleLocation(String.format(
        "%s:%d:%d", currentFile.getName(), location.getSpan(0) + 1, location.getSpan(1) + 1));
    Extension extension = new Extension(extensionProto, location, path, fileLocation);
    messageExtensions.put(getExtensionFieldName(extensionProto.getName()), extension);
    pathSegments.pop();
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:24,代码来源:ExtensionPool.java

示例5: decompile

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
public void decompile(FileDescriptorProto fileDescriptor) throws IOException {
    if (fileDescriptor.hasPackage()) {
        indentedFormat("package %s;", fileDescriptor.getPackage());
        absolutePackage = "." + fileDescriptor.getPackage() + ".";
    }
    for (String dependency : fileDescriptor.getDependencyList()) {
        indentedFormat("import \"%s\";", dependency);
    }
    if (fileDescriptor.hasOptions()) {
        decompileOptions(fileDescriptor.getOptions());
    }
    decompileMembers(fileDescriptor.getEnumTypeList(),
                     fileDescriptor.getMessageTypeList(),
                     Collections.<FieldDescriptorProto>emptyList(),
                     Collections.<DescriptorProto.ExtensionRange>emptyList(),
                     fileDescriptor.getExtensionList());
    for (ServiceDescriptorProto serviceDescriptor : fileDescriptor.getServiceList()) {
        decompile(serviceDescriptor);
    }
    newline();
    flush();
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:23,代码来源:ProtobufDecompiler.java

示例6: testPackedEnumField

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
public void testPackedEnumField() throws Exception {
  FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
      .setName("foo.proto")
      .addEnumType(EnumDescriptorProto.newBuilder()
        .setName("Enum")
        .addValue(EnumValueDescriptorProto.newBuilder()
          .setName("FOO")
          .setNumber(1)
          .build())
        .build())
      .addMessageType(DescriptorProto.newBuilder()
        .setName("Message")
        .addField(FieldDescriptorProto.newBuilder()
          .setName("foo")
          .setTypeName("Enum")
          .setNumber(1)
          .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
          .setOptions(DescriptorProtos.FieldOptions.newBuilder()
            .setPacked(true)
            .build())
          .build())
        .build())
      .build();
  Descriptors.FileDescriptor.buildFrom(
      fileDescriptorProto, new FileDescriptor[0]);
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:27,代码来源:DescriptorsTest.java

示例7: appendToFullName

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
private static Optional<String> appendToFullName(
        DescriptorProto messageDescriptor, List<Integer> path, String fullNameSoFar) {
    switch (path.get(0)) {
        case DescriptorProto.NESTED_TYPE_FIELD_NUMBER:
            DescriptorProto nestedMessage = messageDescriptor.getNestedType(path.get(1));
            return appendMessageToFullName(nestedMessage, path, fullNameSoFar);
        case DescriptorProto.ENUM_TYPE_FIELD_NUMBER:
            EnumDescriptorProto enumDescriptor = messageDescriptor.getEnumType(path.get(1));
            return Optional.of(appendEnumToFullName(enumDescriptor, path, fullNameSoFar));
        case DescriptorProto.FIELD_FIELD_NUMBER:
            FieldDescriptorProto fieldDescriptor = messageDescriptor.getField(path.get(1));
            return Optional.of(appendFieldComponent(fullNameSoFar, fieldDescriptor.getName()));
        default:
            return Optional.empty();
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:17,代码来源:GrpcDocStringExtractor.java

示例8: makeCanonicalProto

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
private FileDescriptorProto makeCanonicalProto(final FileDescriptor fileDescriptor) {
  final FileDescriptorProto.Builder protoBuilder =
      FileDescriptorProto.newBuilder(fileDescriptor.toProto());

  for (final FieldDescriptorProto.Builder field : protoBuilder.getExtensionBuilderList()) {
    makeCanonicalField(field, fileDescriptor.findExtensionByName(field.getName()));
  }

  for (final DescriptorProto.Builder message : protoBuilder.getMessageTypeBuilderList()) {
    makeCanonicalMessage(message, fileDescriptor.findMessageTypeByName(message.getName()));
  }

  // for (EnumDescriptorProto.Builder enumProto :
  // protoBuilder.getEnumTypeBuilderList()) {
  // makeCanonicalEnum(enumProto,
  // fileDescriptor.findEnumTypeByName(enumProto.getName()));
  // }

  for (final ServiceDescriptorProto.Builder serviceProto : protoBuilder.getServiceBuilderList()) {
    makeCanonicalService(serviceProto, fileDescriptor.findServiceByName(serviceProto.getName()));
  }

  // TODO: incorporate options' tree walking into canonicalization to eliminate double walking
  return OptionResolver.newBuilder().setCustomOptionsAsExtensions(false)
      .resolveAllOptionsFor(fileDescriptor, protoBuilder).build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:27,代码来源:FileDescriptors.java

示例9: exitBytesFieldOption

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
@Override
public void exitBytesFieldOption(final BytesFieldOptionContext ctx) {
  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 =
          protoEscapeBytes(unescapeBytes(input.substring(1, input.length() - 1)));
      fieldBuilder.setDefaultValue(result);
    } catch (final InvalidEscapeSequenceException e) {
      contextLookup.reportInvalidDefaultValue((ParserRuleContext) ctx.getChild(2), e);
    }
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:18,代码来源:ProtoFileParser.java

示例10: 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

示例11: 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

示例12: resolveAllRefs

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
public boolean resolveAllRefs(final Collection<FileDescriptor> dependencies,
    final IProtoErrorListener errorListener) {
  if (isBuilt()) {
    throw new IllegalStateException("not supported when proto is already built");
  }

  final Map<String, NameContext> cache = new HashMap<String, NameContext>();

  if (resolveAllRefs(dependencies, errorListener, cache)) {
    return true;
  }

  for (final Entry<FieldDescriptorProto.Builder, FieldContext> entry : unresolved) {
    reportUnresolvedTypeNameError(entry.getKey(), entry.getValue(), errorListener);
  }

  return false;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:19,代码来源:ProtoFileParser.java

示例13: 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

示例14: makeCanonicalProto

import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; //导入依赖的package包/类
private FileDescriptorProto makeCanonicalProto(final FileDescriptor file) {
  final FileDescriptorProto.Builder protoBuilder = FileDescriptorProto.newBuilder(file.toProto());

  for (final FieldDescriptorProto.Builder field : protoBuilder.getExtensionBuilderList()) {
    makeCanonicalField(field, file.findExtensionByName(field.getName()));
  }

  for (final DescriptorProto.Builder message : protoBuilder.getMessageTypeBuilderList()) {
    makeCanonicalMessage(message, file.findMessageTypeByName(message.getName()));
  }

  // for (EnumDescriptorProto.Builder enumProto :
  // protoBuilder.getEnumTypeBuilderList()) {
  // makeCanonicalEnum(enumProto,
  // file.findEnumTypeByName(enumProto.getName()));
  // }

  for (final ServiceDescriptorProto.Builder serviceProto : protoBuilder.getServiceBuilderList()) {
    makeCanonicalService(serviceProto, file.findServiceByName(serviceProto.getName()));
  }

  return OptionResolver.newBuilder().setCustomOptionsAsExtensions(reparseCustomOptions)
      .resolveAllOptionsFor(file, protoBuilder).build();
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:25,代码来源:FileDescriptorEx.java

示例15: 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


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