AAPT2: Rename to match new style
Use Google3 naming style to match new
projects' and open source google projects' style.
Preferred to do this in a massive CL so as to avoid
style inconsistencies that plague legacy code bases.
This is a relatively NEW code base, may as well keep
it up to date.
Test: name/style refactor - existing tests pass
Change-Id: Ie80ecb78d46ec53efdfca2336bb57d96cbb7fb87
diff --git a/tools/aapt2/compile/IdAssigner.cpp b/tools/aapt2/compile/IdAssigner.cpp
index 73eb066..17c22c5 100644
--- a/tools/aapt2/compile/IdAssigner.cpp
+++ b/tools/aapt2/compile/IdAssigner.cpp
@@ -15,13 +15,15 @@
*/
#include "compile/IdAssigner.h"
+
+#include <map>
+
+#include "android-base/logging.h"
+
#include "ResourceTable.h"
#include "process/IResourceTableConsumer.h"
#include "util/Util.h"
-#include <cassert>
-#include <map>
-
namespace aapt {
/**
@@ -29,44 +31,44 @@
* ResourceEntry,
* as long as there is no existing ID or the ID is the same.
*/
-static bool assignId(IDiagnostics* diag, const ResourceId& id,
+static bool AssignId(IDiagnostics* diag, const ResourceId& id,
const ResourceName& name, ResourceTablePackage* pkg,
ResourceTableType* type, ResourceEntry* entry) {
- if (pkg->id.value() == id.packageId()) {
- if (!type->id || type->id.value() == id.typeId()) {
- type->id = id.typeId();
+ if (pkg->id.value() == id.package_id()) {
+ if (!type->id || type->id.value() == id.type_id()) {
+ type->id = id.type_id();
- if (!entry->id || entry->id.value() == id.entryId()) {
- entry->id = id.entryId();
+ if (!entry->id || entry->id.value() == id.entry_id()) {
+ entry->id = id.entry_id();
return true;
}
}
}
- const ResourceId existingId(pkg->id.value(), type->id ? type->id.value() : 0,
- entry->id ? entry->id.value() : 0);
- diag->error(DiagMessage() << "can't assign ID " << id << " to resource "
- << name << " with conflicting ID " << existingId);
+ const ResourceId existing_id(pkg->id.value(), type->id ? type->id.value() : 0,
+ entry->id ? entry->id.value() : 0);
+ diag->Error(DiagMessage() << "can't assign ID " << id << " to resource "
+ << name << " with conflicting ID " << existing_id);
return false;
}
-bool IdAssigner::consume(IAaptContext* context, ResourceTable* table) {
- std::map<ResourceId, ResourceName> assignedIds;
+bool IdAssigner::Consume(IAaptContext* context, ResourceTable* table) {
+ std::map<ResourceId, ResourceName> assigned_ids;
for (auto& package : table->packages) {
- assert(package->id && "packages must have manually assigned IDs");
+ CHECK(bool(package->id)) << "packages must have manually assigned IDs";
for (auto& type : package->types) {
for (auto& entry : type->entries) {
const ResourceName name(package->name, type->type, entry->name);
- if (mAssignedIdMap) {
+ if (assigned_id_map_) {
// Assign the pre-assigned stable ID meant for this resource.
- const auto iter = mAssignedIdMap->find(name);
- if (iter != mAssignedIdMap->end()) {
- const ResourceId assignedId = iter->second;
+ const auto iter = assigned_id_map_->find(name);
+ if (iter != assigned_id_map_->end()) {
+ const ResourceId assigned_id = iter->second;
const bool result =
- assignId(context->getDiagnostics(), assignedId, name,
+ AssignId(context->GetDiagnostics(), assigned_id, name,
package.get(), type.get(), entry.get());
if (!result) {
return false;
@@ -76,14 +78,14 @@
if (package->id && type->id && entry->id) {
// If the ID is set for this resource, then reserve it.
- ResourceId resourceId(package->id.value(), type->id.value(),
- entry->id.value());
- auto result = assignedIds.insert({resourceId, name});
- const ResourceName& existingName = result.first->second;
+ ResourceId resource_id(package->id.value(), type->id.value(),
+ entry->id.value());
+ auto result = assigned_ids.insert({resource_id, name});
+ const ResourceName& existing_name = result.first->second;
if (!result.second) {
- context->getDiagnostics()->error(
+ context->GetDiagnostics()->Error(
DiagMessage() << "resource " << name << " has same ID "
- << resourceId << " as " << existingName);
+ << resource_id << " as " << existing_name);
return false;
}
}
@@ -91,20 +93,20 @@
}
}
- if (mAssignedIdMap) {
+ if (assigned_id_map_) {
// Reserve all the IDs mentioned in the stable ID map. That way we won't
// assign
// IDs that were listed in the map if they don't exist in the table.
- for (const auto& stableIdEntry : *mAssignedIdMap) {
- const ResourceName& preAssignedName = stableIdEntry.first;
- const ResourceId& preAssignedId = stableIdEntry.second;
- auto result = assignedIds.insert({preAssignedId, preAssignedName});
- const ResourceName& existingName = result.first->second;
- if (!result.second && existingName != preAssignedName) {
- context->getDiagnostics()->error(
- DiagMessage() << "stable ID " << preAssignedId << " for resource "
- << preAssignedName << " is already taken by resource "
- << existingName);
+ for (const auto& stable_id_entry : *assigned_id_map_) {
+ const ResourceName& pre_assigned_name = stable_id_entry.first;
+ const ResourceId& pre_assigned_id = stable_id_entry.second;
+ auto result = assigned_ids.insert({pre_assigned_id, pre_assigned_name});
+ const ResourceName& existing_name = result.first->second;
+ if (!result.second && existing_name != pre_assigned_name) {
+ context->GetDiagnostics()->Error(
+ DiagMessage() << "stable ID " << pre_assigned_id << " for resource "
+ << pre_assigned_name
+ << " is already taken by resource " << existing_name);
return false;
}
}
@@ -114,21 +116,21 @@
// if possible,
// unless those IDs have been reserved.
- const auto assignedIdsIterEnd = assignedIds.end();
+ const auto assigned_ids_iter_end = assigned_ids.end();
for (auto& package : table->packages) {
- assert(package->id && "packages must have manually assigned IDs");
+ CHECK(bool(package->id)) << "packages must have manually assigned IDs";
// Build a half filled ResourceId object, which will be used to find the
// closest matching
// reserved ID in the assignedId map. From that point the next available
// type ID can be
// found.
- ResourceId resourceId(package->id.value(), 0, 0);
- uint8_t nextExpectedTypeId = 1;
+ ResourceId resource_id(package->id.value(), 0, 0);
+ uint8_t next_expected_type_id = 1;
// Find the closest matching ResourceId that is <= the one with only the
// package set.
- auto nextTypeIter = assignedIds.lower_bound(resourceId);
+ auto next_type_iter = assigned_ids.lower_bound(resource_id);
for (auto& type : package->types) {
if (!type->id) {
// We need to assign a type ID. Iterate over the reserved IDs until we
@@ -136,41 +138,41 @@
// some type ID that is a distance of 2 greater than the last one we've
// seen.
// That means there is an available type ID between these reserved IDs.
- while (nextTypeIter != assignedIdsIterEnd) {
- if (nextTypeIter->first.packageId() != package->id.value()) {
+ while (next_type_iter != assigned_ids_iter_end) {
+ if (next_type_iter->first.package_id() != package->id.value()) {
break;
}
- const uint8_t typeId = nextTypeIter->first.typeId();
- if (typeId > nextExpectedTypeId) {
+ const uint8_t type_id = next_type_iter->first.type_id();
+ if (type_id > next_expected_type_id) {
// There is a gap in the type IDs, so use the missing one.
- type->id = nextExpectedTypeId++;
+ type->id = next_expected_type_id++;
break;
}
// Set our expectation to be the next type ID after the reserved one
// we
// just saw.
- nextExpectedTypeId = typeId + 1;
+ next_expected_type_id = type_id + 1;
// Move to the next reserved ID.
- ++nextTypeIter;
+ ++next_type_iter;
}
if (!type->id) {
// We must have hit the end of the reserved IDs and not found a gap.
// That means the next ID is available.
- type->id = nextExpectedTypeId++;
+ type->id = next_expected_type_id++;
}
}
- resourceId = ResourceId(package->id.value(), type->id.value(), 0);
- uint16_t nextExpectedEntryId = 0;
+ resource_id = ResourceId(package->id.value(), type->id.value(), 0);
+ uint16_t next_expected_entry_id = 0;
// Find the closest matching ResourceId that is <= the one with only the
// package
// and type set.
- auto nextEntryIter = assignedIds.lower_bound(resourceId);
+ auto next_entry_iter = assigned_ids.lower_bound(resource_id);
for (auto& entry : type->entries) {
if (!entry->id) {
// We need to assign an entry ID. Iterate over the reserved IDs until
@@ -179,32 +181,32 @@
// we've seen.
// That means there is an available entry ID between these reserved
// IDs.
- while (nextEntryIter != assignedIdsIterEnd) {
- if (nextEntryIter->first.packageId() != package->id.value() ||
- nextEntryIter->first.typeId() != type->id.value()) {
+ while (next_entry_iter != assigned_ids_iter_end) {
+ if (next_entry_iter->first.package_id() != package->id.value() ||
+ next_entry_iter->first.type_id() != type->id.value()) {
break;
}
- const uint16_t entryId = nextEntryIter->first.entryId();
- if (entryId > nextExpectedEntryId) {
+ const uint16_t entry_id = next_entry_iter->first.entry_id();
+ if (entry_id > next_expected_entry_id) {
// There is a gap in the entry IDs, so use the missing one.
- entry->id = nextExpectedEntryId++;
+ entry->id = next_expected_entry_id++;
break;
}
// Set our expectation to be the next type ID after the reserved one
// we
// just saw.
- nextExpectedEntryId = entryId + 1;
+ next_expected_entry_id = entry_id + 1;
// Move to the next reserved entry ID.
- ++nextEntryIter;
+ ++next_entry_iter;
}
if (!entry->id) {
// We must have hit the end of the reserved IDs and not found a gap.
// That means the next ID is available.
- entry->id = nextExpectedEntryId++;
+ entry->id = next_expected_entry_id++;
}
}
}