Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Latest commit

 

History

History
74 lines (61 loc) · 4.71 KB

File metadata and controls

74 lines (61 loc) · 4.71 KB

+++ title = "Java Proto Names" weight = 655 linkTitle = "Generated Proto Names" description = "Names that are generated by the immutable API." type = "docs" +++

This document contains information on what the fully-qualified Java name of a proto is, based on the different proto options. This name corresponds to the package you need to import to use that message.

Immutable API Message Names { #immutable-api-message-names }

The names for protos generated by the immutable API (java_proto_library BUILD target) are listed in the following table.

java_api_version java_multiple_files java_alt_api_package java_package java_outer_classname Generated full message name
1 true Defined - $java_alt_api_package.$message
1 true Not defined Not defined com.google.protos.$package.proto2api.$message
1 true Not defined Defined $java_package.proto2api.$message
1 false Defined - Not defined $java_alt_api_package.$derived_outer_class.$message
1 false Defined - Defined $java_alt_api_package.$java_outer_classname.$message
1 false Not defined Not defined Not defined com.google.protos.$package.proto2api.$derived_outer_class.$message
1 false Not defined Not defined Defined com.google.protos.$package.proto2api.$java_outer_classname.$message
1 false Not defined Defined Not defined $java_package.proto2api.$derived_outer_class.$message
1 false Not defined Defined Defined $java_package.proto2api.$java_outer_classname.$message
2 true - Not defined - com.google.protos.$package.$message
2 true - Defined - $java_package.$message
2 false - Not defined Not defined com.google.protos.$package.$derived_outer_class.$message
2 false - Not defined Defined com.google.protos.$package.$java_outer_classname.$message
2 false - Defined Not defined $java_package.$derived_outer_class.$message
2 false - Defined Defined $java_package.$java_outer_classname.$message

Legend

  • - means either setting or not setting the option will not change the generated full message name.

  • $message is the actual name of the proto message.

  • $package is the name of the proto package. This is the name specified by the package directive in the proto file, which is usually at the top of the file.

  • $derived_outer_class is a name generated from the proto file name. Generally it's computed by removing punctuation from the file name and converting it to CamelCase. For example, if the proto is foo_bar.proto, the $derived_outer_class value is FooBar.

    If the generated class name would be the same as one of the messages defined in the proto file, derived_outer_class has OuterClass appended to it. For example, if the proto is foo_bar.proto and contains a FooBar message, the $derived_outer_class value is FooBarOuterClass. The same is true when using the v1 API, whether or not the class name would be the same as one of the messages defined.

  • All other $names are the values of the corresponding proto2 file options defined in the proto file.

Recommendation { #recommendation }

The recommended option to use is:

option java_multiple_files = true;

With java_multiple_files = true, the generated Java class for each message will be placed in a separate .java file. This makes it much easier to move messages from one .proto file to another. There is also an outer Java class generated for the .proto file itself. (The legend above explains how this outer class name is generated.)

The java_api_version option defaults to 2, but you can manually set it to 1 when necessary.