本文整理汇总了Java中com.google.protobuf.DescriptorProtos.FileDescriptorProto.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptorProto.Builder方法的具体用法?Java FileDescriptorProto.Builder怎么用?Java FileDescriptorProto.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.DescriptorProtos.FileDescriptorProto
的用法示例。
在下文中一共展示了FileDescriptorProto.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateFile
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
private FileDescriptorProto generateFile(String name, FileContents contents) {
FileDescriptorProto.Builder fileBuilder = FileDescriptorProto.newBuilder();
fileBuilder.setName(name);
if (!Strings.isNullOrEmpty(contents.packageName)) {
fileBuilder.setPackage(contents.packageName);
}
for (Api api : contents.apis) {
fileBuilder.addService(generateApi(api));
}
for (Type type : contents.types.values()) {
fileBuilder.addMessageType(generateType(type, contents));
}
for (Enum e : contents.enums) {
fileBuilder.addEnumType(generateEnum(e));
}
if (imports.containsKey(name)) {
for (String imported : imports.get(name)) {
fileBuilder.addDependency(imported);
}
}
return fileBuilder.build();
}
示例2: makeCanonicalProto
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的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();
}
示例3: ParsedContext
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的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));
}
}
}
示例4: buildAllOptions
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的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: makeCanonicalProto
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的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();
}
示例6: makeProtoRefsRelative
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的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;
}
示例7: testParsed
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
@Test
public final void testParsed() throws Exception {
try {
walker.walk(protoParser, tree);
final FileDescriptorProto.Builder protoBuilder =
(FileDescriptorProto.Builder) protoParser.getParsed().getProto();
final FileDescriptor fileDescriptor =
FileDescriptor.buildFrom(protoBuilder.build(), new FileDescriptor[0]);
fail(String.format("expected exception type %s with message containg '%s', but got none!",
exception, exceptionExtra));
} catch (final Exception e) {
log.debug("expected exception with message '{}'", e.getMessage());
assertThat(e, instanceOf(exception));
assertThat(e.getMessage(), containsString(exceptionExtra));
}
}
示例8: addDeepMessageTypeToFile
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
private FileDescriptorProto.Builder addDeepMessageTypeToFile(
FileDescriptorProto.Builder builder, Message descriptorProto) {
//TODO delete this method!!!
final FieldDescriptor field = FileDescriptorProto.getDescriptor()
.findFieldByNumber(FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
final FieldDescriptor nestedTypeField = DescriptorProto.getDescriptor().findFieldByNumber(
DescriptorProto.NESTED_TYPE_FIELD_NUMBER);
builder.addRepeatedField(field, descriptorProto);
for (Message nestedMessageType : (List<Message>) descriptorProto.getField(nestedTypeField)) {
// builder.addRepeatedField(field, nestedMessageType);
addDeepMessageTypeToFile(builder, nestedMessageType);
}
return builder;
}
示例9: setProto
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
public Builder setProto(final FileDescriptorProtoOrBuilder proto) {
if (this.proto != Objects.requireNonNull(proto)) {
isBuilt = false;
if (proto instanceof FileDescriptorProto.Builder) {
this.proto = ((FileDescriptorProto.Builder) proto).build();
} else {
this.proto = (FileDescriptorProto) proto;
}
fileDescriptor = null;
}
return this;
}
示例10: accept
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
@Accepts
protected void accept(final FileDescriptorProto.Builder file) {
pushParent(BuilderVisitorNodeInfo.create(file));
currentFile.setManageSourceCodeInfo(manageSourceCodeInfo);
visitRepeated(FileDescriptorProto.MESSAGE_TYPE_FIELD_NUMBER);
visitRepeated(FileDescriptorProto.ENUM_TYPE_FIELD_NUMBER);
visitRepeated(FileDescriptorProto.EXTENSION_FIELD_NUMBER);
visitRepeated(FileDescriptorProto.SERVICE_FIELD_NUMBER);
visit(file.getOptionsBuilder());
popExpectedParent(file);
}
示例11: setupPathsForFile
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
private void setupPathsForFile(FileDescriptorProto.Builder file) {
// Populate location map
if (file.hasSourceCodeInfo() && manageSourceCodeInfo) {
for (SourceCodeInfo.Location location : file.getSourceCodeInfo().getLocationList()) {
pathToLocation.addDataElement(new ProtoPathWrapper(location.getPathList()), location);
}
} else {
// Turn off SourceCodeInfo management if there is none.
manageSourceCodeInfo = false;
}
}
示例12: resetPathsForFile
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
private void resetPathsForFile(FileDescriptorProto.Builder file) {
if (modifiedSourceCodeInfo) {
SourceCodeInfo.Builder sourceCodeInfo = file.getSourceCodeInfoBuilder();
sourceCodeInfo.clearLocation();
new LocationInfoUpdater(sourceCodeInfo).visit(pathToLocation);
modifiedSourceCodeInfo = false;
}
elementToOriginalPath.clear();
pathToLocation.clear();
}
示例13: testParsedPhase2
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
@Test
public final void testParsedPhase2() throws Exception {
walker.walk(protoParser, tree);
final FileDescriptorProto.Builder protoBuilder =
(FileDescriptorProto.Builder) protoParser.getParsed().getProto();
final FileDescriptorProto proto = protoBuilder.build();
log.debug("1st phase proto: \n{}\n", proto);
final FileDescriptor fileDescriptor = FileDescriptor.buildFrom(proto, new FileDescriptor[0]);
final FileDescriptorProto proto2 = fileDescriptor.toProto();
assertThat(proto2, equalTo(originalProto));
// log.debug(tree.toStringTree(parser));
// assert that protoc compiled GeneratedMessage.getDescriptor().getFile().toProto() equals to
// our proto!
}
示例14: createFileDescriptorProto
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
private FileDescriptorProto createFileDescriptorProto(String fileName, String packageName,
UnknownFieldSet unknownFields) {
FileDescriptorProto.Builder fileBuilder = FileDescriptorProto.newBuilder();
return fileBuilder
.setName(fileName)
.setPackage(packageName)
.setUnknownFields(unknownFields)
.addAllDependency(Collections.<String>emptyList())
.addAllEnumType(Collections.<EnumDescriptorProto>emptyList())
.addAllExtension(Collections.<FieldDescriptorProto>emptyList())
.addAllMessageType(Collections.<DescriptorProto>emptyList())
.addAllPublicDependency(Collections.<Integer>emptyList())
.addAllService(Collections.<ServiceDescriptorProto>emptyList())
.build();
}
示例15: create
import com.google.protobuf.DescriptorProtos.FileDescriptorProto; //导入方法依赖的package包/类
public static BuilderVisitorNodeInfo create(FileDescriptorProto.Builder node) {
return new FileNodeInfo(node);
}