diff options
author | 2011-06-24 18:38:41 +0900 | |
---|---|---|
committer | 2011-06-24 18:38:41 +0900 | |
commit | 80a9ce76d85ff521aeb5a51d759f5ba367ffc627 (patch) | |
tree | 239ff93af9a2b5bb0271968467a212c150608e03 /java/src/com/android/inputmethod/compat/CompatUtils.java | |
parent | dfd66f19edf1e1d97a0bf83dd20b99ee8bfae35e (diff) | |
parent | 52344a0788db20d12960b2481e99e990c3de1ea4 (diff) | |
download | latinime-80a9ce76d85ff521aeb5a51d759f5ba367ffc627.tar.gz latinime-80a9ce76d85ff521aeb5a51d759f5ba367ffc627.tar.xz latinime-80a9ce76d85ff521aeb5a51d759f5ba367ffc627.zip |
Merge remote-tracking branch 'goog/master' into merge
Conflicts:
java/res/xml/method.xml
Change-Id: I7b5f2232753d7159b520e5e57a0e06c51935edbd
Diffstat (limited to 'java/src/com/android/inputmethod/compat/CompatUtils.java')
-rw-r--r-- | java/src/com/android/inputmethod/compat/CompatUtils.java | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java index 0b532f7f0..b42633cd9 100644 --- a/java/src/com/android/inputmethod/compat/CompatUtils.java +++ b/java/src/com/android/inputmethod/compat/CompatUtils.java @@ -22,7 +22,6 @@ import android.util.Log; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; @@ -74,76 +73,73 @@ public class CompatUtils { return targetClass.getMethod(name, parameterTypes); } catch (SecurityException e) { // ignore - return null; } catch (NoSuchMethodException e) { // ignore - return null; } + return null; } public static Field getField(Class<?> targetClass, String name) { + if (targetClass == null || TextUtils.isEmpty(name)) return null; try { return targetClass.getField(name); } catch (SecurityException e) { // ignore - return null; } catch (NoSuchFieldException e) { // ignore - return null; } + return null; } - public static Constructor<?> getConstructor(Class<?> targetClass, Class<?>[] types) { + public static Constructor<?> getConstructor(Class<?> targetClass, Class<?> ... types) { if (targetClass == null || types == null) return null; try { return targetClass.getConstructor(types); } catch (SecurityException e) { // ignore - return null; } catch (NoSuchMethodException e) { // ignore - return null; } + return null; + } + + public static Object newInstance(Constructor<?> constructor, Object ... args) { + if (constructor == null) return null; + try { + return constructor.newInstance(args); + } catch (Exception e) { + Log.e(TAG, "Exception in newInstance: " + e.getClass().getSimpleName()); + } + return null; } public static Object invoke( Object receiver, Object defaultValue, Method method, Object... args) { - if (receiver == null || method == null) return defaultValue; + if (method == null) return defaultValue; try { return method.invoke(receiver, args); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Exception in invoke: IllegalArgumentException"); - return defaultValue; - } catch (IllegalAccessException e) { - Log.e(TAG, "Exception in invoke: IllegalAccessException"); - return defaultValue; - } catch (InvocationTargetException e) { - Log.e(TAG, "Exception in invoke: IllegalTargetException"); - return defaultValue; + } catch (Exception e) { + Log.e(TAG, "Exception in invoke: " + e.getClass().getSimpleName()); } + return defaultValue; } public static Object getFieldValue(Object receiver, Object defaultValue, Field field) { - if (receiver == null || field == null) return defaultValue; + if (field == null) return defaultValue; try { return field.get(receiver); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Exception in getFieldValue: IllegalArgumentException"); - return defaultValue; - } catch (IllegalAccessException e) { - Log.e(TAG, "Exception in getFieldValue: IllegalAccessException"); - return defaultValue; + } catch (Exception e) { + Log.e(TAG, "Exception in getFieldValue: " + e.getClass().getSimpleName()); } + return defaultValue; } public static void setFieldValue(Object receiver, Field field, Object value) { - if (receiver == null || field == null) return; + if (field == null) return; try { field.set(receiver, value); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Exception in setFieldValue: IllegalArgumentException"); - } catch (IllegalAccessException e) { - Log.e(TAG, "Exception in setFieldValue: IllegalAccessException"); + } catch (Exception e) { + Log.e(TAG, "Exception in setFieldValue: " + e.getClass().getSimpleName()); } } |