com.google.protobuf.DescriptorProtos.FileOptions Java Examples

The following examples show how to use com.google.protobuf.DescriptorProtos.FileOptions. 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: FileDescriptor.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
FileDescriptor(final FileDescriptorProto protoFile) {
    this.protoFile = protoFile;
    sanitizedProtoFileName = sanitizeFileName(protoFile.getName());
    protoPackageName = protoFile.hasPackage() ? protoFile.getPackage() : null;

    if (protoFile.hasOptions()) {
        final FileOptions fileOptions = protoFile.getOptions();
        deprecated = fileOptions.hasDeprecated() && fileOptions.getDeprecated();
        multipleClassFiles = fileOptions.hasJavaMultipleFiles() && fileOptions.getJavaMultipleFiles();
        javaPackageName = fileOptions.hasJavaPackage() ? fileOptions.getJavaPackage() : null;
        outerClassName = fileOptions.hasJavaOuterClassname() ? fileOptions.getJavaOuterClassname() : null;
    } else {
        deprecated = false;
        multipleClassFiles = false;
        javaPackageName = null;
        outerClassName = null;
    }

    serviceClassBuilders = new ArrayList<>(protoFile.getServiceCount());
}
 
Example #2
Source File: CommonProto2Java.java    From saluki with Apache License 2.0 6 votes vote down vote up
private Pair<String, String> packageClassName(FileOptions options) {
  String packageName = null;
  String className = null;
  for (Map.Entry<FieldDescriptor, Object> entry : options.getAllFields().entrySet()) {
    if (entry.getKey().getName().equals("java_package")) {
      packageName = entry.getValue().toString();
    }
    if (entry.getKey().getName().equals("java_outer_classname")) {
      className = entry.getValue().toString();
    }
  }
  if (packageName != null && className != null) {
    return new ImmutablePair<String, String>(packageName, className);
  }
  return null;
}
 
Example #3
Source File: AbstractGenerator.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * fetch the package name
 *
 * @param proto
 * @return
 */
private String extractPackageName(FileDescriptorProto proto) {
    FileOptions options = proto.getOptions();
    if (options != null) {
        String javaPackage = options.getJavaPackage();
        if (!Strings.isNullOrEmpty(javaPackage)) {
            return javaPackage;
        }
    }

    return Strings.nullToEmpty(proto.getPackage());
}
 
Example #4
Source File: ReactiveGrpcGenerator.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private String extractPackageName(FileDescriptorProto proto) {
    FileOptions options = proto.getOptions();
    if (options != null) {
        String javaPackage = options.getJavaPackage();
        if (!Strings.isNullOrEmpty(javaPackage)) {
            return javaPackage;
        }
    }

    return Strings.nullToEmpty(proto.getPackage());
}
 
Example #5
Source File: ProtoGenerator.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
public void generateProtoFromDescriptor(FileDescriptor descriptor,
                                        Appendable out, Descriptor wrapperMessage) throws IOException {
    String package1 = descriptor.getPackage();
    if (package1 != null) {
        out.append("package " + package1 + ";\n");
    }

    FileOptions options = descriptor.getOptions();
    String javaPackage = options.getJavaPackage();
    if (javaPackage != null) {
        out.append("option java_package = \"" + javaPackage + "\";\n");
    }

    String javaOuterClassname = options.getJavaOuterClassname();
    if (javaOuterClassname != null) {
        out.append("option java_outer_classname = \"" + javaOuterClassname
                + "\";\n");
    }

    for (ServiceDescriptor serviceDescriptor : descriptor.getServices()) {
        generateProtoFromDescriptor(serviceDescriptor, out);
    }

    for (Descriptor messageDescriptor : descriptor.getMessageTypes()) {
        if (wrapperMessage != null && messageDescriptor.equals(wrapperMessage)) {
            out.append("// This is the message you can send to this service (wrapper message):\n");
        }

        generateProtoFromDescriptor(messageDescriptor, out, "",
                new LinkedHashMap<Descriptor, Boolean>());
    }

    for (EnumDescriptor enumDescriptor : descriptor.getEnumTypes()) {
        generateProtoFromDescriptor(enumDescriptor, out, "");
    }
}
 
Example #6
Source File: Descriptors.java    From play-store-api with GNU General Public License v3.0 4 votes vote down vote up
/** Get the {@code FileOptions}, defined in {@code descriptor.proto}. */
public FileOptions getOptions() { return proto.getOptions(); }