@@ -989,6 +989,16 @@ bool java_bytecode_convert_class(
989
989
return true ;
990
990
}
991
991
992
+ static std::string get_final_name_component (const std::string &name)
993
+ {
994
+ return name.substr (name.rfind (" ::" ) + 2 );
995
+ }
996
+
997
+ static std::string get_without_final_name_component (const std::string &name)
998
+ {
999
+ return name.substr (0 , name.rfind (" ::" ));
1000
+ }
1001
+
992
1002
// / For a given generic type parameter, check if there is a parameter in the
993
1003
// / given vector of replacement parameters with a matching name. If yes,
994
1004
// / replace the identifier of the parameter at hand by the identifier of
@@ -1008,19 +1018,17 @@ static void find_and_replace_parameter(
1008
1018
// get the name of the parameter, e.g., `T` from `java::Class::T`
1009
1019
const std::string ¶meter_full_name =
1010
1020
id2string (parameter.type_variable_ref ().get_identifier ());
1011
- const std::string & parameter_name =
1012
- parameter_full_name. substr (parameter_full_name. rfind ( " :: " ) + 2 );
1021
+ const std::string parameter_name =
1022
+ get_final_name_component (parameter_full_name);
1013
1023
1014
1024
// check if there is a replacement parameter with the same name
1015
1025
const auto replacement_parameter_it = std::find_if (
1016
1026
replacement_parameters.begin (),
1017
1027
replacement_parameters.end (),
1018
1028
[¶meter_name](const java_generic_parametert &replacement_param) {
1019
- const std::string &replacement_parameter_full_name =
1020
- id2string (replacement_param.type_variable ().get_identifier ());
1021
1029
return parameter_name ==
1022
- replacement_parameter_full_name. substr (
1023
- replacement_parameter_full_name. rfind ( " :: " ) + 2 );
1030
+ get_final_name_component (
1031
+ id2string (replacement_param. type_variable (). get_identifier ()) );
1024
1032
});
1025
1033
1026
1034
// if a replacement parameter was found, update the identifier
@@ -1032,10 +1040,9 @@ static void find_and_replace_parameter(
1032
1040
// the replacement parameter is a viable one, i.e., it comes from an outer
1033
1041
// class
1034
1042
PRECONDITION (
1035
- parameter_full_name.substr (0 , parameter_full_name.rfind (" ::" ))
1036
- .compare (
1037
- replacement_parameter_full_name.substr (
1038
- 0 , replacement_parameter_full_name.rfind (" ::" ))) > 0 );
1043
+ get_without_final_name_component (parameter_full_name)
1044
+ .compare (get_without_final_name_component (
1045
+ replacement_parameter_full_name)) > 0 );
1039
1046
1040
1047
parameter.type_variable_ref ().set_identifier (
1041
1048
replacement_parameter_full_name);
0 commit comments