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

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

Issue 2845773004: DO NOT SUBMIT: add main dex list check to classloader. (Closed)
Patch Set: Created 3 years, 8 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/src/org/chromium/base/Reflect.java
diff --git a/build/android/incremental_install/java/org/chromium/incrementalinstall/Reflect.java b/base/android/java/src/org/chromium/base/Reflect.java
similarity index 79%
rename from build/android/incremental_install/java/org/chromium/incrementalinstall/Reflect.java
rename to base/android/java/src/org/chromium/base/Reflect.java
index c64dc1e8a313a86604983b98b287826c0ad0e6a6..94e4730d7e9be6924b50787e2e1e36dc85deb2ee 100644
--- a/build/android/incremental_install/java/org/chromium/incrementalinstall/Reflect.java
+++ b/base/android/java/src/org/chromium/base/Reflect.java
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.incrementalinstall;
+package org.chromium.base;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
@@ -13,7 +13,7 @@ import java.util.Arrays;
/**
* Reflection helper methods.
*/
-final class Reflect {
+public final class Reflect {
/**
* Sets the value of an object's field (even if it's not visible).
*
@@ -21,7 +21,7 @@ final class Reflect {
* @param name The name of the field to set.
* @param value The new value for the field.
*/
- static void setField(Object instance, String name, Object value)
+ public static void setField(Object instance, String name, Object value)
throws ReflectiveOperationException {
Field field = findField(instance, name);
field.setAccessible(true);
@@ -36,17 +36,30 @@ final class Reflect {
* @return The field's value. Primitive values are returned as their boxed
* type.
*/
- static Object getField(Object instance, String name) throws ReflectiveOperationException {
+ public static Object getField(Object instance, String name)
+ throws ReflectiveOperationException {
Field field = findField(instance, name);
field.setAccessible(true);
return field.get(instance);
}
+ public static Field getField(Class<?> cls, String name) {
+ for (Field field : cls.getDeclaredFields()) {
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
+ }
+ if (field.getName().equals(name)) {
+ return field;
+ }
+ }
+ return null;
+ }
+
/**
* Concatenates two arrays into a new array. The arrays must be of the same
* type.
*/
- static Object[] concatArrays(Object[] arrType, Object[] left, Object[] right) {
+ public static Object[] concatArrays(Object[] arrType, Object[] left, Object[] right) {
Object[] result = (Object[]) Array.newInstance(
arrType.getClass().getComponentType(), left.length + right.length);
System.arraycopy(left, 0, result, 0, left.length);
@@ -58,10 +71,10 @@ final class Reflect {
* Invokes a method with zero or more parameters. For static methods, use the Class as the
* instance.
*/
- static Object invokeMethod(Object instance, String name, Object... params)
+ public static Object invokeMethod(Object instance, String name, Object... params)
throws ReflectiveOperationException {
boolean isStatic = instance instanceof Class;
- Class<?> clazz = isStatic ? (Class<?>) instance : instance.getClass();
+ Class<?> clazz = isStatic ? (Class<?>) instance : instance.getClass();
Method method = findMethod(clazz, name, params);
method.setAccessible(true);
return method.invoke(instance, params);
@@ -70,7 +83,7 @@ final class Reflect {
/**
* Calls a constructor with zero or more parameters.
*/
- static Object newInstance(Class<?> clazz, Object... params)
+ public static Object newInstance(Class<?> clazz, Object... params)
throws ReflectiveOperationException {
Constructor<?> constructor = findConstructor(clazz, params);
constructor.setAccessible(true);
@@ -79,7 +92,7 @@ final class Reflect {
private static Field findField(Object instance, String name) throws NoSuchFieldException {
boolean isStatic = instance instanceof Class;
- Class<?> clazz = isStatic ? (Class<?>) instance : instance.getClass();
+ Class<?> clazz = isStatic ? (Class<?>) instance : instance.getClass();
for (; clazz != null; clazz = clazz.getSuperclass()) {
try {
return clazz.getDeclaredField(name);
@@ -111,8 +124,8 @@ final class Reflect {
return constructor;
}
}
- throw new NoSuchMethodException("Constructor with parameters " + Arrays.asList(params)
- + " not found in " + clazz);
+ throw new NoSuchMethodException(
+ "Constructor with parameters " + Arrays.asList(params) + " not found in " + clazz);
}
private static boolean areParametersCompatible(Class<?>[] paramTypes, Object... params) {
@@ -135,7 +148,7 @@ final class Reflect {
if (left.isPrimitive()) {
// TODO(agrieve): Fill in the rest as needed.
return left == boolean.class && rightClazz == Boolean.class
- || left == int.class && rightClazz == Integer.class;
+ || left == int.class && rightClazz == Integer.class;
}
return left.isAssignableFrom(rightClazz);
}

Powered by Google App Engine
This is Rietveld 408576698