private ServiceContext buildServiceContext(ServiceDescriptorProto serviceProto, ProtoTypeMap typeMap, List<Location> locations,
                                               int serviceNumber) {
        ServiceContext serviceContext = new ServiceContext();
        serviceContext.setFileName(getClassPrefix() + serviceProto.getName() + getClassSuffix() + ".java");
        serviceContext.setClassName(getClassPrefix() + serviceProto.getName() + getClassSuffix());
        serviceContext.setServiceName(serviceProto.getName());
        serviceContext.setDeprecated(serviceProto.getOptions() != null && serviceProto.getOptions().getDeprecated());

        List<Location> allLocationsForService = new LinkedList<>();
        for (Location location : locations) {
            if (location.getPathCount() >= 2 &&
                    location.getPath(0) == FileDescriptorProto.SERVICE_FIELD_NUMBER &&
                    location.getPath(1) == serviceNumber) {
                allLocationsForService.add(location);
            }
        }

        Optional<Location> found = Optional.empty();
        for (Location location : allLocationsForService) {
            if (location.getPathCount() == SERVICE_NUMBER_OF_PATHS) {
                found = Optional.of(location);
                break;
            }
        }
        Location locationDefault = Location.getDefaultInstance();
        Location serviceLocation = found
                .orElseGet(new Supplier<Location>() {
                    @Override
                    public Location get() {
                        return locationDefault;
                    }
                });
        serviceContext.setJavaDoc(getJavaDoc(getComments(serviceLocation), getServiceJavaDocPrefix()));

        for (int methodNumber = 0; methodNumber < serviceProto.getMethodCount(); methodNumber++) {
            MethodContext methodContext = buildMethodContext(serviceProto.getMethod(methodNumber), typeMap, locations, methodNumber
            );
            serviceContext.getMethods().add(methodContext);
            serviceContext.getMethodTypes().add(methodContext.getInputType());
            serviceContext.getMethodTypes().add(methodContext.getOutputType());
        }
        return serviceContext;
    }
construct the context

@param serviceProto
@param typeMap
@param locations
@param serviceNumber
@return
compiler/src/main/java/com/alipay/sofa/gen/base/AbstractGenerator.java