From 9b8528fee4eed35b8e887ded0851d08eb2b10db6 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Wed, 10 Aug 2016 14:15:30 -0700 Subject: Fix clang-tidy warnings in aapt and aapt2. * Add explicit keyword to conversion constructors. * Add NOLINT(implicit) comments for implicit conversion constructors. Bug: 28341362 * Use const reference type for read-only parameters. Bug: 30407689 * Use const reference type to avoid unnecessary copy. Bug: 30413862 Test: build with WITH_TIDY=1 Change-Id: Id6d21961f313a1ad92b15a37fdaa5be9e8ab48e1 --- tools/aapt/ApkBuilder.h | 2 +- tools/aapt/CacheUpdater.h | 2 +- tools/aapt/Command.cpp | 4 ++-- tools/aapt/ConfigDescription.h | 2 +- tools/aapt/CrunchCache.cpp | 2 +- tools/aapt/CrunchCache.h | 2 +- tools/aapt/FileFinder.cpp | 2 +- tools/aapt/FileFinder.h | 2 +- tools/aapt/IndentPrinter.h | 2 +- tools/aapt/Resource.cpp | 14 +++++++------- tools/aapt/ResourceFilter.h | 4 ++-- tools/aapt/ResourceTable.cpp | 6 +++--- tools/aapt/StringPool.h | 2 +- tools/aapt/WorkQueue.h | 2 +- tools/aapt/XMLNode.cpp | 4 ++-- tools/aapt/XMLNode.h | 2 +- tools/aapt/pseudolocalize.h | 2 +- 17 files changed, 28 insertions(+), 28 deletions(-) (limited to 'tools/aapt') diff --git a/tools/aapt/ApkBuilder.h b/tools/aapt/ApkBuilder.h index 0d7f06b1f323..5d3abc63519f 100644 --- a/tools/aapt/ApkBuilder.h +++ b/tools/aapt/ApkBuilder.h @@ -32,7 +32,7 @@ class AaptFile; class ApkBuilder : public android::RefBase { public: - ApkBuilder(const sp& configFilter); + explicit ApkBuilder(const sp& configFilter); /** * Tells the builder to generate a separate APK for resources that diff --git a/tools/aapt/CacheUpdater.h b/tools/aapt/CacheUpdater.h index 10a1bbc2f4aa..6fa96d67e6a3 100644 --- a/tools/aapt/CacheUpdater.h +++ b/tools/aapt/CacheUpdater.h @@ -51,7 +51,7 @@ private: class SystemCacheUpdater : public CacheUpdater { public: // Constructor to set bundle to pass to preProcessImage - SystemCacheUpdater (Bundle* b) + explicit SystemCacheUpdater (Bundle* b) : bundle(b) { }; // Make sure all the directories along this path exist diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp index cbad4b9b48a9..d80aaba8f64b 100644 --- a/tools/aapt/Command.cpp +++ b/tools/aapt/Command.cpp @@ -248,7 +248,7 @@ bail: } static void printResolvedResourceAttribute(const ResTable& resTable, const ResXMLTree& tree, - uint32_t attrRes, String8 attrLabel, String8* outError) + uint32_t attrRes, const String8& attrLabel, String8* outError) { Res_value value; AaptXml::getResolvedResourceAttribute(resTable, tree, attrRes, &value, outError); @@ -399,7 +399,7 @@ static void printUsesImpliedPermission(const String8& name, const String8& reaso ResTable::normalizeForOutput(reason.string()).string()); } -Vector getNfcAidCategories(AssetManager& assets, String8 xmlPath, bool offHost, +Vector getNfcAidCategories(AssetManager& assets, const String8& xmlPath, bool offHost, String8 *outError = NULL) { Asset* aidAsset = assets.openNonAsset(xmlPath, Asset::ACCESS_BUFFER); diff --git a/tools/aapt/ConfigDescription.h b/tools/aapt/ConfigDescription.h index 4f999a2ff0c6..09430f2532fa 100644 --- a/tools/aapt/ConfigDescription.h +++ b/tools/aapt/ConfigDescription.h @@ -29,7 +29,7 @@ struct ConfigDescription : public android::ResTable_config { size = sizeof(android::ResTable_config); } - ConfigDescription(const android::ResTable_config&o) { + ConfigDescription(const android::ResTable_config&o) { // NOLINT(implicit) *static_cast(this) = o; size = sizeof(android::ResTable_config); } diff --git a/tools/aapt/CrunchCache.cpp b/tools/aapt/CrunchCache.cpp index 0d574cf127dd..7b8a576b88d3 100644 --- a/tools/aapt/CrunchCache.cpp +++ b/tools/aapt/CrunchCache.cpp @@ -94,7 +94,7 @@ void CrunchCache::loadFiles() delete dw; } -bool CrunchCache::needsUpdating(String8 relativePath) const +bool CrunchCache::needsUpdating(const String8& relativePath) const { // Retrieve modification dates for this file entry under the source and // cache directory trees. The vectors will return a modification date of 0 diff --git a/tools/aapt/CrunchCache.h b/tools/aapt/CrunchCache.h index be3da5c40b25..4d6a16922f25 100644 --- a/tools/aapt/CrunchCache.h +++ b/tools/aapt/CrunchCache.h @@ -81,7 +81,7 @@ private: * // Recrunch sourceFile out to destFile. * */ - bool needsUpdating(String8 relativePath) const; + bool needsUpdating(const String8& relativePath) const; // DATA MEMBERS ==================================================== diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp index 18775c06863f..c9d0744a4463 100644 --- a/tools/aapt/FileFinder.cpp +++ b/tools/aapt/FileFinder.cpp @@ -77,7 +77,7 @@ bool SystemFileFinder::findFiles(String8 basePath, Vector& extensions, return true; } -void SystemFileFinder::checkAndAddFile(String8 path, const struct stat* stats, +void SystemFileFinder::checkAndAddFile(const String8& path, const struct stat* stats, Vector& extensions, KeyedVector& fileStore) { diff --git a/tools/aapt/FileFinder.h b/tools/aapt/FileFinder.h index 6974aee033a8..f405381ee275 100644 --- a/tools/aapt/FileFinder.h +++ b/tools/aapt/FileFinder.h @@ -72,7 +72,7 @@ private: * time as the value. * */ - static void checkAndAddFile(String8 path, const struct stat* stats, + static void checkAndAddFile(const String8& path, const struct stat* stats, Vector& extensions, KeyedVector& fileStore); diff --git a/tools/aapt/IndentPrinter.h b/tools/aapt/IndentPrinter.h index 6fc94bc927b8..bd0edcbed8ad 100644 --- a/tools/aapt/IndentPrinter.h +++ b/tools/aapt/IndentPrinter.h @@ -3,7 +3,7 @@ class IndentPrinter { public: - IndentPrinter(FILE* stream, int indentSize=2) + explicit IndentPrinter(FILE* stream, int indentSize=2) : mStream(stream) , mIndentSize(indentSize) , mIndent(0) diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index b278831ddf4e..b4c4d05a7397 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -399,7 +399,7 @@ static void collect_files(const sp& dir, const DefaultKeyedVector >& groups = dir->getFiles(); int N = groups.size(); for (int i=0; i& group = groups.valueAt(i); const DefaultKeyedVector >& files @@ -422,7 +422,7 @@ static void collect_files(const sp& dir, set->add(leafName, group); resources->add(resType, set); } else { - sp set = resources->valueAt(index); + const sp& set = resources->valueAt(index); index = set->indexOfKey(leafName); if (index < 0) { if (kIsDebug) { @@ -457,7 +457,7 @@ static void collect_files(const sp& ass, int N = dirs.size(); for (int i=0; i d = dirs.itemAt(i); + const sp& d = dirs.itemAt(i); if (kIsDebug) { printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(), d->getLeaf().string()); @@ -615,7 +615,7 @@ static bool applyFileOverlay(Bundle *bundle, // get the overlay resources of the requested type ssize_t index = overlayRes->indexOfKey(resTypeString); if (index >= 0) { - sp overlaySet = overlayRes->valueAt(index); + const sp& overlaySet = overlayRes->valueAt(index); // for each of the resources, check for a match in the previously built // non-overlay "baseset". @@ -765,7 +765,7 @@ bool addTagAttribute(const sp& node, const char* ns8, return addTagAttribute(node, ns8, attr8, value, errorOnFailedInsert, false); } -static void fullyQualifyClassName(const String8& package, sp node, +static void fullyQualifyClassName(const String8& package, const sp& node, const String16& attrName) { XMLNode::attribute_entry* attr = node->editAttribute( String16("http://schemas.android.com/apk/res/android"), attrName); @@ -1350,7 +1350,7 @@ status_t buildResources(Bundle* bundle, const sp& assets, spvalueAt(index), String8("values")); ssize_t res; while ((res=it.next()) == NO_ERROR) { - sp file = it.getFile(); + const sp& file = it.getFile(); res = compileResourceFile(bundle, assets, file, it.getParams(), (current!=assets), &table); if (res != NO_ERROR) { @@ -2688,7 +2688,7 @@ status_t writeResourceSymbols(Bundle* bundle, const sp& assets, String8 dest(bundle->getRClassDir()); if (bundle->getMakePackageDirs()) { - String8 pkg(package); + const String8& pkg(package); const char* last = pkg.string(); const char* s = last-1; do { diff --git a/tools/aapt/ResourceFilter.h b/tools/aapt/ResourceFilter.h index d6430c0409cc..40d5b752000c 100644 --- a/tools/aapt/ResourceFilter.h +++ b/tools/aapt/ResourceFilter.h @@ -78,7 +78,7 @@ private: class StrongResourceFilter : public ResourceFilter { public: StrongResourceFilter() {} - StrongResourceFilter(const std::set& configs) + explicit StrongResourceFilter(const std::set& configs) : mConfigs(configs) {} android::status_t parse(const android::String8& str); @@ -106,7 +106,7 @@ private: */ class InverseResourceFilter : public ResourceFilter { public: - InverseResourceFilter(const android::sp& filter) + explicit InverseResourceFilter(const android::sp& filter) : mFilter(filter) {} bool match(const android::ResTable_config& config) const { diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index 4d5bb312aaf1..76c59dd57068 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -4081,7 +4081,7 @@ status_t ResourceTable::Type::applyPublicEntryOrder() j = 0; for (i=0; i e = origOrder.itemAt(i); + const sp& e = origOrder.itemAt(i); // There will always be enough room for the remaining entries. while (mOrderedConfigs.itemAt(j) != NULL) { j++; @@ -4203,7 +4203,7 @@ status_t ResourceTable::Package::applyPublicTypeOrder() size_t j=0; for (i=0; i t = origOrder.itemAt(i); + const sp& t = origOrder.itemAt(i); // There will always be enough room for the remaining types. while (mOrderedTypes.itemAt(j) != NULL) { j++; @@ -4636,7 +4636,7 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle) { c->getEntries(); const size_t entryCount = entries.size(); for (size_t ei = 0; ei < entryCount; ei++) { - sp e = entries.valueAt(ei); + const sp& e = entries.valueAt(ei); if (e == NULL || e->getType() != Entry::TYPE_BAG) { continue; } diff --git a/tools/aapt/StringPool.h b/tools/aapt/StringPool.h index 4b0d920c3274..625b0bfb3832 100644 --- a/tools/aapt/StringPool.h +++ b/tools/aapt/StringPool.h @@ -41,7 +41,7 @@ class StringPool public: struct entry { entry() : offset(0) { } - entry(const String16& _value) : value(_value), offset(0), hasStyles(false) { } + explicit entry(const String16& _value) : value(_value), offset(0), hasStyles(false) { } entry(const entry& o) : value(o.value), offset(o.offset), hasStyles(o.hasStyles), indices(o.indices), configTypeName(o.configTypeName), configs(o.configs) { } diff --git a/tools/aapt/WorkQueue.h b/tools/aapt/WorkQueue.h index d38f05d034e9..ab5f9691c21d 100644 --- a/tools/aapt/WorkQueue.h +++ b/tools/aapt/WorkQueue.h @@ -47,7 +47,7 @@ public: }; /* Creates a work queue with the specified maximum number of work threads. */ - WorkQueue(size_t maxThreads, bool canCallJava = true); + explicit WorkQueue(size_t maxThreads, bool canCallJava = true); /* Destroys the work queue. * Cancels pending work and waits for all remaining threads to complete. diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp index 5b215daeb494..15ec4afa52dd 100644 --- a/tools/aapt/XMLNode.cpp +++ b/tools/aapt/XMLNode.cpp @@ -67,7 +67,7 @@ static const String16 RESOURCES_PREFIX_AUTO_PACKAGE(RESOURCES_AUTO_PACKAGE_NAMES static const String16 RESOURCES_PRV_PREFIX(RESOURCES_ROOT_PRV_NAMESPACE); static const String16 RESOURCES_TOOLS_NAMESPACE("http://schemas.android.com/tools"); -String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri, bool* outIsPublic) +String16 getNamespaceResourcePackage(const String16& appPackage, const String16& namespaceUri, bool* outIsPublic) { //printf("%s starts with %s?\n", String8(namespaceUri).string(), // String8(RESOURCES_PREFIX).string()); @@ -98,7 +98,7 @@ String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri, status_t hasSubstitutionErrors(const char* fileName, ResXMLTree* inXml, - String16 str16) + const String16& str16) { const char16_t* str = str16.string(); const char16_t* p = str; diff --git a/tools/aapt/XMLNode.h b/tools/aapt/XMLNode.h index 749bf9f59bf7..ac920186fe63 100644 --- a/tools/aapt/XMLNode.h +++ b/tools/aapt/XMLNode.h @@ -178,7 +178,7 @@ private: XMLNode(const String8& filename, const String16& s1, const String16& s2, bool isNamespace); // Creating a CDATA node. - XMLNode(const String8& filename); + explicit XMLNode(const String8& filename); status_t collect_strings(StringPool* dest, Vector* outResIds, bool stripComments, bool stripRawValues) const; diff --git a/tools/aapt/pseudolocalize.h b/tools/aapt/pseudolocalize.h index 1faecd14172d..9bb1fd8312b0 100644 --- a/tools/aapt/pseudolocalize.h +++ b/tools/aapt/pseudolocalize.h @@ -43,7 +43,7 @@ class PseudoMethodAccent : public PseudoMethodImpl { class Pseudolocalizer { public: - Pseudolocalizer(PseudolocalizationMethod m); + explicit Pseudolocalizer(PseudolocalizationMethod m); ~Pseudolocalizer() { if (mImpl) delete mImpl; } void setMethod(PseudolocalizationMethod m); String16 start() { return mImpl->start(); } -- cgit v1.2.3-59-g8ed1b