private Map < String , TField > computeFieldNameMap ( Class < ? > clazz ) { final Map < String , TField > map = new HashMap <> ( ) ; if ( isTBase ( clazz ) ) { // Get the metaDataMap for this Thrift class @ SuppressWarnings ( "unchecked" ) final Map < ? extends TFieldIdEnum , FieldMetaData > metaDataMap = FieldMetaData . getStructMetaDataMap ( ( Class < ? extends TBase < ? , ? > > ) clazz ) ; for ( Entry < ? extends TFieldIdEnum , FieldMetaData > e : metaDataMap . entrySet ( ) ) { final String fieldName = e . getKey ( ) . getFieldName ( ) ; final FieldMetaData metaData = e . getValue ( ) ; final FieldValueMetaData elementMetaData ; if ( metaData . valueMetaData . isContainer ( ) ) { if ( metaData . valueMetaData instanceof SetMetaData ) { elementMetaData = ( ( SetMetaData ) metaData . valueMetaData ) . elemMetaData ; } else if ( metaData . valueMetaData instanceof ListMetaData ) { elementMetaData = ( ( ListMetaData ) metaData . valueMetaData ) . elemMetaData ; } else if ( metaData . valueMetaData instanceof MapMetaData ) { elementMetaData = ( ( MapMetaData ) metaData . valueMetaData ) . valueMetaData ; } else { // Unrecognized container type, but let's still continue processing without // special enum support. elementMetaData = metaData . valueMetaData ; } } else { elementMetaData = metaData . valueMetaData ; } if ( elementMetaData instanceof EnumMetaData ) { classMap . put ( fieldName , ( ( EnumMetaData ) elementMetaData ) . enumClass ) ; } else if ( elementMetaData instanceof StructMetaData ) { classMap . put ( fieldName , ( ( StructMetaData ) elementMetaData ) . structClass ) ; } // Workaround a bug in the generated thrift message read() // method by mapping the ENUM type to the INT32 type // The thrift generated parsing code requires that, when expecting // a value of enum, we actually parse a value of type int32. The // generated read() method then looks up the enum value in a map. final byte type = TType . ENUM == metaData . valueMetaData . type ? TType . I32 : metaData . valueMetaData . type ; map . put ( fieldName , new TField ( fieldName , type , e . getKey ( ) . getThriftFieldId ( ) ) ) ; } } else { // TApplicationException map . put ( "message" , new TField ( "message" , ( byte ) 11 , ( short ) 1 ) ) ; map . put ( "type" , new TField ( "type" , ( byte ) 8 , ( short ) 2 ) ) ; } return map ; }
Compute a new field name map for the current thrift message we are parsing .