com.salesforce.jprotoc.ProtoTypeMap Java Examples
The following examples show how to use
com.salesforce.jprotoc.ProtoTypeMap.
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: MutinyGrpcGenerator.java From quarkus with Apache License 2.0 | 6 votes |
private List<ServiceContext> findServices(List<DescriptorProtos.FileDescriptorProto> protos, ProtoTypeMap typeMap) { List<ServiceContext> contexts = new ArrayList<>(); protos.forEach(fileProto -> { for (int serviceNumber = 0; serviceNumber < fileProto.getServiceCount(); serviceNumber++) { ServiceContext serviceContext = buildServiceContext( fileProto.getService(serviceNumber), typeMap, fileProto.getSourceCodeInfo().getLocationList(), serviceNumber); serviceContext.protoName = fileProto.getName(); serviceContext.packageName = extractPackageName(fileProto); contexts.add(serviceContext); } }); return contexts; }
Example #2
Source File: AbstractGenerator.java From sofa-rpc with Apache License 2.0 | 6 votes |
private List<ServiceContext> findServices(List<FileDescriptorProto> protos, ProtoTypeMap typeMap) { List<ServiceContext> contexts = new ArrayList<>(); for (FileDescriptorProto fileProto : protos) { for (int serviceNumber = 0; serviceNumber < fileProto.getServiceCount(); serviceNumber++) { ServiceContext serviceContext = buildServiceContext( fileProto.getService(serviceNumber), typeMap, fileProto.getSourceCodeInfo().getLocationList(), serviceNumber ); serviceContext.setProtoName(fileProto.getName()); serviceContext.setPackageName(extractPackageName(fileProto)); contexts.add(serviceContext); } } return contexts; }
Example #3
Source File: ReactiveGrpcGenerator.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
private List<ServiceContext> findServices(List<FileDescriptorProto> protos, ProtoTypeMap typeMap) { List<ServiceContext> contexts = new ArrayList<>(); protos.forEach(fileProto -> { for (int serviceNumber = 0; serviceNumber < fileProto.getServiceCount(); serviceNumber++) { ServiceContext serviceContext = buildServiceContext( fileProto.getService(serviceNumber), typeMap, fileProto.getSourceCodeInfo().getLocationList(), serviceNumber ); serviceContext.protoName = fileProto.getName(); serviceContext.packageName = extractPackageName(fileProto); contexts.add(serviceContext); } }); return contexts; }
Example #4
Source File: Jdk8Generator.java From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License | 6 votes |
private List<ServiceContext> extractContext(ProtoTypeMap protoTypeMap, DescriptorProtos.FileDescriptorProto fileProto) { List<ServiceContext> serviceContexts = new ArrayList<>(); List<DescriptorProtos.SourceCodeInfo.Location> locations = fileProto.getSourceCodeInfo().getLocationList(); locations.stream() .filter(location -> location.getPathCount() == 2 && location.getPath(0) == DescriptorProtos.FileDescriptorProto.SERVICE_FIELD_NUMBER) .forEach(location -> { int serviceNumber = location.getPath(1); DescriptorProtos.ServiceDescriptorProto serviceProto = fileProto.getService(serviceNumber); ServiceContext ctx = extractServiceContext(protoTypeMap, serviceProto, locations, serviceNumber); ctx.packageName = extractPackageName(fileProto); ctx.protoName = fileProto.getName(); ctx.javaDoc = getJavaDoc(getComments(location), SERVICE_JAVADOC_PREFIX); serviceContexts.add(ctx); }); return serviceContexts; }
Example #5
Source File: MutinyGrpcGenerator.java From quarkus with Apache License 2.0 | 5 votes |
@Override public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException { ProtoTypeMap typeMap = ProtoTypeMap.of(request.getProtoFileList()); List<DescriptorProtos.FileDescriptorProto> protosToGenerate = request.getProtoFileList().stream() .filter(protoFile -> request.getFileToGenerateList().contains(protoFile.getName())) .collect(Collectors.toList()); List<ServiceContext> services = findServices(protosToGenerate, typeMap); return generateFiles(services); }
Example #6
Source File: MutinyGrpcGenerator.java From quarkus with Apache License 2.0 | 5 votes |
private ServiceContext buildServiceContext(DescriptorProtos.ServiceDescriptorProto serviceProto, ProtoTypeMap typeMap, List<DescriptorProtos.SourceCodeInfo.Location> locations, int serviceNumber) { ServiceContext serviceContext = new ServiceContext(); serviceContext.classPrefix = CLASS_PREFIX; serviceContext.fileName = CLASS_PREFIX + serviceProto.getName() + "Grpc.java"; serviceContext.className = CLASS_PREFIX + serviceProto.getName() + "Grpc"; serviceContext.serviceName = serviceProto.getName(); serviceContext.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated(); List<DescriptorProtos.SourceCodeInfo.Location> allLocationsForService = locations.stream() .filter(location -> location.getPathCount() >= 2 && location.getPath(0) == DescriptorProtos.FileDescriptorProto.SERVICE_FIELD_NUMBER && location.getPath(1) == serviceNumber) .collect(Collectors.toList()); DescriptorProtos.SourceCodeInfo.Location serviceLocation = allLocationsForService.stream() .filter(location -> location.getPathCount() == SERVICE_NUMBER_OF_PATHS) .findFirst() .orElseGet(DescriptorProtos.SourceCodeInfo.Location::getDefaultInstance); serviceContext.javaDoc = getJavaDoc(getComments(serviceLocation), getServiceJavaDocPrefix()); for (int methodNumber = 0; methodNumber < serviceProto.getMethodCount(); methodNumber++) { MethodContext methodContext = buildMethodContext( serviceProto.getMethod(methodNumber), typeMap, locations, methodNumber); serviceContext.methods.add(methodContext); } return serviceContext; }
Example #7
Source File: MutinyGrpcGenerator.java From quarkus with Apache License 2.0 | 5 votes |
private MethodContext buildMethodContext(DescriptorProtos.MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<DescriptorProtos.SourceCodeInfo.Location> locations, int methodNumber) { MethodContext methodContext = new MethodContext(); methodContext.methodName = lowerCaseFirst(methodProto.getName()); methodContext.inputType = typeMap.toJavaTypeName(methodProto.getInputType()); methodContext.outputType = typeMap.toJavaTypeName(methodProto.getOutputType()); methodContext.deprecated = methodProto.getOptions() != null && methodProto.getOptions().getDeprecated(); methodContext.isManyInput = methodProto.getClientStreaming(); methodContext.isManyOutput = methodProto.getServerStreaming(); methodContext.methodNumber = methodNumber; DescriptorProtos.SourceCodeInfo.Location methodLocation = locations.stream() .filter(location -> location.getPathCount() == METHOD_NUMBER_OF_PATHS && location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber) .findFirst() .orElseGet(DescriptorProtos.SourceCodeInfo.Location::getDefaultInstance); methodContext.javaDoc = getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix()); if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { methodContext.mutinyCallsMethodName = "oneToOne"; methodContext.grpcCallsMethodName = "asyncUnaryCall"; } if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) { methodContext.mutinyCallsMethodName = "oneToMany"; methodContext.grpcCallsMethodName = "asyncServerStreamingCall"; } if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { methodContext.mutinyCallsMethodName = "manyToOne"; methodContext.grpcCallsMethodName = "asyncClientStreamingCall"; } if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) { methodContext.mutinyCallsMethodName = "manyToMany"; methodContext.grpcCallsMethodName = "asyncBidiStreamingCall"; } return methodContext; }
Example #8
Source File: AbstractGenerator.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException { final ProtoTypeMap typeMap = ProtoTypeMap.of(request.getProtoFileList()); List<FileDescriptorProto> protosToGenerate = new ArrayList<>(); for (FileDescriptorProto protoFile : request.getProtoFileList()) { if (request.getFileToGenerateList().contains(protoFile.getName())) { protosToGenerate.add(protoFile); } } List<ServiceContext> services = findServices(protosToGenerate, typeMap); return generateFiles(services); }
Example #9
Source File: ReactiveGrpcGenerator.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException { final ProtoTypeMap typeMap = ProtoTypeMap.of(request.getProtoFileList()); List<FileDescriptorProto> protosToGenerate = request.getProtoFileList().stream() .filter(protoFile -> request.getFileToGenerateList().contains(protoFile.getName())) .collect(Collectors.toList()); List<ServiceContext> services = findServices(protosToGenerate, typeMap); return generateFiles(services); }
Example #10
Source File: ReactiveGrpcGenerator.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ServiceContext buildServiceContext(ServiceDescriptorProto serviceProto, ProtoTypeMap typeMap, List<Location> locations, int serviceNumber) { ServiceContext serviceContext = new ServiceContext(); serviceContext.fileName = getClassPrefix() + serviceProto.getName() + "Grpc.java"; serviceContext.className = getClassPrefix() + serviceProto.getName() + "Grpc"; serviceContext.serviceName = serviceProto.getName(); serviceContext.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated(); List<Location> allLocationsForService = locations.stream() .filter(location -> location.getPathCount() >= 2 && location.getPath(0) == FileDescriptorProto.SERVICE_FIELD_NUMBER && location.getPath(1) == serviceNumber ) .collect(Collectors.toList()); Location serviceLocation = allLocationsForService.stream() .filter(location -> location.getPathCount() == SERVICE_NUMBER_OF_PATHS) .findFirst() .orElseGet(Location::getDefaultInstance); serviceContext.javaDoc = getJavaDoc(getComments(serviceLocation), getServiceJavaDocPrefix()); for (int methodNumber = 0; methodNumber < serviceProto.getMethodCount(); methodNumber++) { MethodContext methodContext = buildMethodContext( serviceProto.getMethod(methodNumber), typeMap, locations, methodNumber ); serviceContext.methods.add(methodContext); } return serviceContext; }
Example #11
Source File: ReactiveGrpcGenerator.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations, int methodNumber) { MethodContext methodContext = new MethodContext(); methodContext.methodName = lowerCaseFirst(methodProto.getName()); methodContext.inputType = typeMap.toJavaTypeName(methodProto.getInputType()); methodContext.outputType = typeMap.toJavaTypeName(methodProto.getOutputType()); methodContext.deprecated = methodProto.getOptions() != null && methodProto.getOptions().getDeprecated(); methodContext.isManyInput = methodProto.getClientStreaming(); methodContext.isManyOutput = methodProto.getServerStreaming(); methodContext.methodNumber = methodNumber; Location methodLocation = locations.stream() .filter(location -> location.getPathCount() == METHOD_NUMBER_OF_PATHS && location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber ) .findFirst() .orElseGet(Location::getDefaultInstance); methodContext.javaDoc = getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix()); if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { methodContext.reactiveCallsMethodName = "oneToOne"; methodContext.grpcCallsMethodName = "asyncUnaryCall"; } if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) { methodContext.reactiveCallsMethodName = "oneToMany"; methodContext.grpcCallsMethodName = "asyncServerStreamingCall"; } if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { methodContext.reactiveCallsMethodName = "manyToOne"; methodContext.grpcCallsMethodName = "asyncClientStreamingCall"; } if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) { methodContext.reactiveCallsMethodName = "manyToMany"; methodContext.grpcCallsMethodName = "asyncBidiStreamingCall"; } return methodContext; }
Example #12
Source File: Jdk8Generator.java From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.CodeGeneratorRequest request) throws GeneratorException { final ProtoTypeMap protoTypeMap = ProtoTypeMap.of(request.getProtoFileList()); List<PluginProtos.CodeGeneratorResponse.File> files = new ArrayList<>(); for (DescriptorProtos.FileDescriptorProto protoFile : request.getProtoFileList()) { if (request.getFileToGenerateList().contains(protoFile.getName())) { for (ServiceContext ctx : extractContext(protoTypeMap, protoFile)) { files.add(buildFile(ctx)); } } } return files; }
Example #13
Source File: Jdk8Generator.java From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ServiceContext extractServiceContext( ProtoTypeMap protoTypeMap, DescriptorProtos.ServiceDescriptorProto serviceProto, List<DescriptorProtos.SourceCodeInfo.Location> locations, int serviceNumber) { ServiceContext ctx = new ServiceContext(); ctx.fileName = serviceProto.getName() + CLASS_SUFFIX + ".java"; ctx.className = serviceProto.getName() + CLASS_SUFFIX; ctx.serviceName = serviceProto.getName(); ctx.deprecated = serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated(); locations.stream() .filter(location -> location.getPathCount() == METHOD_NUMBER_OF_PATHS && location.getPath(0) == DescriptorProtos.FileDescriptorProto.SERVICE_FIELD_NUMBER && location.getPath(1) == serviceNumber && location.getPath(2) == DescriptorProtos.ServiceDescriptorProto.METHOD_FIELD_NUMBER) .forEach(location -> { int methodNumber = location.getPath(METHOD_NUMBER_OF_PATHS - 1); DescriptorProtos.MethodDescriptorProto methodProto = serviceProto.getMethod(methodNumber); // Identify methods to generate a CompletableFuture-based client for. // Only unary methods are supported. if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { MethodContext ctxMethod = new MethodContext(); ctxMethod.methodName = lowerCaseFirst(methodProto.getName()); ctxMethod.inputType = protoTypeMap.toJavaTypeName(methodProto.getInputType()); ctxMethod.outputType = protoTypeMap.toJavaTypeName(methodProto.getOutputType()); ctxMethod.deprecated = methodProto.getOptions() != null && methodProto.getOptions().getDeprecated(); ctxMethod.javaDoc = getJavaDoc(getComments(location), METHOD_JAVADOC_PREFIX); ctx.methods.add(ctxMethod); } }); return ctx; }
Example #14
Source File: AbstractGenerator.java From sofa-rpc with Apache License 2.0 | 4 votes |
private MethodContext buildMethodContext(MethodDescriptorProto methodProto, ProtoTypeMap typeMap, List<Location> locations, int methodNumber) { MethodContext methodContext = new MethodContext(); methodContext.setMethodName(lowerCaseFirst(methodProto.getName())); methodContext.setInputType(typeMap.toJavaTypeName(methodProto.getInputType())); methodContext.setOutputType(typeMap.toJavaTypeName(methodProto.getOutputType())); methodContext.setDeprecated(methodProto.getOptions() != null && methodProto.getOptions().getDeprecated()); methodContext.setManyInput(methodProto.getClientStreaming()); methodContext.setManyOutput(methodProto.getServerStreaming()); methodContext.setMethodNumber(methodNumber); Optional<Location> found = Optional.empty(); for (Location location : locations) { if (location.getPathCount() == METHOD_NUMBER_OF_PATHS && location.getPath(METHOD_NUMBER_OF_PATHS - 1) == methodNumber) { found = Optional.of(location); break; } } Location methodLocation = found .orElseGet(Location::getDefaultInstance); methodContext.setJavaDoc(getJavaDoc(getComments(methodLocation), getMethodJavaDocPrefix())); if (!methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { methodContext.setReactiveCallsMethodName("oneToOne"); methodContext.setGrpcCallsMethodName("asyncUnaryCall"); } if (!methodProto.getClientStreaming() && methodProto.getServerStreaming()) { methodContext.setReactiveCallsMethodName("oneToMany"); methodContext.setGrpcCallsMethodName("asyncServerStreamingCall"); } if (methodProto.getClientStreaming() && !methodProto.getServerStreaming()) { methodContext.setReactiveCallsMethodName("manyToOne"); methodContext.setGrpcCallsMethodName("asyncClientStreamingCall"); } if (methodProto.getClientStreaming() && methodProto.getServerStreaming()) { methodContext.setReactiveCallsMethodName("manyToMany"); methodContext.setGrpcCallsMethodName("asyncBidiStreamingCall"); } return methodContext; }