Finish moving oatdump to ClassAccessor

Moved one remaining part of oatdump/ to class accessor.

Bug: 79758018
Test: test-art-host

Change-Id: I7a1abfa9547658f1e9349c09f2c088bdc820af85
diff --git a/libdexfile/dex/class_accessor.h b/libdexfile/dex/class_accessor.h
index 0d87f93..6af907e 100644
--- a/libdexfile/dex/class_accessor.h
+++ b/libdexfile/dex/class_accessor.h
@@ -40,6 +40,10 @@
       return index_;
     }
 
+    uint32_t GetRawAccessFlags() const {
+      return access_flags_;
+    }
+
     uint32_t GetAccessFlags() const {
       return HiddenApiAccessFlags::RemoveFromDex(access_flags_);
     }
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index 235cd6e..4521e63 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -867,28 +867,28 @@
 
     VariableIndentationOutputStream vios(&os);
     ScopedIndentation indent1(&vios);
-    for (size_t class_def_index = 0;
-         class_def_index < dex_file->NumClassDefs();
-         class_def_index++) {
-      const DexFile::ClassDef& class_def = dex_file->GetClassDef(class_def_index);
-      const char* descriptor = dex_file->GetClassDescriptor(class_def);
-
+    for (ClassAccessor accessor : dex_file->GetClasses()) {
       // TODO: Support regex
+      const char* descriptor = accessor.GetDescriptor();
       if (DescriptorToDot(descriptor).find(options_.class_filter_) == std::string::npos) {
         continue;
       }
 
+      const uint16_t class_def_index = accessor.GetClassDefIndex();
       uint32_t oat_class_offset = oat_dex_file.GetOatClassOffset(class_def_index);
       const OatFile::OatClass oat_class = oat_dex_file.GetOatClass(class_def_index);
       os << StringPrintf("%zd: %s (offset=0x%08x) (type_idx=%d)",
-                         class_def_index, descriptor, oat_class_offset, class_def.class_idx_.index_)
+                         static_cast<ssize_t>(class_def_index),
+                         descriptor,
+                         oat_class_offset,
+                         accessor.GetClassIdx().index_)
          << " (" << oat_class.GetStatus() << ")"
          << " (" << oat_class.GetType() << ")\n";
       // TODO: include bitmap here if type is kOatClassSomeCompiled?
       if (options_.list_classes_) {
         continue;
       }
-      if (!DumpOatClass(&vios, oat_class, *dex_file, class_def, &stop_analysis)) {
+      if (!DumpOatClass(&vios, oat_class, *dex_file, accessor, &stop_analysis)) {
         success = false;
       }
       if (stop_analysis) {
@@ -1023,22 +1023,23 @@
   }
 
   bool DumpOatClass(VariableIndentationOutputStream* vios,
-                    const OatFile::OatClass& oat_class, const DexFile& dex_file,
-                    const DexFile::ClassDef& class_def, bool* stop_analysis) {
+                    const OatFile::OatClass& oat_class,
+                    const DexFile& dex_file,
+                    const ClassAccessor& class_accessor,
+                    bool* stop_analysis) {
     bool success = true;
     bool addr_found = false;
-    const uint8_t* class_data = dex_file.GetClassData(class_def);
-    if (class_data == nullptr) {  // empty class such as a marker interface?
-      vios->Stream() << std::flush;
-      return success;
-    }
-    ClassDataItemIterator it(dex_file, class_data);
-    it.SkipAllFields();
     uint32_t class_method_index = 0;
-    while (it.HasNextMethod()) {
-      if (!DumpOatMethod(vios, class_def, class_method_index, oat_class, dex_file,
-                         it.GetMemberIndex(), it.GetMethodCodeItem(),
-                         it.GetRawMemberAccessFlags(), &addr_found)) {
+    for (const ClassAccessor::Method& method : class_accessor.GetMethods()) {
+      if (!DumpOatMethod(vios,
+                         dex_file.GetClassDef(class_accessor.GetClassDefIndex()),
+                         class_method_index,
+                         oat_class,
+                         dex_file,
+                         method.GetIndex(),
+                         method.GetCodeItem(),
+                         method.GetRawAccessFlags(),
+                         &addr_found)) {
         success = false;
       }
       if (addr_found) {
@@ -1046,9 +1047,7 @@
         return success;
       }
       class_method_index++;
-      it.Next();
     }
-    DCHECK(!it.HasNext());
     vios->Stream() << std::flush;
     return success;
   }