@@ -121,23 +121,31 @@ void java_bytecode_parse_treet::annotationt::element_value_pairt::output(
121
121
out << expr2java (value, ns);
122
122
}
123
123
124
- bool java_bytecode_parse_treet::does_annotation_exist (
124
+ // / Find an annotation given its name
125
+ // / \param annotations: A vector of annotationt
126
+ // / \param annotation_type_name: An irep_idt representing the name of the
127
+ // / annotation class, e.g. java::java.lang.SuppressWarnings
128
+ // / \return The first annotation with the given name in annotations if one
129
+ // / exists, an empty optionalt otherwise.
130
+ optionalt<java_bytecode_parse_treet::annotationt>
131
+ java_bytecode_parse_treet::find_annotation (
125
132
const annotationst &annotations,
126
133
const irep_idt &annotation_type_name)
127
134
{
128
- return
129
- std::find_if (
130
- annotations.begin (),
131
- annotations.end (),
132
- [&annotation_type_name](const annotationt &annotation)
133
- {
134
- if (annotation.type .id () != ID_pointer)
135
- return false ;
136
- typet type = annotation.type .subtype ();
137
- return
138
- type.id () == ID_symbol
139
- && to_symbol_type (type).get_identifier () == annotation_type_name;
140
- }) != annotations.end ();
135
+ const auto annotation_it = std::find_if (
136
+ annotations.begin (),
137
+ annotations.end (),
138
+ [&annotation_type_name](const annotationt &annotation)
139
+ {
140
+ if (annotation.type .id () != ID_pointer)
141
+ return false ;
142
+ const typet &type = annotation.type .subtype ();
143
+ return type.id () == ID_symbol &&
144
+ to_symbol_type (type).get_identifier () == annotation_type_name;
145
+ });
146
+ if (annotation_it == annotations.end ())
147
+ return {};
148
+ return *annotation_it;
141
149
}
142
150
143
151
void java_bytecode_parse_treet::methodt::output (std::ostream &out) const
0 commit comments