Search in sources :

Example 1 with ProtoTypeMap

use of com.salesforce.jprotoc.ProtoTypeMap in project dubbo by alibaba.

the class AbstractGenerator method generateFiles.

@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);
}
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) ProtoTypeMap(com.salesforce.jprotoc.ProtoTypeMap) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto)

Example 2 with ProtoTypeMap

use of com.salesforce.jprotoc.ProtoTypeMap 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)

Aggregations

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