Skip to content

Commit 078dc0f

Browse files
author
svorenova
committed
Updating a utility function
To test for a new field lamba_method_ref for a lambda method handle
1 parent a8ac3d4 commit 078dc0f

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

unit/testing-utils/require_parse_tree.cpp

+21-31
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,38 @@
1111
/// Find in the parsed class a specific entry within the
1212
/// lambda_method_handle_map with a matching descriptor. Will fail if no
1313
/// matching lambda entry found.
14-
/// \param parsed_class: the class to inspect
15-
/// \param descriptor: the descriptor the lambda method should have
16-
/// \param entry_index: the number to skip (i.e. if multiple entries with the
17-
/// same descriptor
14+
/// \param parsed_class the class to inspect
15+
/// \param lambda_method_ref the reference/descriptor of the lambda method
16+
/// to which this lambda entry points to, must be unique
17+
/// \param method_type the descriptor the lambda method should have
1818
/// \return
1919
require_parse_tree::lambda_method_handlet
2020
require_parse_tree::require_lambda_entry_for_descriptor(
2121
const java_bytecode_parse_treet::classt &parsed_class,
22-
const std::string &descriptor,
23-
const size_t entry_index)
22+
const std::string &lambda_method_ref,
23+
const std::string &method_type)
2424
{
25-
REQUIRE(entry_index < parsed_class.lambda_method_handle_map.size());
2625
typedef java_bytecode_parse_treet::classt::lambda_method_handle_mapt::
2726
value_type lambda_method_entryt;
2827

29-
size_t matches_found = 0;
30-
31-
const auto matching_lambda_entry = std::find_if(
28+
INFO(
29+
"Looking for entry with lambda_method_ref: " << lambda_method_ref
30+
<< " and method_type: "
31+
<< method_type);
32+
std::vector<lambda_method_entryt> matches;
33+
std::copy_if(
3234
parsed_class.lambda_method_handle_map.begin(),
3335
parsed_class.lambda_method_handle_map.end(),
34-
[&descriptor, &matches_found, &entry_index](
35-
const lambda_method_entryt &entry) {
36-
if(entry.second.method_type == descriptor)
37-
{
38-
++matches_found;
39-
return matches_found == entry_index + 1;
40-
}
41-
return false;
36+
back_inserter(matches),
37+
[&method_type,
38+
&lambda_method_ref](const lambda_method_entryt &entry) { //NOLINT
39+
return (
40+
entry.second.method_type == method_type &&
41+
entry.second.lambda_method_ref == lambda_method_ref);
4242
});
43-
44-
INFO("Looking for descriptor: " << descriptor);
45-
std::ostringstream found_entries;
46-
for(const auto entry : parsed_class.lambda_method_handle_map)
47-
{
48-
found_entries << id2string(entry.first.first) << ": "
49-
<< id2string(entry.second.method_type) << std::endl;
50-
}
51-
INFO("Found descriptors:\n" << found_entries.str());
52-
53-
REQUIRE(matching_lambda_entry != parsed_class.lambda_method_handle_map.end());
54-
55-
return matching_lambda_entry->second;
43+
INFO("Number of matching lambda method entries: " << matches.size());
44+
REQUIRE(matches.size() == 1);
45+
return matches.at(0).second;
5646
}
5747

5848
/// Finds a specific method in the parsed class with a matching name.

unit/testing-utils/require_parse_tree.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ typedef java_bytecode_parse_treet::classt::lambda_method_handlet
2323

2424
lambda_method_handlet require_lambda_entry_for_descriptor(
2525
const java_bytecode_parse_treet::classt &parsed_class,
26-
const std::string &descriptor,
27-
const size_t entry_index = 0);
26+
const std::string &lambda_method_ref,
27+
const std::string &method_type);
2828

2929
typedef java_bytecode_parse_treet::methodt methodt;
3030

0 commit comments

Comments
 (0)