Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Unified Diff: base/android/java/debug_src/org/chromium/base/Reflect.java

Issue 1291793007: GN(android): Add scripts & runtime logic for installing _managed apks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-managed-install
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/java/debug_src/org/chromium/base/Reflect.java
diff --git a/base/android/java/debug_src/org/chromium/base/Reflect.java b/base/android/java/debug_src/org/chromium/base/Reflect.java
new file mode 100644
index 0000000000000000000000000000000000000000..636a1a6c4681ac31431f208fa3868e6c61d9bf3e
--- /dev/null
+++ b/base/android/java/debug_src/org/chromium/base/Reflect.java
@@ -0,0 +1,53 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.base;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+
+/**
+ * Reflection helper methods.
+ */
+final class Reflect {
+ static void setField(Object instance, String name, Object val)
+ throws NoSuchFieldException {
+ Field field = findField(instance, name);
+ try {
+ field.setAccessible(true);
+ field.set(instance, val);
+ } catch (IllegalAccessException e) {
+ // This shouldn't happen.
+ }
+ }
+
+ static Object getField(Object instance, String name) throws NoSuchFieldException {
+ Field field = findField(instance, name);
+ try {
+ field.setAccessible(true);
+ return field.get(instance);
+ } catch (IllegalAccessException e) {
+ // This shouldn't happen.
+ }
+ return null;
+ }
+
+ static Object[] concatArrays(Object[] left, Object[] right) {
+ Object[] result = (Object[]) (Array.newInstance(
+ left.getClass().getComponentType(), left.length + right.length));
+ System.arraycopy(left, 0, result, 0, left.length);
+ System.arraycopy(right, 0, result, left.length, right.length);
+ return result;
+ }
+
+ private static Field findField(Object instance, String name) throws NoSuchFieldException {
+ for (Class<?> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass()) {
+ try {
+ return clazz.getDeclaredField(name);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ throw new NoSuchFieldException("Field " + name + " not found in " + instance.getClass());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698