Java 类com.google.protobuf.DescriptorProtos.FileOptions 实例源码

项目:saluki    文件:CommonProto2Java.java   
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;
}
项目:piezo    文件:TypeMap.java   
public static TypeMap of(FileDescriptorProto protoFile) {
  ImmutableMap.Builder<String, JavaType> types = ImmutableMap.builder();
  FileOptions options = protoFile.getOptions();

  String protoPackage = "." + (protoFile.hasPackage() ?
      protoFile.getPackage() : "");
  String javaPackage = options.hasJavaPackage() ?
      options.getJavaPackage() : protoFile.hasPackage() ?
      protoFile.getPackage() : null;
  String enclosingClass = options.getJavaMultipleFiles() ?
      null : options.hasJavaOuterClassname() ?
      options.getJavaOuterClassname() : createOuterJavaClassname(protoFile.getName());

  for (DescriptorProto message : protoFile.getMessageTypeList()) {
    types.put(protoPackage + "." + message.getName(),
        new JavaType(javaPackage, enclosingClass, message.getName()));
  }

  return new TypeMap(types.build());
}
项目:reactive-grpc    文件:ReactiveGrpcGenerator.java   
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());
}
项目:closure-templates    文件:JavaQualifiedNames.java   
static String getPackage(FileDescriptorProto file, ProtoFlavor flavor) {
  FileOptions fileOptions = file.getOptions();
  StringBuilder sb = new StringBuilder();
  if (fileOptions.hasJavaPackage()) {
    sb.append(fileOptions.getJavaPackage());
  } else {
    if (!file.getPackage().isEmpty()) {
      sb.append(file.getPackage());
    }
  }


  return sb.toString();
}
项目:closure-templates    文件:JavaQualifiedNames.java   
private static boolean multipleJavaFiles(FileDescriptorProto fd, ProtoFlavor flavor) {
  FileOptions options = fd.getOptions();
  switch (flavor) {
    case PROTO2:
      return options.getJavaMultipleFiles();
    default:
      throw new AssertionError();
  }
}
项目:fuchsia    文件:ProtoGenerator.java   
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, "");
    }
}
项目:play-store-api    文件:Descriptors.java   
/** Get the {@code FileOptions}, defined in {@code descriptor.proto}. */
public FileOptions getOptions() { return proto.getOptions(); }
项目:Beam    文件:Descriptors.java   
/**
 * Get the {@code FileOptions}, defined in {@code descriptor.proto}.
 */
public FileOptions getOptions () {
    return proto.getOptions ();
}
项目:protobuf-el    文件:SourceInfoProtoFileParser.java   
@Override
public void exitFileOption(final FileOptionContext ctx) {
  super.exitFileOption(ctx);

  if (ctx.customFileOption() != null) {
    final CustomOptionContext customOptionCtx = ctx.customFileOption().customOption();

    locationBuilder.addLocation().setAllSpan(ctx)
        .addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER);

    final int optionIndex =
        (treatStandardOptionAsUninterpreted ? getTotalFieldCount(fileOptionsBuilder)
            : fileOptionsBuilder.getUninterpretedOptionCount()) - 1;

    locationBuilder.addLocationClone().addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER)
        .addPath(optionIndex);

    locationBuilder.addLocationClone().clearComments()
        .addPath(UninterpretedOption.NAME_FIELD_NUMBER)
        .setAllSpan(customOptionCtx.customOptionName());

    int i = -1;

    for (final CustomOptionNamePartContext namePart : customOptionCtx.customOptionName()
        .customOptionNamePart()) {
      locationBuilder.addLocation().addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
          .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
          .addPath(UninterpretedOption.NAME_FIELD_NUMBER).addPath(++i).setAllSpan(namePart);

      locationBuilder
          .addLocationClone()
          .addPath(UninterpretedOption.NamePart.NAME_PART_FIELD_NUMBER)
          .setAllSpan(
              namePart.customOptionNamePartId() == null ? namePart.identifier() : namePart
                  .customOptionNamePartId());
    }

    // customOption value locations: can be scalar or aggregate!

    final CustomOptionValueContext customOptionValue = customOptionCtx.customOptionValue();
    int valuePath;

    if (customOptionValue.optionAggregateValue() != null) {
      valuePath = UninterpretedOption.AGGREGATE_VALUE_FIELD_NUMBER;
    } else {
      final OptionScalarValueContext optionScalarValue = customOptionValue.optionScalarValue();

      if (optionScalarValue.doubleValue() != null) {
        valuePath = UninterpretedOption.DOUBLE_VALUE_FIELD_NUMBER;
      } else if (optionScalarValue.identifier() != null) {
        valuePath = UninterpretedOption.IDENTIFIER_VALUE_FIELD_NUMBER;
      } else if (optionScalarValue.StringLiteral() != null
          || optionScalarValue.BooleanLiteral() != null) {
        valuePath = UninterpretedOption.STRING_VALUE_FIELD_NUMBER;
      } else if (optionScalarValue.NegativeIntegerLiteral() != null) {
        valuePath = UninterpretedOption.NEGATIVE_INT_VALUE_FIELD_NUMBER;
      } else if (optionScalarValue.IntegerLiteral() != null) {
        valuePath = UninterpretedOption.POSITIVE_INT_VALUE_FIELD_NUMBER;
      } else { // we shouldn't arrive here!
        throw new RuntimeException("custom option value has unidentified type!");
      }
    }

    locationBuilder.addLocation().addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
        .addPath(valuePath).setAllSpan(customOptionValue);

    // should the aggregate locations be added here? BTW, protoc fails on aggregates!
  }
}
项目:protobuf-el    文件:SourceInfoProtoFileParser.java   
private void doStandardOptionSource(final StandardFileOptionContext ctx,
    final int customOptionValueType) {
  final FileOptionContext parentCtx = (FileOptionContext) ctx.getParent();

  locationBuilder.addLocation().setAllSpan(parentCtx)
      .addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER);

  if (treatStandardOptionAsUninterpreted) {
    final int optionIndex = getTotalFieldCount(fileOptionsBuilder) - 1;

    locationBuilder.addLocation().comments(parentCtx)
        .addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
        .setAllSpan(parentCtx);

    locationBuilder.addLocation().addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
        .addPath(UninterpretedOption.NAME_FIELD_NUMBER)
        .setAllSpan((TerminalNode) ctx.getChild(0));

    locationBuilder.addLocation().addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
        .addPath(UninterpretedOption.NAME_FIELD_NUMBER).addPath(0)
        .setAllSpan((TerminalNode) ctx.getChild(0));

    locationBuilder.addLocation().addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
        .addPath(UninterpretedOption.NAME_FIELD_NUMBER).addPath(0)
        .addPath(UninterpretedOption.NamePart.NAME_PART_FIELD_NUMBER)
        .setAllSpan((TerminalNode) ctx.getChild(0));

    locationBuilder.addLocation().addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(FileOptions.UNINTERPRETED_OPTION_FIELD_NUMBER).addPath(optionIndex)
        .addPath(customOptionValueType).setAllSpan(ctx.getChild(2));
  } else {
    locationBuilder
        .addLocation()
        .comments(parentCtx)
        .addPath(FileDescriptorProto.OPTIONS_FIELD_NUMBER)
        .addPath(
            FileOptions.getDescriptor().findFieldByName(ctx.getChild(0).getText()).getNumber())
        .setAllSpan(ctx.getChild(2));
  }
}
项目:protobuf-el    文件:Scopes.java   
public FileOptions.Builder getFileOptions() {
  return currentScope.getFileOptions();
}
项目:protobuf-el    文件:Scopes.java   
protected FileOptions.Builder getFileOptions() {
  throw new RuntimeException(NOT_APPLICABLE_IN_CURRENT_SCOPE);
}
项目:protobuf-el    文件:Scopes.java   
@Override
protected FileOptions.Builder getFileOptions() {
  return protoBuilder.getOptionsBuilder();
}
项目:protobuf-el    文件:Scopes.java   
@Override
protected FileOptions.Builder getFileOptions() {
  return getParent().getFileOptions();
}
项目:protobuf-el    文件:FileDescriptorEx.java   
public FileOptions getOptions() {
  return delegate.getOptions();
}
项目:piezo    文件:ProtoFileHandler.java   
@VisibleForTesting
static String inferJavaPackage(FileDescriptorProto file) {
  FileOptions options = file.getOptions();
  return options.hasJavaPackage() ?
      options.getJavaPackage() : file.hasPackage() ? file.getPackage() : null;
}