@@ -99,23 +99,30 @@ void java_bytecode_parse_treet::annotationt::element_value_pairt::output(
9999 out << expr2java (value, ns);
100100}
101101
102- bool java_bytecode_parse_treet::does_annotation_exist (
102+ // / Find an annotation given its name
103+ // / \param annotations: A vector of annotationt
104+ // / \param annotation_type_name: An irep_idt representing the name of the
105+ // / annotation class, e.g. java::java.lang.SuppressWarnings
106+ // / \return The first annotation with the given name in annotations if one
107+ // / exists, an empty optionalt otherwise.
108+ optionalt<java_bytecode_parse_treet::annotationt>
109+ java_bytecode_parse_treet::find_annotation (
103110 const annotationst &annotations,
104111 const irep_idt &annotation_type_name)
105112{
106- return
107- std::find_if (
108- annotations.begin (),
109- annotations. end (),
110- [&annotation_type_name]( const annotationt &annotation )
111- {
112- if ( annotation.type .id () != ID_pointer)
113- return false ;
114- typet type = annotation. type . subtype () ;
115- return
116- type. id () == ID_symbol
117- && to_symbol_type (type). get_identifier () == annotation_type_name ;
118- }) != annotations. end () ;
113+ const auto annotation_it = std::find_if (
114+ annotations. begin (),
115+ annotations.end (),
116+ [&annotation_type_name]( const annotationt &annotation) {
117+ if (annotation. type . id () != ID_pointer )
118+ return false ;
119+ const typet &type = annotation.type .subtype ();
120+ return type. id () == ID_symbol &&
121+ to_symbol_type ( type). get_identifier () == annotation_type_name ;
122+ });
123+ if (annotation_it == annotations. end ())
124+ return {} ;
125+ return *annotation_it ;
119126}
120127
121128void java_bytecode_parse_treet::methodt::output (std::ostream &out) const
0 commit comments