use of org.infinispan.protostream.descriptors.Descriptor in project protostream by infinispan.
the class DescriptorsTest method testDocAnnotations.
@Test
public void testDocAnnotations() {
String file1 = "package test1;\n" + "/** \n" + " * @Foo(fooValue) \n" + " * some more doc text \n" + " **/\n\n" + "message X {\n" + " /**\n" + " * @Bar(barValue) \n\n" + " */\n" + " optional int32 field1 = 1;\n" + "}\n";
Configuration config = Configuration.builder().annotationsConfig().annotation("Foo", AnnotationElement.AnnotationTarget.MESSAGE).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.IDENTIFIER).metadataCreator((descriptor, annotation) -> annotation.getDefaultAttributeValue().getValue()).annotation("Bar", AnnotationElement.AnnotationTarget.FIELD).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.IDENTIFIER).metadataCreator((fieldDescriptor, annotation) -> annotation.getDefaultAttributeValue().getValue()).build();
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("file1.proto", file1);
Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
assertEquals(1, descriptors.size());
assertTrue(descriptors.containsKey("file1.proto"));
Map<String, GenericDescriptor> types = descriptors.get("file1.proto").getTypes();
Descriptor typeX = (Descriptor) types.get("test1.X");
assertNotNull(typeX);
assertEquals(1, typeX.getFields().size());
FieldDescriptor field1 = typeX.getFields().get(0);
assertEquals("@Foo(fooValue) \n some more doc text", typeX.getDocumentation());
Map<String, AnnotationElement.Annotation> typeAnnotations = typeX.getAnnotations();
assertEquals("fooValue", typeAnnotations.get("Foo").getDefaultAttributeValue().getValue());
assertEquals("fooValue", typeX.getProcessedAnnotation("Foo"));
assertEquals("@Bar(barValue)", field1.getDocumentation());
Map<String, AnnotationElement.Annotation> fieldAnnotations = field1.getAnnotations();
assertEquals("barValue", fieldAnnotations.get("Bar").getDefaultAttributeValue().getValue());
assertEquals("barValue", field1.getProcessedAnnotation("Bar"));
}
use of org.infinispan.protostream.descriptors.Descriptor in project kogito-runtimes by kiegroup.
the class ProtostreamProtobufAdapterTypeProvider method buildMessageTypes.
private FileDescriptorProto buildMessageTypes(FileDescriptor descriptor) {
FileDescriptorProto.Builder protoFileBuilder = FileDescriptorProto.newBuilder();
protoFileBuilder.setPackage(descriptor.getPackage());
protoFileBuilder.setName(descriptor.getName());
for (Descriptor message : descriptor.getMessageTypes()) {
protoFileBuilder.addMessageType(buildMessage(message));
}
return protoFileBuilder.build();
}
use of org.infinispan.protostream.descriptors.Descriptor in project kogito-runtimes by kiegroup.
the class AbstractMarshallerGenerator method javaTypeForMessage.
protected String javaTypeForMessage(FileDescriptor d, String messageName, SerializationContext serializationContext) {
Map<String, FileDescriptor> descriptors = serializationContext.getFileDescriptors();
for (Entry<String, FileDescriptor> entry : descriptors.entrySet()) {
List<Descriptor> messages = entry.getValue().getMessageTypes();
for (Descriptor msg : messages) {
if (messageName.equals(msg.getName())) {
return packageFromOption(d, msg) + "." + messageName;
} else if (messageName.equals(msg.getFullName())) {
return packageFromOption(d, msg) + "." + msg.getName();
}
}
List<EnumDescriptor> enums = entry.getValue().getEnumTypes();
for (EnumDescriptor msg : enums) {
if (messageName.equals(msg.getName())) {
return packageFromOption(d, msg) + "." + messageName;
} else if (messageName.equals(msg.getFullName())) {
return packageFromOption(d, msg) + "." + msg.getName();
}
}
}
return null;
}
Aggregations