@ -28,16 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include <google/protobuf/compiler/java/map_field.h>
# include "google/protobuf/compiler/java/map_field.h"
# include <google/protobuf/io/printer.h>
# include "google/protobuf/io/printer.h"
# include <google/protobuf/compiler/java/context.h>
# include "google/protobuf/compiler/java/context.h"
# include <google/protobuf/compiler/java/doc_comment.h>
# include "google/protobuf/compiler/java/doc_comment.h"
# include <google/protobuf/compiler/java/helpers.h>
# include "google/protobuf/compiler/java/helpers.h"
# include <google/protobuf/compiler/java/name_resolver.h>
# include "google/protobuf/compiler/java/name_resolver.h"
// Must be last.
// Must be last.
# include <google/protobuf/port_def.inc>
# include "google/protobuf/port_def.inc"
namespace google {
namespace google {
namespace protobuf {
namespace protobuf {
@ -88,9 +88,9 @@ std::string WireType(const FieldDescriptor* field) {
std : : string ( FieldTypeName ( field - > type ( ) ) ) ;
std : : string ( FieldTypeName ( field - > type ( ) ) ) ;
}
}
void SetMessageVariables ( const FieldDescriptor * descriptor , int messageBitIndex ,
void SetMessageVariables (
int builderBitIndex , const FieldGeneratorInfo * info ,
const FieldDescriptor * descriptor , int messageBitIndex , int builderBitIndex ,
Context * context ,
const FieldGeneratorInfo * info , Context * context ,
std : : map < std : : string , std : : string > * variables ) {
std : : map < std : : string , std : : string > * variables ) {
SetCommonFieldVariables ( descriptor , info , variables ) ;
SetCommonFieldVariables ( descriptor , info , variables ) ;
ClassNameResolver * name_resolver = context - > GetNameResolver ( ) ;
ClassNameResolver * name_resolver = context - > GetNameResolver ( ) ;
@ -120,13 +120,14 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
: " " ;
: " " ;
( * variables ) [ " value_null_check " ] =
( * variables ) [ " value_null_check " ] =
valueJavaType ! = JAVATYPE_ENUM & & IsReferenceType ( valueJavaType )
valueJavaType ! = JAVATYPE_ENUM & & IsReferenceType ( valueJavaType )
? " if (value == null) { \n "
? " if (value == null) { "
" throw new NullPointerException( \" map value \" ); \n "
" throw new NullPointerException( \" map value \" ); } "
" } \n "
: " " ;
: " " ;
if ( valueJavaType = = JAVATYPE_ENUM ) {
if ( valueJavaType = = JAVATYPE_ENUM ) {
// We store enums as Integers internally.
// We store enums as Integers internally.
( * variables ) [ " value_type " ] = " int " ;
( * variables ) [ " value_type " ] = " int " ;
variables - > insert (
{ " value_type_pass_through_nullness " , ( * variables ) [ " value_type " ] } ) ;
( * variables ) [ " boxed_value_type " ] = " java.lang.Integer " ;
( * variables ) [ " boxed_value_type " ] = " java.lang.Integer " ;
( * variables ) [ " value_wire_type " ] = WireType ( value ) ;
( * variables ) [ " value_wire_type " ] = WireType ( value ) ;
( * variables ) [ " value_default_value " ] =
( * variables ) [ " value_default_value " ] =
@ -134,13 +135,15 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
( * variables ) [ " value_enum_type " ] = TypeName ( value , name_resolver , false ) ;
( * variables ) [ " value_enum_type " ] = TypeName ( value , name_resolver , false ) ;
( * variables ) [ " value_enum_type_pass_through_nullness " ] =
variables - > insert (
pass_through_nullness + ( * variables ) [ " value_enum_type " ] ;
{ " value_enum_type_pass_through_nullness " ,
StrCat ( pass_through_nullness , ( * variables ) [ " value_enum_type " ] ) } ) ;
if ( SupportUnknownEnumValue ( descriptor - > file ( ) ) ) {
if ( SupportUnknownEnumValue ( descriptor - > file ( ) ) ) {
// Map unknown values to a special UNRECOGNIZED value if supported.
// Map unknown values to a special UNRECOGNIZED value if supported.
( * variables ) [ " unrecognized_value " ] =
variables - > insert (
( * variables ) [ " value_enum_type " ] + " .UNRECOGNIZED " ;
{ " unrecognized_value " ,
StrCat ( ( * variables ) [ " value_enum_type " ] , " .UNRECOGNIZED " ) } ) ;
} else {
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
// Map unknown values to the default value if we don't have UNRECOGNIZED.
( * variables ) [ " unrecognized_value " ] =
( * variables ) [ " unrecognized_value " ] =
@ -149,35 +152,48 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
} else {
} else {
( * variables ) [ " value_type " ] = TypeName ( value , name_resolver , false ) ;
( * variables ) [ " value_type " ] = TypeName ( value , name_resolver , false ) ;
( * variables ) [ " value_type_pass_through_nullness " ] =
variables - > insert (
( IsReferenceType ( valueJavaType ) ? pass_through_nullness : " " ) +
{ " value_type_pass_through_nullness " ,
( * variables ) [ " value_type " ] ;
StrCat (
( IsReferenceType ( valueJavaType ) ? pass_through_nullness : " " ) ,
( * variables ) [ " value_type " ] ) } ) ;
( * variables ) [ " boxed_value_type " ] = TypeName ( value , name_resolver , true ) ;
( * variables ) [ " boxed_value_type " ] = TypeName ( value , name_resolver , true ) ;
( * variables ) [ " value_wire_type " ] = WireType ( value ) ;
( * variables ) [ " value_wire_type " ] = WireType ( value ) ;
( * variables ) [ " value_default_value " ] =
( * variables ) [ " value_default_value " ] =
DefaultValue ( value , true , name_resolver ) ;
DefaultValue ( value , true , name_resolver ) ;
}
}
( * variables ) [ " type_parameters " ] =
variables - > insert (
( * variables ) [ " boxed_key_type " ] + " , " + ( * variables ) [ " boxed_value_type " ] ;
{ " type_parameters " , StrCat ( ( * variables ) [ " boxed_key_type " ] , " , " ,
( * variables ) [ " boxed_value_type " ] ) } ) ;
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
// by the proto compiler
( * variables ) [ " deprecation " ] =
( * variables ) [ " deprecation " ] =
descriptor - > options ( ) . deprecated ( ) ? " @java.lang.Deprecated " : " " ;
descriptor - > options ( ) . deprecated ( ) ? " @java.lang.Deprecated " : " " ;
( * variables ) [ " kt_deprecation " ] =
variables - > insert (
{ " kt_deprecation " ,
descriptor - > options ( ) . deprecated ( )
descriptor - > options ( ) . deprecated ( )
? " @kotlin.Deprecated(message = \" Field " + ( * variables ) [ " name " ] +
? StrCat ( " @kotlin.Deprecated(message = \" Field " ,
" is deprecated \" ) "
( * variables ) [ " name " ] , " is deprecated \" ) " )
: " " ;
: " " } ) ;
( * variables ) [ " on_changed " ] = " onChanged(); " ;
( * variables ) [ " on_changed " ] = " onChanged(); " ;
( * variables ) [ " default_entry " ] =
variables - > insert (
( * variables ) [ " capitalized_name " ] + " DefaultEntryHolder.defaultEntry " ;
{ " default_entry " , StrCat ( ( * variables ) [ " capitalized_name " ] ,
( * variables ) [ " map_field_parameter " ] = ( * variables ) [ " default_entry " ] ;
" DefaultEntryHolder.defaultEntry " ) } ) ;
variables - > insert ( { " map_field_parameter " , ( * variables ) [ " default_entry " ] } ) ;
( * variables ) [ " descriptor " ] =
( * variables ) [ " descriptor " ] =
name_resolver - > GetImmutableClassName ( descriptor - > file ( ) ) + " .internal_ " +
name_resolver - > GetImmutableClassName ( descriptor - > file ( ) ) + " .internal_ " +
UniqueFileScopeIdentifier ( descriptor - > message_type ( ) ) + " _descriptor, " ;
UniqueFileScopeIdentifier ( descriptor - > message_type ( ) ) + " _descriptor, " ;
( * variables ) [ " ver " ] = GeneratedCodeVersionSuffix ( ) ;
( * variables ) [ " ver " ] = GeneratedCodeVersionSuffix ( ) ;
( * variables ) [ " get_has_field_bit_builder " ] = GenerateGetBit ( builderBitIndex ) ;
( * variables ) [ " get_has_field_bit_from_local " ] =
GenerateGetBitFromLocal ( builderBitIndex ) ;
( * variables ) [ " set_has_field_bit_builder " ] =
GenerateSetBit ( builderBitIndex ) + " ; " ;
( * variables ) [ " clear_has_field_bit_builder " ] =
GenerateClearBit ( builderBitIndex ) + " ; " ;
}
}
} // namespace
} // namespace
@ -185,7 +201,11 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMapFieldGenerator : : ImmutableMapFieldGenerator (
ImmutableMapFieldGenerator : : ImmutableMapFieldGenerator (
const FieldDescriptor * descriptor , int messageBitIndex , int builderBitIndex ,
const FieldDescriptor * descriptor , int messageBitIndex , int builderBitIndex ,
Context * context )
Context * context )
: descriptor_ ( descriptor ) , name_resolver_ ( context - > GetNameResolver ( ) ) {
: descriptor_ ( descriptor ) ,
message_bit_index_ ( messageBitIndex ) ,
builder_bit_index_ ( builderBitIndex ) ,
name_resolver_ ( context - > GetNameResolver ( ) ) ,
context_ ( context ) {
SetMessageVariables ( descriptor , messageBitIndex , builderBitIndex ,
SetMessageVariables ( descriptor , messageBitIndex , builderBitIndex ,
context - > GetFieldGeneratorInfo ( descriptor ) , context ,
context - > GetFieldGeneratorInfo ( descriptor ) , context ,
& variables_ ) ;
& variables_ ) ;
@ -193,6 +213,14 @@ ImmutableMapFieldGenerator::ImmutableMapFieldGenerator(
ImmutableMapFieldGenerator : : ~ ImmutableMapFieldGenerator ( ) { }
ImmutableMapFieldGenerator : : ~ ImmutableMapFieldGenerator ( ) { }
int ImmutableMapFieldGenerator : : GetMessageBitIndex ( ) const {
return message_bit_index_ ;
}
int ImmutableMapFieldGenerator : : GetBuilderBitIndex ( ) const {
return builder_bit_index_ ;
}
int ImmutableMapFieldGenerator : : GetNumBitsForMessage ( ) const { return 0 ; }
int ImmutableMapFieldGenerator : : GetNumBitsForMessage ( ) const { return 0 ; }
int ImmutableMapFieldGenerator : : GetNumBitsForBuilder ( ) const { return 1 ; }
int ImmutableMapFieldGenerator : : GetNumBitsForBuilder ( ) const { return 1 ; }
@ -254,15 +282,15 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" $deprecation$ \n "
" $deprecation$$value_type_pass_through_nullness$ "
" $value_type$ $ {$get$capitalized_name$ValueOrDefault$}$( \n "
" ${$get$capitalized_name$ValueOrDefault$}$( \n "
" $key_type$ key, \n "
" $key_type$ key, \n "
" $value_type$ defaultValue); \n " ) ;
" $value_type_pass_through_nullness $ defaultValue); \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print (
" $deprecation$ \n "
variables_ ,
" $value_type$ ${$get$capitalized_name$ValueOrThrow$}$( \n "
" $deprecation$ $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n "
" $key_type$ key); \n " ) ;
" $key_type$ key); \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
}
}
@ -282,16 +310,15 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" $deprecation$ \n "
" $deprecation$$value_type_pass_through_nullness$ "
" $value_type_pass_through_nullness$ "
" ${$get$capitalized_name$OrDefault$}$( \n "
" ${$get$capitalized_name$OrDefault$}$( \n "
" $key_type$ key, \n "
" $key_type$ key, \n "
" $value_type_pass_through_nullness$ defaultValue); \n " ) ;
" $value_type_pass_through_nullness$ defaultValue); \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print (
" $deprecation$ \n "
variables_ ,
" $value_type$ ${$get$capitalized_name$OrThrow$}$( \n "
" $deprecation$ $value_type$ ${$get$capitalized_name$OrThrow$}$(\n "
" $key_type$ key); \n " ) ;
" $key_type$ key); \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
}
}
@ -312,6 +339,7 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const {
" $value_default_value$); \n "
" $value_default_value$); \n "
" } \n " ) ;
" } \n " ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" @SuppressWarnings( \" serial \" ) \n "
" private com.google.protobuf.MapField< \n "
" private com.google.protobuf.MapField< \n "
" $type_parameters$> $name$_; \n "
" $type_parameters$> $name$_; \n "
" private com.google.protobuf.MapField<$type_parameters$> \n "
" private com.google.protobuf.MapField<$type_parameters$> \n "
@ -347,10 +375,11 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const {
void ImmutableMapFieldGenerator : : GenerateBuilderMembers (
void ImmutableMapFieldGenerator : : GenerateBuilderMembers (
io : : Printer * printer ) const {
io : : Printer * printer ) const {
printer - > Print ( variables_ ,
printer - > Print (
variables_ ,
" private com.google.protobuf.MapField< \n "
" private com.google.protobuf.MapField< \n "
" $type_parameters$> $name$_; \n "
" $type_parameters$> $name$_; \n "
" private com.google.protobuf.MapField<$type_parameters$> \n "
" $deprecation$ private com.google.protobuf.MapField<$type_parameters$>\n "
" internalGet$capitalized_name$() { \n "
" internalGet$capitalized_name$() { \n "
" if ($name$_ == null) { \n "
" if ($name$_ == null) { \n "
" return com.google.protobuf.MapField.emptyMapField( \n "
" return com.google.protobuf.MapField.emptyMapField( \n "
@ -358,9 +387,8 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" } \n "
" } \n "
" return $name$_; \n "
" return $name$_; \n "
" } \n "
" } \n "
" private com.google.protobuf.MapField<$type_parameters$> \n "
" $deprecation$ private com.google.protobuf.MapField<$type_parameters$>\n "
" internalGetMutable$capitalized_name$() { \n "
" internalGetMutable$capitalized_name$() { \n "
" $on_changed$; \n "
" if ($name$_ == null) { \n "
" if ($name$_ == null) { \n "
" $name$_ = com.google.protobuf.MapField.newMapField( \n "
" $name$_ = com.google.protobuf.MapField.newMapField( \n "
" $map_field_parameter$); \n "
" $map_field_parameter$); \n "
@ -368,21 +396,24 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" if (!$name$_.isMutable()) { \n "
" if (!$name$_.isMutable()) { \n "
" $name$_ = $name$_.copy(); \n "
" $name$_ = $name$_.copy(); \n "
" } \n "
" } \n "
" $set_has_field_bit_builder$ \n "
" $on_changed$ \n "
" return $name$_; \n "
" return $name$_; \n "
" } \n " ) ;
" } \n " ) ;
GenerateMapGetters ( printer ) ;
GenerateMapGetters ( printer ) ;
printer - > Print ( variables_ ,
printer - > Print (
" $deprecation$ \n "
variables_ ,
" public Builder ${$clear$capitalized_name$$}$() { \n "
" $deprecation$public Builder ${$clear$capitalized_name$$}$() { \n "
" $clear_has_field_bit_builder$ \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" .clear(); \n "
" .clear(); \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" $deprecation$ \n "
" $deprecation$public Builder ${$remove$capitalized_name$$}$( \n "
" public Builder ${$remove$capitalized_name$$}$( \n "
" $key_type$ key) { \n "
" $key_type$ key) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
@ -390,6 +421,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
if ( GetJavaType ( ValueField ( descriptor_ ) ) = = JAVATYPE_ENUM ) {
if ( GetJavaType ( ValueField ( descriptor_ ) ) = = JAVATYPE_ENUM ) {
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
@ -399,6 +431,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" @java.lang.Deprecated \n "
" @java.lang.Deprecated \n "
" public java.util.Map<$boxed_key_type$, $value_enum_type$> \n "
" public java.util.Map<$boxed_key_type$, $value_enum_type$> \n "
" ${$getMutable$capitalized_name$$}$() { \n "
" ${$getMutable$capitalized_name$$}$() { \n "
" $set_has_field_bit_builder$ \n "
" return internalGetAdapted$capitalized_name$Map( \n "
" return internalGetAdapted$capitalized_name$Map( \n "
" internalGetMutable$capitalized_name$().getMutableMap()); \n "
" internalGetMutable$capitalized_name$().getMutableMap()); \n "
" } \n " ) ;
" } \n " ) ;
@ -412,9 +445,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $value_null_check$ \n "
" $value_null_check$ \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" .put(key, $name$ValueConverter.doBackward(value)); \n "
" .put(key, $name$ValueConverter.doBackward(value)); \n "
" $set_has_field_bit_builder$ \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
@ -423,9 +458,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" internalGetAdapted$capitalized_name$Map( \n "
" internalGetAdapted$capitalized_name$Map( \n "
" internalGetMutable$capitalized_name$().getMutableMap()) \n "
" internalGetMutable$capitalized_name$().getMutableMap()) \n "
" .putAll(values); \n "
" .putAll(values); \n "
" $set_has_field_bit_builder$ \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
if ( SupportUnknownEnumValue ( descriptor_ - > file ( ) ) ) {
if ( SupportUnknownEnumValue ( descriptor_ - > file ( ) ) ) {
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
@ -435,6 +472,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" @java.lang.Deprecated \n "
" @java.lang.Deprecated \n "
" public java.util.Map<$boxed_key_type$, $boxed_value_type$> \n "
" public java.util.Map<$boxed_key_type$, $boxed_value_type$> \n "
" ${$getMutable$capitalized_name$Value$}$() { \n "
" ${$getMutable$capitalized_name$Value$}$() { \n "
" $set_has_field_bit_builder$ \n "
" return internalGetMutable$capitalized_name$().getMutableMap(); \n "
" return internalGetMutable$capitalized_name$().getMutableMap(); \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
@ -448,9 +486,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $value_null_check$ \n "
" $value_null_check$ \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" .put(key, value); \n "
" .put(key, value); \n "
" $set_has_field_bit_builder$ \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
@ -458,6 +498,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" java.util.Map<$boxed_key_type$, $boxed_value_type$> values) { \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> values) { \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" .putAll(values); \n "
" .putAll(values); \n "
" $set_has_field_bit_builder$ \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
@ -471,29 +512,32 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" @java.lang.Deprecated \n "
" @java.lang.Deprecated \n "
" public java.util.Map<$type_parameters$> \n "
" public java.util.Map<$type_parameters$> \n "
" ${$getMutable$capitalized_name$$}$() { \n "
" ${$getMutable$capitalized_name$$}$() { \n "
" $set_has_field_bit_builder$ \n "
" return internalGetMutable$capitalized_name$().getMutableMap(); \n "
" return internalGetMutable$capitalized_name$().getMutableMap(); \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" $deprecation$ "
" $deprecation$public Builder ${$put$capitalized_name$$}$( \n "
" public Builder ${$put$capitalized_name$$}$( \n "
" $key_type$ key, \n "
" $key_type$ key, \n "
" $value_type$ value) { \n "
" $value_type$ value) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" $value_null_check$ \n "
" $value_null_check$ \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" .put(key, value); \n "
" .put(key, value); \n "
" $set_has_field_bit_builder$ \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print (
" $deprecation$ \n "
variables_ ,
" public Builder ${$putAll$capitalized_name$$}$( \n "
" $deprecation$ public Builder ${$putAll$capitalized_name$$}$(\n "
" java.util.Map<$type_parameters$> values) { \n "
" java.util.Map<$type_parameters$> values) { \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" internalGetMutable$capitalized_name$().getMutableMap() \n "
" .putAll(values); \n "
" .putAll(values); \n "
" $set_has_field_bit_builder$ \n "
" return this; \n "
" return this; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
@ -502,23 +546,24 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
void ImmutableMapFieldGenerator : : GenerateMapGetters (
void ImmutableMapFieldGenerator : : GenerateMapGetters (
io : : Printer * printer ) const {
io : : Printer * printer ) const {
printer - > Print ( variables_ ,
printer - > Print (
" $deprecation$ \n "
variables_ ,
" public int ${$get$capitalized_name$Count$}$() { \n "
" $deprecation$ public int ${$get$capitalized_name$Count$}$() {\n "
" return internalGet$capitalized_name$().getMap().size(); \n "
" return internalGet$capitalized_name$().getMap().size(); \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
" $deprecation$ \n "
" @java.lang.Override \n "
" @java.lang.Override \n "
" public boolean ${$contains$capitalized_name$$}$( \n "
" $deprecation$ public boolean ${$contains$capitalized_name$$}$(\n "
" $key_type$ key) { \n "
" $key_type$ key) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" return internalGet$capitalized_name$().getMap().containsKey(key); \n "
" return internalGet$capitalized_name$().getMap().containsKey(key); \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
if ( GetJavaType ( ValueField ( descriptor_ ) ) = = JAVATYPE_ENUM ) {
if ( GetJavaType ( ValueField ( descriptor_ ) ) = = JAVATYPE_ENUM ) {
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" /** \n "
" /** \n "
@ -534,19 +579,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public java.util.Map<$boxed_key_type$, "
" public java.util.Map<$boxed_key_type$, $value_enum_type$>\n "
" $value_enum_type$> \n "
" ${$get$capitalized_name$Map$}$() { \n "
" ${$get$capitalized_name$Map$}$() { \n "
" return internalGetAdapted$capitalized_name$Map( \n "
" return internalGetAdapted$capitalized_name$Map( \n "
" internalGet$capitalized_name$().getMap()); "
" internalGet$capitalized_name$().getMap()); "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public $value_enum_type_pass_through_nullness$ "
" public $value_enum_type_pass_through_nullness$ "
" ${$get$capitalized_name$OrDefault$}$( \n "
" ${$get$capitalized_name$OrDefault$}$( \n "
" $key_type$ key, \n "
" $key_type$ key, \n "
" $value_enum_type_pass_through_nullness$ defaultValue) { \n "
" $value_enum_type_pass_through_nullness$ defaultValue) { \n "
@ -558,12 +603,12 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" : defaultValue; \n "
" : defaultValue; \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public $value_enum_type$ get$capitalized_name$OrThrow( \n "
" public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$( \n "
" $key_type$ key) { \n "
" $key_type$ key) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map = \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map = \n "
@ -574,6 +619,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" return $name$ValueConverter.doForward(map.get(key)); \n "
" return $name$ValueConverter.doForward(map.get(key)); \n "
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
if ( SupportUnknownEnumValue ( descriptor_ - > file ( ) ) ) {
if ( SupportUnknownEnumValue ( descriptor_ - > file ( ) ) ) {
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
@ -588,11 +634,10 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print (
printer - > Print ( variables_ ,
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public java.util.Map<$boxed_key_type$, "
" public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n "
" $boxed_value_type$> \n "
" ${$get$capitalized_name$ValueMap$}$() { \n "
" ${$get$capitalized_name$ValueMap$}$() { \n "
" return internalGet$capitalized_name$().getMap(); \n "
" return internalGet$capitalized_name$().getMap(); \n "
" } \n " ) ;
" } \n " ) ;
@ -601,10 +646,10 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public $value_type_pass_through_nullness$ "
" public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n "
" ${$get$capitalized_name$ValueOrDefault$}$( \n "
" $key_type$ key, \n "
" $key_type$ key, \n "
" $value_type$ defaultValue) { \n "
" $value_type_pass_through_nullness $ defaultValue) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map = \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map = \n "
" internalGet$capitalized_name$().getMap(); \n "
" internalGet$capitalized_name$().getMap(); \n "
@ -615,8 +660,8 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public $value_type$ "
" public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n "
" ${$get$capitalized_name$ValueOrThrow$}$( \n "
" $key_type$ key) { \n "
" $key_type$ key) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map = \n "
" java.util.Map<$boxed_key_type$, $boxed_value_type$> map = \n "
@ -643,8 +688,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public java.util.Map<$type_parameters$> "
" public java.util.Map<$type_parameters$> "
" ${$get$capitalized_name$Map$}$() { \n "
" ${$get$capitalized_name$Map$}$() { \n "
" return internalGet$capitalized_name$().getMap(); \n "
" return internalGet$capitalized_name$().getMap(); \n "
" } \n " ) ;
" } \n " ) ;
@ -653,10 +697,10 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer - > Print (
printer - > Print (
variables_ ,
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public $value_type_pass_through_nullness$ "
" public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n "
" ${$get$capitalized_name$OrDefault$}$( \n "
" $key_type$ key, \n "
" $key_type$ key, \n "
" $value_type$ defaultValue) { \n "
" $value_type_pass_through_nullness $ defaultValue) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" java.util.Map<$type_parameters$> map = \n "
" java.util.Map<$type_parameters$> map = \n "
" internalGet$capitalized_name$().getMap(); \n "
" internalGet$capitalized_name$().getMap(); \n "
@ -664,10 +708,10 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" } \n " ) ;
" } \n " ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
printer - > Annotate ( " { " , " } " , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
WriteFieldDocComment ( printer , descriptor_ ) ;
printer - > Print ( variables_ ,
printer - > Print (
variables_ ,
" @java.lang.Override \n "
" @java.lang.Override \n "
" $deprecation$ \n "
" $deprecation$public $value_type$ ${$get$capitalized_name$OrThrow$}$( \n "
" public $value_type$ ${$get$capitalized_name$OrThrow$}$( \n "
" $key_type$ key) { \n "
" $key_type$ key) { \n "
" $key_null_check$ \n "
" $key_null_check$ \n "
" java.util.Map<$type_parameters$> map = \n "
" java.util.Map<$type_parameters$> map = \n "
@ -775,6 +819,7 @@ void ImmutableMapFieldGenerator::GenerateInitializationCode(
void ImmutableMapFieldGenerator : : GenerateBuilderClearCode (
void ImmutableMapFieldGenerator : : GenerateBuilderClearCode (
io : : Printer * printer ) const {
io : : Printer * printer ) const {
// No need to clear the has-bit since we clear the bitField ints all at once.
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" internalGetMutable$capitalized_name$().clear(); \n " ) ;
" internalGetMutable$capitalized_name$().clear(); \n " ) ;
}
}
@ -783,14 +828,17 @@ void ImmutableMapFieldGenerator::GenerateMergingCode(
io : : Printer * printer ) const {
io : : Printer * printer ) const {
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" internalGetMutable$capitalized_name$().mergeFrom( \n "
" internalGetMutable$capitalized_name$().mergeFrom( \n "
" other.internalGet$capitalized_name$()); \n " ) ;
" other.internalGet$capitalized_name$()); \n "
" $set_has_field_bit_builder$ \n " ) ;
}
}
void ImmutableMapFieldGenerator : : GenerateBuildingCode (
void ImmutableMapFieldGenerator : : GenerateBuildingCode (
io : : Printer * printer ) const {
io : : Printer * printer ) const {
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
" if ($get_has_field_bit_from_local$) { \n "
" result.$name$_ = internalGet$capitalized_name$(); \n "
" result.$name$_ = internalGet$capitalized_name$(); \n "
" result.$name$_.makeImmutable(); \n " ) ;
" result.$name$_.makeImmutable(); \n "
" } \n " ) ;
}
}
void ImmutableMapFieldGenerator : : GenerateBuilderParsingCode (
void ImmutableMapFieldGenerator : : GenerateBuilderParsingCode (
@ -807,6 +855,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode(
" } else { \n "
" } else { \n "
" internalGetMutable$capitalized_name$().getMutableMap().put( \n "
" internalGetMutable$capitalized_name$().getMutableMap().put( \n "
" $name$__.getKey(), $name$__.getValue()); \n "
" $name$__.getKey(), $name$__.getValue()); \n "
" $set_has_field_bit_builder$ \n "
" } \n " ) ;
" } \n " ) ;
} else {
} else {
printer - > Print (
printer - > Print (
@ -815,10 +864,10 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode(
" $name$__ = input.readMessage( \n "
" $name$__ = input.readMessage( \n "
" $default_entry$.getParserForType(), extensionRegistry); \n "
" $default_entry$.getParserForType(), extensionRegistry); \n "
" internalGetMutable$capitalized_name$().getMutableMap().put( \n "
" internalGetMutable$capitalized_name$().getMutableMap().put( \n "
" $name$__.getKey(), $name$__.getValue()); \n " ) ;
" $name$__.getKey(), $name$__.getValue()); \n "
" $set_has_field_bit_builder$ \n " ) ;
}
}
}
}
void ImmutableMapFieldGenerator : : GenerateSerializationCode (
void ImmutableMapFieldGenerator : : GenerateSerializationCode (
io : : Printer * printer ) const {
io : : Printer * printer ) const {
printer - > Print ( variables_ ,
printer - > Print ( variables_ ,
@ -871,4 +920,4 @@ std::string ImmutableMapFieldGenerator::GetBoxedType() const {
} // namespace protobuf
} // namespace protobuf
} // namespace google
} // namespace google
# include <google/protobuf/port_undef.inc>
# include "google/protobuf/port_undef.inc"