Class GeneratorNames

java.lang.Object
com.google.protobuf.GeneratorNames

public final class GeneratorNames extends Object
Class containing helper methods for predicting names of generated java classes.
  • Constructor Details

    • GeneratorNames

      private GeneratorNames()
  • Method Details

    • getFileJavaPackage

      public static String getFileJavaPackage(DescriptorProtos.FileDescriptorProtoOrBuilder file)
      Returns the generated package for the given file descriptor proto.
    • getFileJavaPackage

      public static String getFileJavaPackage(Descriptors.FileDescriptor file)
      Returns the generated package for the given file descriptor.
    • getDefaultJavaPackage

      static String getDefaultJavaPackage(DescriptorProtos.FileOptions fileOptions, String filePackage)
      Returns the default java package for the given file.
    • joinPackage

      static String joinPackage(String a, String b)
      Joins two package segments into a single package name with a dot separator.
    • getProto2ApiDefaultJavaPackage

      static String getProto2ApiDefaultJavaPackage(DescriptorProtos.FileOptions fileOptions, String filePackage)
      Returns the package name to use for a file that is being compiled as proto2-API. If the file is declared as proto1-API, this may involve using the alternate package name.
    • getFileClassName

      public static String getFileClassName(DescriptorProtos.FileDescriptorProtoOrBuilder file)
      Returns the generated unqualified outer file class name for the given file descriptor proto.
    • getFileClassName

      public static String getFileClassName(Descriptors.FileDescriptor file)
      Returns the generated unqualified outer file class name for the given file descriptor.
    • getFileClassNameImpl

      private static String getFileClassNameImpl(DescriptorProtos.FileDescriptorProtoOrBuilder file, JavaFeaturesProto.JavaFeatures resolvedFeatures)
    • getResolvedFileFeatures

      Returns the resolved features for the given descriptor proto.

      This method isn't actually naming-specific, but lives here for now because it's the only place it's needed. Once we have a better home for dealing with features in code generators, this should move.

    • getDefaultFileClassName

      static String getDefaultFileClassName(DescriptorProtos.FileDescriptorProtoOrBuilder file, boolean useOldOuterClassnameDefault)
      Returns the default unqualified file class name for the given file.
      Parameters:
      file - the file descriptor proto
      useOldOuterClassnameDefault - whether to use the old default for the outer classname
    • stripProto

      private static String stripProto(String filename)
    • hasConflictingClassName

      private static boolean hasConflictingClassName(DescriptorProtos.FileDescriptorProtoOrBuilder file, String name)
      Checks whether any generated classes conflict with the given name.
    • hasConflictingClassName

      private static boolean hasConflictingClassName(DescriptorProtos.DescriptorProto messageDesc, String name)
      Used by the other overload, descends recursively into messages.
    • underscoresToCamelCase

      static String underscoresToCamelCase(String input, boolean capitalizeNextLetter)
      Converts a name to camel-case.
      Parameters:
      input - the input string to convert
      capitalizeNextLetter - whether to capitalize the first letter
    • underscoresToCamelCase

      static String underscoresToCamelCase(String input)
    • getBytecodeClassName

      public static String getBytecodeClassName(Descriptors.Descriptor message)
      Returns the fully qualified Java bytecode class name for the given message descriptor.

      Nested classes will use '$' as the separator, rather than '.'.

    • getBytecodeClassName

      public static String getBytecodeClassName(Descriptors.EnumDescriptor enm)
      Returns the fully qualified Java bytecode class name for the given enum descriptor.

      Nested classes will use '$' as the separator, rather than '.'.

    • getBytecodeClassName

      static String getBytecodeClassName(Descriptors.ServiceDescriptor service)
      Returns the fully qualified Java bytecode class name for the given service descriptor.

      Nested classes will use '$' as the separator, rather than '.'.

    • getQualifiedFromBytecodeClassName

      static String getQualifiedFromBytecodeClassName(String bytecodeClassName)
    • getQualifiedClassName

      public static String getQualifiedClassName(Descriptors.Descriptor message)
      Returns the fully qualified Java class name for the given message descriptor.

      Nested classes will use '.' as the separator, rather than '$'.

    • getQualifiedClassName

      public static String getQualifiedClassName(Descriptors.EnumDescriptor enm)
      Returns the fully qualified Java class name for the given enum descriptor.

      Nested classes will use '.' as the separator, rather than '$'.

    • getQualifiedClassName

      public static String getQualifiedClassName(Descriptors.ServiceDescriptor service)
      Returns the fully qualified Java class name for the given service descriptor.

      Nested classes will use '.' as the separator, rather than '$'.

    • getClassFullName

      private static String getClassFullName(String nameWithoutPackage, Descriptors.FileDescriptor file, boolean isOwnFile)
    • getNestInFileClass

      private static boolean getNestInFileClass(Descriptors.FileDescriptor file, JavaFeaturesProto.JavaFeatures resolvedFeatures)
      Returns the nest_in_file_class behavior for a given set of features in a specific file.
    • getNestInFileClass

      public static boolean getNestInFileClass(Descriptors.Descriptor descriptor)
    • getNestInFileClass

      public static boolean getNestInFileClass(Descriptors.EnumDescriptor descriptor)
    • getNestInFileClass

      private static boolean getNestInFileClass(Descriptors.ServiceDescriptor descriptor)
    • stripPackageName

      static String stripPackageName(String fullName, Descriptors.FileDescriptor file)
      Returns the name of the given descriptor without the package name prefix.
    • getClassNameWithoutPackage

      static String getClassNameWithoutPackage(Descriptors.Descriptor message)
      Returns the name of the given message descriptor without the package name prefix.
    • getClassNameWithoutPackage

      static String getClassNameWithoutPackage(Descriptors.EnumDescriptor enm)
      Returns the name of the given enum descriptor without the package name prefix.
    • getClassNameWithoutPackage

      static String getClassNameWithoutPackage(Descriptors.ServiceDescriptor service)
      Returns the name of the given service descriptor without the package name prefix.