bool has_annotation()

in source/model-generator/ModelGenerator.cpp [382:417]


bool has_annotation(
    const DexAnnotationSet* annotations_set,
    const std::string& expected_type,
    const std::optional<std::unordered_set<std::string>>& expected_values) {
  if (!annotations_set) {
    return false;
  }

  for (const auto& annotation : annotations_set->get_annotations()) {
    const DexType* annotation_type = annotation->type();
    if (!annotation_type || annotation_type->c_str() != expected_type) {
      continue;
    }

    // If we expect a certain value, check values of the current
    // annotation.
    if (expected_values && !expected_values->empty()) {
      for (const auto& element : annotation->anno_elems()) {
        if (expected_values->find(element.encoded_value->show()) !=
            expected_values->end()) {
          LOG(4,
              "Found annotation type {} value {}.",
              annotation_type->str(),
              element.encoded_value->show());
          return true;
        }
      }
    }

    // If we do not expect a certain value, return as we found the
    // annotation.
    return true;
  }

  return false;
}