Java Code Examples for com.google.protobuf.DescriptorProtos.FileDescriptorSet#Builder
The following examples show how to use
com.google.protobuf.DescriptorProtos.FileDescriptorSet#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: ResolverTest.java From api-compiler with Apache License 2.0 | 6 votes |
@Test public void resolvesWithErrors() { // Modify the descriptor injecting some errors. FileDescriptorSet.Builder builder = descriptors.toBuilder(); builder .getFileBuilder(0) .getMessageTypeBuilder(0) .getFieldBuilder(1) // required N n .setTypeName("undef_N"); builder .getFileBuilder(0) .getMessageTypeBuilder(0) .getFieldBuilder(2) // optional E e .setTypeName("undef_E"); Model testApi = Model.create(builder.build()); testApi.registerProcessor(new Resolver()); Truth.assertThat(testApi.establishStage(Resolved.KEY)).isFalse(); Truth.assertThat(testApi.getDiagReporter().getDiagCollector().getErrorCount()).isEqualTo(2); assertThat(testApi.getDiagReporter().getDiagCollector().getDiags().get(0).toString()) .contains("undef_N"); assertThat(testApi.getDiagReporter().getDiagCollector().getDiags().get(1).toString()) .contains("undef_E"); }
Example 2
Source File: DescriptorGenerator.java From api-compiler with Apache License 2.0 | 5 votes |
private FileDescriptorSet generate() { FileDescriptorSet.Builder setBuilder = FileDescriptorSet.newBuilder(); for (Map.Entry<String, FileContents> entry : contentsByFile.entrySet()) { FileContents contents = entry.getValue(); String fileName = entry.getKey(); if (!contents.apis.isEmpty() || !contents.types.isEmpty() || !contents.enums.isEmpty()) { setBuilder.addFile(generateFile(fileName, contents)); } } return setBuilder.build(); }
Example 3
Source File: ResolverTest.java From api-compiler with Apache License 2.0 | 5 votes |
@Test public void resolvesOkWithPartialNames() { // Modify the descriptor. Protoc generates full names, and // we want to check whether we can also deal with partial names. FileDescriptorSet.Builder builder = descriptors.toBuilder(); builder .getFileBuilder(0) .getMessageTypeBuilder(0) .getFieldBuilder(1) // required N n .setTypeName("N"); Model testApi = Model.create(builder.build()); testApi.registerProcessor(new Resolver()); Truth.assertThat(testApi.establishStage(Resolved.KEY)).isTrue(); Truth.assertThat(testApi.getDiagReporter().getDiagCollector().hasErrors()).isFalse(); }
Example 4
Source File: DynamicSchema.java From protobuf-dynamic with Apache License 2.0 | 5 votes |
/** * Builds a dynamic schema * * @return the schema object * @throws DescriptorValidationException */ public DynamicSchema build() throws DescriptorValidationException { FileDescriptorSet.Builder fileDescSetBuilder = FileDescriptorSet.newBuilder(); fileDescSetBuilder.addFile(mFileDescProtoBuilder.build()); fileDescSetBuilder.mergeFrom(mFileDescSetBuilder.build()); return new DynamicSchema(fileDescSetBuilder.build()); }
Example 5
Source File: BuilderVisitor.java From api-compiler with Apache License 2.0 | 4 votes |
@Accepts protected void accept(final FileDescriptorSet.Builder files) { pushParent(BuilderVisitorNodeInfo.create(files)); visitRepeated(FileDescriptorSet.FILE_FIELD_NUMBER); popExpectedParent(files); }
Example 6
Source File: BuilderVisitorNodeInfo.java From api-compiler with Apache License 2.0 | 4 votes |
public static BuilderVisitorNodeInfo create(FileDescriptorSet.Builder node) { // FileDescriptorSet can't be contained within a FileDescriptor, so pass null here. return new GenericNodeInfo(node, null); }
Example 7
Source File: ProtobufStorageDescriptionHelper.java From sql-layer with GNU Affero General Public License v3.0 | 4 votes |
static FileDescriptorProto validateAndGenerate(HasStorage object, ProtobufRowFormat.Type formatType, FileDescriptorProto fileProto, AISValidationOutput output) { if (!(object instanceof Group)) { output.reportFailure(new AISValidationFailure(new StorageDescriptionInvalidException(object, "is not a Group and cannot use Protocol Buffers"))); return null; } Group group = (Group)object; if (formatType == ProtobufRowFormat.Type.SINGLE_TABLE) { if (!group.getRoot().getChildJoins().isEmpty()) { output.reportFailure(new AISValidationFailure(new StorageDescriptionInvalidException(object, "has more than one table"))); return null; } } int currentVersion = sumTableVersions(group.getRoot()); if (fileProto != null) { int storedVersion = fileProto.getOptions() .getExtension(CustomOptions.GroupOptions.fdbsql).getVersion(); if (storedVersion == currentVersion) { return fileProto; } } FileDescriptorSet set = null; if (fileProto != null) { FileDescriptorSet.Builder builder = FileDescriptorSet.newBuilder(); builder.addFile(fileProto); set = builder.build(); } AISToProtobuf ais2p = new AISToProtobuf(formatType, set); ais2p.addGroup(group); set = ais2p.build(); fileProto = set.getFile(0); // Only added one group. // Make sure it will build before committing to this format. try { FileDescriptor.buildFrom(fileProto, DEPENDENCIES); } catch (DescriptorValidationException ex) { output.reportFailure(new AISValidationFailure(new ProtobufBuildException(ex))); } return fileProto; }