com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location Java Examples

The following examples show how to use com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location. 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: ReactiveGrpcGenerator.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #2
Source File: ReactiveGrpcGenerator.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #3
Source File: AbstractGenerator.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #4
Source File: ReactiveGrpcGenerator.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private String getComments(Location location) {
    return location.getLeadingComments().isEmpty() ? location.getTrailingComments() : location.getLeadingComments();
}
 
Example #5
Source File: AbstractGenerator.java    From sofa-rpc with Apache License 2.0 2 votes vote down vote up
/**
 * 注释
 *
 * @param location
 * @return
 */
private String getComments(Location location) {
    return location.getLeadingComments().isEmpty() ? location.getTrailingComments() : location
        .getLeadingComments();
}