Search in sources :

Example 1 with Location

use of com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location in project dubbo by alibaba.

the class AbstractGenerator method buildServiceContext.

private ServiceContext buildServiceContext(ServiceDescriptorProto serviceProto, ProtoTypeMap typeMap, List<Location> locations, int serviceNumber) {
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.fileName = getClassPrefix() + serviceProto.getName() + getClassSuffix() + ".java";
    serviceContext.className = getClassPrefix() + serviceProto.getName() + getClassSuffix();
    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);
        serviceContext.methodTypes.add(methodContext.inputType);
        serviceContext.methodTypes.add(methodContext.outputType);
    }
    return serviceContext;
}
Also used : Arrays(java.util.Arrays) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) Set(java.util.Set) HtmlEscapers(com.google.common.html.HtmlEscapers) Generator(com.salesforce.jprotoc.Generator) Collectors(java.util.stream.Collectors) Location(com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location) PluginProtos(com.google.protobuf.compiler.PluginProtos) ProtoTypeMap(com.salesforce.jprotoc.ProtoTypeMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) List(java.util.List) GeneratorException(com.salesforce.jprotoc.GeneratorException) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto) FileOptions(com.google.protobuf.DescriptorProtos.FileOptions) Location(com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location)

Example 2 with Location

use of com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location in project dubbo by alibaba.

the class AbstractGenerator method buildMethodContext.

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;
}
Also used : Location(com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location)

Aggregations

Location (com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location)2 Strings (com.google.common.base.Strings)1 HtmlEscapers (com.google.common.html.HtmlEscapers)1 FileDescriptorProto (com.google.protobuf.DescriptorProtos.FileDescriptorProto)1 FileOptions (com.google.protobuf.DescriptorProtos.FileOptions)1 MethodDescriptorProto (com.google.protobuf.DescriptorProtos.MethodDescriptorProto)1 ServiceDescriptorProto (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto)1 PluginProtos (com.google.protobuf.compiler.PluginProtos)1 Generator (com.salesforce.jprotoc.Generator)1 GeneratorException (com.salesforce.jprotoc.GeneratorException)1 ProtoTypeMap (com.salesforce.jprotoc.ProtoTypeMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1