Skip to content

Commit 34ff0bc

Browse files
Extract get_final_name_component/get_without_final_name_component
1 parent 30be0e7 commit 34ff0bc

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,16 @@ bool java_bytecode_convert_class(
989989
return true;
990990
}
991991

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+
9921002
/// For a given generic type parameter, check if there is a parameter in the
9931003
/// given vector of replacement parameters with a matching name. If yes,
9941004
/// replace the identifier of the parameter at hand by the identifier of
@@ -1008,19 +1018,17 @@ static void find_and_replace_parameter(
10081018
// get the name of the parameter, e.g., `T` from `java::Class::T`
10091019
const std::string &parameter_full_name =
10101020
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);
10131023

10141024
// check if there is a replacement parameter with the same name
10151025
const auto replacement_parameter_it = std::find_if(
10161026
replacement_parameters.begin(),
10171027
replacement_parameters.end(),
10181028
[&parameter_name](const java_generic_parametert &replacement_param) {
1019-
const std::string &replacement_parameter_full_name =
1020-
id2string(replacement_param.type_variable().get_identifier());
10211029
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()));
10241032
});
10251033

10261034
// if a replacement parameter was found, update the identifier
@@ -1032,10 +1040,9 @@ static void find_and_replace_parameter(
10321040
// the replacement parameter is a viable one, i.e., it comes from an outer
10331041
// class
10341042
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);
10391046

10401047
parameter.type_variable_ref().set_identifier(
10411048
replacement_parameter_full_name);

0 commit comments

Comments
 (0)