Skip to content

Commit

Permalink
Fix some Java Lint naming errors
Browse files Browse the repository at this point in the history
This is a pure naming change made by find/replace in bash.

The current binary resources system is transliterated from C++ code, and
changes often trigger Lint errors.

Long-term the naming and spacing should be updated to follow Java
conventions.
  • Loading branch information
hoisie committed Mar 16, 2023
1 parent 1349544 commit bbcf7a4
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 69 deletions.
16 changes: 8 additions & 8 deletions resources/src/main/java/org/robolectric/res/android/Chunk.java
Expand Up @@ -7,12 +7,12 @@
import java.nio.ByteBuffer;
import org.robolectric.res.android.ResourceTypes.ResChunk_header;
import org.robolectric.res.android.ResourceTypes.ResStringPool_header;
import org.robolectric.res.android.ResourceTypes.ResTableStagedAliasEntry;
import org.robolectric.res.android.ResourceTypes.ResTableStagedAliasHeader;
import org.robolectric.res.android.ResourceTypes.ResTable_header;
import org.robolectric.res.android.ResourceTypes.ResTable_lib_entry;
import org.robolectric.res.android.ResourceTypes.ResTable_lib_header;
import org.robolectric.res.android.ResourceTypes.ResTable_package;
import org.robolectric.res.android.ResourceTypes.ResTable_staged_alias_entry;
import org.robolectric.res.android.ResourceTypes.ResTable_staged_alias_header;
import org.robolectric.res.android.ResourceTypes.ResTable_type;
import org.robolectric.res.android.ResourceTypes.WithOffset;

Expand Down Expand Up @@ -121,17 +121,17 @@ public ResTable_lib_entry asResTable_lib_entry() {
}
}

public ResTable_staged_alias_header asResTable_staged_alias_header() {
if (header_size() >= ResTable_staged_alias_header.SIZEOF) {
return new ResTable_staged_alias_header(device_chunk_.myBuf(), device_chunk_.myOffset());
public ResTableStagedAliasHeader asResTableStagedAliasHeader() {
if (header_size() >= ResTableStagedAliasHeader.SIZEOF) {
return new ResTableStagedAliasHeader(device_chunk_.myBuf(), device_chunk_.myOffset());
} else {
return null;
}
}

public ResTable_staged_alias_entry asResTable_staged_alias_entry() {
if (data_size() >= ResTable_staged_alias_entry.SIZEOF) {
return new ResTable_staged_alias_entry(
public ResTableStagedAliasEntry asResTableStagedAliasEntry() {
if (data_size() >= ResTableStagedAliasEntry.SIZEOF) {
return new ResTableStagedAliasEntry(
device_chunk_.myBuf(), device_chunk_.myOffset() + header_size());
} else {
return null;
Expand Down
Expand Up @@ -350,7 +350,7 @@ void BuildDynamicRefTable() {
// that compile against the framework.
for (ConfiguredPackage pkg : iter.packages_) {
for (Map.Entry<Integer, Integer> entry :
pkg.loaded_package_.GetAliasResourceIdMap().entrySet()) {
pkg.loaded_package_.getAliasResourceIdMap().entrySet()) {
iter2.dynamic_ref_table.addAlias(entry.getKey(), entry.getValue());
}
}
Expand Down
Expand Up @@ -102,11 +102,11 @@ int lookupResourceId(Ref<Integer> resId) {
int res = resId.get();
int packageId = Res_GETPACKAGE(res) + 1;

Integer alias_id = mAliasId.get(res);
if (alias_id != null) {
Integer aliasId = mAliasId.get(res);
if (aliasId != null) {
// Rewrite the resource id to its alias resource id. Since the alias resource id is a
// compile-time id, it still needs to be resolved further.
res = alias_id;
res = aliasId;
}

if (packageId == SYS_PACKAGE_ID || (packageId == APP_PACKAGE_ID && !mAppAsLib)) {
Expand Down
96 changes: 48 additions & 48 deletions resources/src/main/java/org/robolectric/res/android/LoadedArsc.java
Expand Up @@ -29,6 +29,8 @@
import org.robolectric.res.android.Idmap.LoadedIdmap;
import org.robolectric.res.android.ResourceTypes.IdmapEntry_header;
import org.robolectric.res.android.ResourceTypes.ResStringPool_header;
import org.robolectric.res.android.ResourceTypes.ResTableStagedAliasEntry;
import org.robolectric.res.android.ResourceTypes.ResTableStagedAliasHeader;
import org.robolectric.res.android.ResourceTypes.ResTable_entry;
import org.robolectric.res.android.ResourceTypes.ResTable_header;
import org.robolectric.res.android.ResourceTypes.ResTable_lib_entry;
Expand All @@ -37,8 +39,6 @@
import org.robolectric.res.android.ResourceTypes.ResTable_map_entry;
import org.robolectric.res.android.ResourceTypes.ResTable_package;
import org.robolectric.res.android.ResourceTypes.ResTable_sparseTypeEntry;
import org.robolectric.res.android.ResourceTypes.ResTable_staged_alias_entry;
import org.robolectric.res.android.ResourceTypes.ResTable_staged_alias_header;
import org.robolectric.res.android.ResourceTypes.ResTable_type;
import org.robolectric.res.android.ResourceTypes.ResTable_typeSpec;
import org.robolectric.res.android.ResourceTypes.Res_value;
Expand Down Expand Up @@ -370,7 +370,7 @@ static class LoadedPackage {
// };
final Map<Integer, TypeSpec> type_specs_ = new HashMap<>();
final List<DynamicPackageEntry> dynamic_package_map_ = new ArrayList<>();
final Map<Integer, Integer> alias_id_map_ = new HashMap<>();
final Map<Integer, Integer> aliasIdMap = new HashMap<>();

ResTable_entry GetEntry(ResTable_type type_chunk,
short entry_index) {
Expand Down Expand Up @@ -729,30 +729,30 @@ static LoadedPackage Load(Chunk chunk,

// loaded_package.dynamic_package_map_.reserve(dtohl(lib.count));

// ResTable_lib_entry entry_begin =
// ResTable_lib_entry entryBegin =
// reinterpret_cast<ResTable_lib_entry*>(child_chunk.data_ptr());
ResTable_lib_entry entry_begin =
ResTable_lib_entry entryBegin =
child_chunk.asResTable_lib_entry();
// ResTable_lib_entry entry_end = entry_begin + dtohl(lib.count);
// for (auto entry_iter = entry_begin; entry_iter != entry_end; ++entry_iter) {
for (ResTable_lib_entry entry_iter = entry_begin;
entry_iter.myOffset() != entry_begin.myOffset() + dtohl(lib.count);
entry_iter = new ResTable_lib_entry(entry_iter.myBuf(), entry_iter.myOffset() + ResTable_lib_entry.SIZEOF)) {
// ResTable_lib_entry entry_end = entryBegin + dtohl(lib.count);
// for (auto entryIter = entryBegin; entryIter != entry_end; ++entryIter) {
for (ResTable_lib_entry entryIter = entryBegin;
entryIter.myOffset() != entryBegin.myOffset() + dtohl(lib.count);
entryIter = new ResTable_lib_entry(entryIter.myBuf(), entryIter.myOffset() + ResTable_lib_entry.SIZEOF)) {
String package_name =
Util.ReadUtf16StringFromDevice(entry_iter.packageName,
entry_iter.packageName.length);
Util.ReadUtf16StringFromDevice(entryIter.packageName,
entryIter.packageName.length);

if (dtohl(entry_iter.packageId) >= 255) {
if (dtohl(entryIter.packageId) >= 255) {
logError(String.format(
"Package ID %02x in RES_TABLE_LIBRARY_TYPE too large for package '%s'.",
dtohl(entry_iter.packageId), package_name));
dtohl(entryIter.packageId), package_name));
return emptyBraces();
}

// loaded_package.dynamic_package_map_.emplace_back(std.move(package_name),
// dtohl(entry_iter.packageId));
// dtohl(entryIter.packageId));
loaded_package.dynamic_package_map_.add(new DynamicPackageEntry(package_name,
dtohl(entry_iter.packageId)));
dtohl(entryIter.packageId)));
}

} break;
Expand All @@ -767,52 +767,52 @@ static LoadedPackage Load(Chunk chunk,
break;
}

ResTable_staged_alias_header lib_alias = child_chunk.asResTable_staged_alias_header();
if (lib_alias == null) {
ResTableStagedAliasHeader libAlias = child_chunk.asResTableStagedAliasHeader();
if (libAlias == null) {
logError("RES_TABLE_STAGED_ALIAS_TYPE is too small.");
return emptyBraces();
}
if ((child_chunk.data_size() / ResTable_staged_alias_entry.SIZEOF)
< dtohl(lib_alias.count)) {
if ((child_chunk.data_size() / ResTableStagedAliasEntry.SIZEOF)
< dtohl(libAlias.count)) {
logError("RES_TABLE_STAGED_ALIAS_TYPE is too small to hold entries.");
return emptyBraces();
}

// const auto entry_begin =
// child_chunk.data_ptr().convert<ResTable_staged_alias_entry>();
// const auto entry_end = entry_begin + dtohl(lib_alias.count);
ResTable_staged_alias_entry entry_begin = child_chunk.asResTable_staged_alias_entry();
int entry_end_offset =
entry_begin.myOffset()
+ dtohl(lib_alias.count) * ResTable_staged_alias_entry.SIZEOF;
// std::unordered_set<uint32_t> finalized_ids;
// finalized_ids.reserve(entry_end - entry_begin);
Set<Integer> finalized_ids = new HashSet<>();
for (ResTable_staged_alias_entry entry_iter = entry_begin;
entry_iter.myOffset() != entry_end_offset;
entry_iter =
new ResTable_staged_alias_entry(
entry_iter.myBuf(),
entry_iter.myOffset() + ResTable_staged_alias_entry.SIZEOF)) {

int finalized_id = dtohl(entry_iter.finalizedResId);
// if (!finalized_ids.insert(finalized_id).second) {
if (!finalized_ids.add(finalized_id)) {
// const auto entryBegin =
// child_chunk.data_ptr().convert<ResTableStagedAliasEntry>();
// const auto entry_end = entryBegin + dtohl(libAlias.count);
ResTableStagedAliasEntry entryBegin = child_chunk.asResTableStagedAliasEntry();
int entryEndOffset =
entryBegin.myOffset()
+ dtohl(libAlias.count) * ResTableStagedAliasEntry.SIZEOF;
// std::unordered_set<uint32_t> finalizedIds;
// finalizedIds.reserve(entry_end - entryBegin);
Set<Integer> finalizedIds = new HashSet<>();
for (ResTableStagedAliasEntry entryIter = entryBegin;
entryIter.myOffset() != entryEndOffset;
entryIter =
new ResTableStagedAliasEntry(
entryIter.myBuf(),
entryIter.myOffset() + ResTableStagedAliasEntry.SIZEOF)) {

int finalizedId = dtohl(entryIter.finalizedResId);
// if (!finalizedIds.insert(finalizedId).second) {
if (!finalizedIds.add(finalizedId)) {
logError(
String.format(
"Repeated finalized resource id '%08x' in staged aliases.",
finalized_id));
finalizedId));
return emptyBraces();
}

int staged_id = dtohl(entry_iter.stagedResId);
// auto [_, success] = loaded_package->alias_id_map_.emplace(staged_id,
// finalized_id);
Integer previousValue = loaded_package.alias_id_map_.put(staged_id, finalized_id);
int stagedId = dtohl(entryIter.stagedResId);
// auto [_, success] = loaded_package->aliasIdMap.emplace(stagedId,
// finalizedId);
Integer previousValue = loaded_package.aliasIdMap.put(stagedId, finalizedId);
if (previousValue != null) {
logError(
String.format(
"Repeated staged resource id '%08x' in staged aliases.", staged_id));
"Repeated staged resource id '%08x' in staged aliases.", stagedId));
return emptyBraces();
}
}
Expand Down Expand Up @@ -922,8 +922,8 @@ void ForEachTypeSpec(TypeSpecFunc f) {
}
}

Map<Integer, Integer> GetAliasResourceIdMap() {
return alias_id_map_;
Map<Integer, Integer> getAliasResourceIdMap() {
return aliasIdMap;
}

private static LoadedPackage emptyBraces() {
Expand Down
Expand Up @@ -1508,15 +1508,15 @@ static class ResTable_lib_entry extends WithOffset
* A map that allows rewriting staged (non-finalized) resource ids to their finalized
* counterparts.
*/
static class ResTable_staged_alias_header extends WithOffset {
static class ResTableStagedAliasHeader extends WithOffset {
public static final int SIZEOF = ResChunk_header.SIZEOF + 4;

ResChunk_header header;

// The number of ResTable_staged_alias_entry that follow this header.
// The number of ResTableStagedAliasEntry that follow this header.
int count;

ResTable_staged_alias_header(ByteBuffer buf, int offset) {
ResTableStagedAliasHeader(ByteBuffer buf, int offset) {
super(buf, offset);

header = new ResChunk_header(buf, offset);
Expand All @@ -1525,7 +1525,7 @@ static class ResTable_staged_alias_header extends WithOffset {
}

/** Maps the staged (non-finalized) resource id to its finalized resource id. */
static class ResTable_staged_alias_entry extends WithOffset {
static class ResTableStagedAliasEntry extends WithOffset {
public static final int SIZEOF = 8;

// The compile-time staged resource id to rewrite.
Expand All @@ -1534,7 +1534,7 @@ static class ResTable_staged_alias_entry extends WithOffset {
// The compile-time finalized resource id to which the staged resource id should be rewritten.
int finalizedResId;

ResTable_staged_alias_entry(ByteBuffer buf, int offset) {
ResTableStagedAliasEntry(ByteBuffer buf, int offset) {
super(buf, offset);

stagedResId = buf.getInt(offset);
Expand Down
Expand Up @@ -44,20 +44,20 @@ public void testResTableStagedAliasType() {
(short) RES_TABLE_STAGED_ALIAS_TYPE,
() -> {
// header
buf.putInt(1); // ResTable_staged_alias_header.count
buf.putInt(1); // ResTableStagedAliasHeader.count
},
() -> {
// contents
buf.putInt(stagedResId); // ResTable_staged_alias_entry.stagedResId
buf.putInt(finalizedResId); // ResTable_staged_alias_entry.finalizedResId
buf.putInt(stagedResId); // ResTableStagedAliasEntry.stagedResId
buf.putInt(finalizedResId); // ResTableStagedAliasEntry.finalizedResId
});
});
final Chunk chunk = new Chunk(new ResChunk_header(buf, 0));
final LoadedArsc.LoadedPackage loadedPackage =
LoadedArsc.LoadedPackage.Load(
chunk, null /* loaded_idmap */, true /* system */, false /* load_as_shared_library */);

final Map<Integer, Integer> aliasIdMap = loadedPackage.GetAliasResourceIdMap();
final Map<Integer, Integer> aliasIdMap = loadedPackage.getAliasResourceIdMap();
assertEquals(finalizedResId, (int) aliasIdMap.get(stagedResId));
}
}

0 comments on commit bbcf7a4

Please sign in to comment.