diff --git a/java/src/com/android/inputmethod/compat/CompatUtils.java b/java/src/com/android/inputmethod/compat/CompatUtils.java index 660029baf..4fd2a6936 100644 --- a/java/src/com/android/inputmethod/compat/CompatUtils.java +++ b/java/src/com/android/inputmethod/compat/CompatUtils.java @@ -21,6 +21,7 @@ import android.util.Log; import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public final class CompatUtils { @@ -33,31 +34,31 @@ public final class CompatUtils { public static Class getClass(final String className) { try { return Class.forName(className); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { return null; } } public static Method getMethod(final Class targetClass, final String name, final Class... parameterTypes) { - if (targetClass == null || TextUtils.isEmpty(name)) return null; + if (targetClass == null || TextUtils.isEmpty(name)) { + return null; + } try { return targetClass.getMethod(name, parameterTypes); - } catch (SecurityException e) { - // ignore - } catch (NoSuchMethodException e) { + } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; } public static Field getField(final Class targetClass, final String name) { - if (targetClass == null || TextUtils.isEmpty(name)) return null; + if (targetClass == null || TextUtils.isEmpty(name)) { + return null; + } try { return targetClass.getField(name); - } catch (SecurityException e) { - // ignore - } catch (NoSuchFieldException e) { + } catch (final SecurityException | NoSuchFieldException e) { // ignore } return null; @@ -65,22 +66,25 @@ public final class CompatUtils { public static Constructor getConstructor(final Class targetClass, final Class ... types) { - if (targetClass == null || types == null) return null; + if (targetClass == null || types == null) { + return null; + } try { return targetClass.getConstructor(types); - } catch (SecurityException e) { - // ignore - } catch (NoSuchMethodException e) { + } catch (final SecurityException | NoSuchMethodException e) { // ignore } return null; } public static Object newInstance(final Constructor constructor, final Object ... args) { - if (constructor == null) return null; + if (constructor == null) { + return null; + } try { return constructor.newInstance(args); - } catch (Exception e) { + } catch (final InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { Log.e(TAG, "Exception in newInstance", e); } return null; @@ -88,10 +92,13 @@ public final class CompatUtils { public static Object invoke(final Object receiver, final Object defaultValue, final Method method, final Object... args) { - if (method == null) return defaultValue; + if (method == null) { + return defaultValue; + } try { return method.invoke(receiver, args); - } catch (Exception e) { + } catch (final IllegalAccessException | IllegalArgumentException + | InvocationTargetException e) { Log.e(TAG, "Exception in invoke", e); } return defaultValue; @@ -99,20 +106,24 @@ public final class CompatUtils { public static Object getFieldValue(final Object receiver, final Object defaultValue, final Field field) { - if (field == null) return defaultValue; + if (field == null) { + return defaultValue; + } try { return field.get(receiver); - } catch (Exception e) { + } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in getFieldValue", e); } return defaultValue; } public static void setFieldValue(final Object receiver, final Field field, final Object value) { - if (field == null) return; + if (field == null) { + return; + } try { field.set(receiver, value); - } catch (Exception e) { + } catch (final IllegalAccessException | IllegalArgumentException e) { Log.e(TAG, "Exception in setFieldValue", e); } } diff --git a/java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.java b/java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.java index d0b9c5da6..6209b60b3 100644 --- a/java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/DownloadManagerCompatUtils.java @@ -24,7 +24,7 @@ public final class DownloadManagerCompatUtils { // DownloadManager.Request#setAllowedOverMetered() has been introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_setAllowedOverMetered = CompatUtils.getMethod( - DownloadManager.Request.class, "setAllowedOverMetered", Boolean.TYPE); + DownloadManager.Request.class, "setAllowedOverMetered", boolean.class); public static DownloadManager.Request setAllowedOverMetered( final DownloadManager.Request request, final boolean allowOverMetered) { diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index 18b3a6060..aa20c0336 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -26,7 +26,7 @@ public final class InputMethodManagerCompatWrapper { // Note that InputMethodManager.switchToNextInputMethod() has been introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod( - InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE); + InputMethodManager.class, "switchToNextInputMethod", IBinder.class, boolean.class); // Note that InputMethodManager.shouldOfferSwitchingToNextInputMethod() has been introduced // in API level 19 (Build.VERSION_CODES.KITKAT). diff --git a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java index ee9125a07..365867257 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatUtils.java @@ -32,8 +32,8 @@ public final class InputMethodSubtypeCompatUtils { // has been introduced in API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1). private static final Constructor CONSTRUCTOR_INPUT_METHOD_SUBTYPE = CompatUtils.getConstructor(InputMethodSubtype.class, - Integer.TYPE, Integer.TYPE, String.class, String.class, String.class, - Boolean.TYPE, Boolean.TYPE, Integer.TYPE); + int.class, int.class, String.class, String.class, String.class, boolean.class, + boolean.class, int.class); static { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (CONSTRUCTOR_INPUT_METHOD_SUBTYPE == null) { diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 4c7663527..c07997bc9 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -34,9 +34,9 @@ import java.util.ArrayList; public final class SuggestionSpanUtils { // Note that SuggestionSpan.FLAG_AUTO_CORRECTION has been introduced // in API level 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1). - public static final Field FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField( + private static final Field FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField( SuggestionSpan.class, "FLAG_AUTO_CORRECTION"); - public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils.getFieldValue( + private static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils.getFieldValue( null /* receiver */, null /* defaultValue */, FIELD_FLAG_AUTO_CORRECTION); static { diff --git a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java index 6e32e74ab..1fb597ba6 100644 --- a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java @@ -26,7 +26,7 @@ public final class UserDictionaryCompatUtils { // UserDictionary.Words#addWord(Context, String, int, String, Locale) was introduced // in API level 16 (Build.VERSION_CODES.JELLY_BEAN). private static final Method METHOD_addWord = CompatUtils.getMethod(Words.class, "addWord", - Context.class, String.class, Integer.TYPE, String.class, Locale.class); + Context.class, String.class, int.class, String.class, Locale.class); @SuppressWarnings("deprecation") public static void addWord(final Context context, final String word, diff --git a/java/src/com/android/inputmethod/compat/ViewCompatUtils.java b/java/src/com/android/inputmethod/compat/ViewCompatUtils.java index 767cc423d..deb6809e7 100644 --- a/java/src/com/android/inputmethod/compat/ViewCompatUtils.java +++ b/java/src/com/android/inputmethod/compat/ViewCompatUtils.java @@ -30,7 +30,7 @@ public final class ViewCompatUtils { View.class, "getPaddingEnd"); private static final Method METHOD_setPaddingRelative = CompatUtils.getMethod( View.class, "setPaddingRelative", - Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); + int.class, int.class, int.class, int.class); private ViewCompatUtils() { // This utility class is not publicly instantiable. diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java index 29b169d80..922d2a8c8 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MoreKeySpecSplitTests.java @@ -53,7 +53,7 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase { private static String[] getAllResourceIdNames(final Class resourceIdClass) { final ArrayList names = new ArrayList<>(); for (final Field field : resourceIdClass.getFields()) { - if (field.getType() == Integer.TYPE) { + if (field.getType() == int.class) { names.add(field.getName()); } }