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()); |
+ } |
+} |