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/jni/aapt2_jni.cpp b/tools/aapt2/jni/aapt2_jni.cpp
index dff77b9..211ada8 100644
--- a/tools/aapt2/jni/aapt2_jni.cpp
+++ b/tools/aapt2/jni/aapt2_jni.cpp
@@ -14,84 +14,81 @@
* limitations under the License.
*/
+#include "com_android_tools_aapt2_Aapt2.h"
+
#include <algorithm>
-#include <cassert>
#include <memory>
#include <utility>
#include <vector>
-#include <ScopedUtfChars.h>
+#include "android-base/logging.h"
+#include "nativehelper/ScopedUtfChars.h"
#include "util/Util.h"
-#include "com_android_tools_aapt2_Aapt2.h"
-
namespace aapt {
- extern int compile(const std::vector<StringPiece>& args);
- extern int link(const std::vector<StringPiece>& args);
+extern int Compile(const std::vector<StringPiece> &args);
+extern int Link(const std::vector<StringPiece> &args);
}
/*
* Converts a java List<String> into C++ vector<ScopedUtfChars>.
*/
static std::vector<ScopedUtfChars> list_to_utfchars(JNIEnv *env, jobject obj) {
- std::vector<ScopedUtfChars> converted;
+ std::vector<ScopedUtfChars> converted;
- // Call size() method on the list to know how many elements there are.
- jclass list_cls = env->GetObjectClass(obj);
- jmethodID size_method_id = env->GetMethodID(list_cls, "size", "()I");
- assert(size_method_id != 0);
- jint size = env->CallIntMethod(obj, size_method_id);
- assert(size >= 0);
+ // Call size() method on the list to know how many elements there are.
+ jclass list_cls = env->GetObjectClass(obj);
+ jmethodID size_method_id = env->GetMethodID(list_cls, "size", "()I");
+ CHECK(size_method_id != 0);
+ jint size = env->CallIntMethod(obj, size_method_id);
+ CHECK(size >= 0);
- // Now, iterate all strings in the list
- // (note: generic erasure means get() return an Object)
- jmethodID get_method_id = env->GetMethodID(list_cls, "get", "()Ljava/lang/Object;");
- for (jint i = 0; i < size; i++) {
- // Call get(i) to get the string in the ith position.
- jobject string_obj_uncast = env->CallObjectMethod(obj, get_method_id, i);
- assert(string_obj_uncast != nullptr);
- jstring string_obj = static_cast<jstring>(string_obj_uncast);
- converted.push_back(ScopedUtfChars(env, string_obj));
- }
+ // Now, iterate all strings in the list
+ // (note: generic erasure means get() return an Object)
+ jmethodID get_method_id =
+ env->GetMethodID(list_cls, "get", "()Ljava/lang/Object;");
+ for (jint i = 0; i < size; i++) {
+ // Call get(i) to get the string in the ith position.
+ jobject string_obj_uncast = env->CallObjectMethod(obj, get_method_id, i);
+ CHECK(string_obj_uncast != nullptr);
+ jstring string_obj = static_cast<jstring>(string_obj_uncast);
+ converted.push_back(ScopedUtfChars(env, string_obj));
+ }
- return converted;
+ return converted;
}
/*
* Extracts all StringPiece from the ScopedUtfChars instances.
- *
+ *
* The returned pieces can only be used while the original ones have not been
* destroyed.
*/
static std::vector<aapt::StringPiece> extract_pieces(
- const std::vector<ScopedUtfChars> &strings) {
- std::vector<aapt::StringPiece> pieces;
-
- std::for_each(
- strings.begin(),
- strings.end(),
- [&pieces](const ScopedUtfChars &p) {
- pieces.push_back(p.c_str());
- });
-
- return pieces;
+ const std::vector<ScopedUtfChars> &strings) {
+ std::vector<aapt::StringPiece> pieces;
+
+ std::for_each(
+ strings.begin(), strings.end(),
+ [&pieces](const ScopedUtfChars &p) { pieces.push_back(p.c_str()); });
+
+ return pieces;
}
JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2_nativeCompile(
- JNIEnv *env,
- jclass aapt_obj,
- jobject arguments_obj) {
- std::vector<ScopedUtfChars> compile_args_jni = list_to_utfchars(env, arguments_obj);
- std::vector<aapt::StringPiece> compile_args = extract_pieces(compile_args_jni);
- aapt::compile(compile_args);
+ JNIEnv *env, jclass aapt_obj, jobject arguments_obj) {
+ std::vector<ScopedUtfChars> compile_args_jni =
+ list_to_utfchars(env, arguments_obj);
+ std::vector<aapt::StringPiece> compile_args =
+ extract_pieces(compile_args_jni);
+ aapt::Compile(compile_args);
}
JNIEXPORT void JNICALL Java_com_android_tools_aapt2_Aapt2_nativeLink(
- JNIEnv *env,
- jclass aapt_obj,
- jobject arguments_obj) {
- std::vector<ScopedUtfChars> link_args_jni = list_to_utfchars(env, arguments_obj);
- std::vector<aapt::StringPiece> link_args = extract_pieces(link_args_jni);
- aapt::link(link_args);
+ JNIEnv *env, jclass aapt_obj, jobject arguments_obj) {
+ std::vector<ScopedUtfChars> link_args_jni =
+ list_to_utfchars(env, arguments_obj);
+ std::vector<aapt::StringPiece> link_args = extract_pieces(link_args_jni);
+ aapt::Link(link_args);
}