Last active
September 17, 2017 05:43
-
-
Save ShikherVerma/070e09052d20cc29b60590562c0da0c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Constructor<? extends Unbinder> findBindingConstructorForClass(Class<?> cls) { | |
Constructor<? extends Unbinder> bindingCtor = BINDINGS.get(cls); | |
if (bindingCtor != null) { | |
if (debug) Log.d(TAG, "HIT: Cached in binding map."); | |
return bindingCtor; | |
} | |
String clsName = cls.getName(); | |
if (clsName.startsWith("android.") || clsName.startsWith("java.")) { | |
if (debug) Log.d(TAG, "MISS: Reached framework class. Abandoning search."); | |
return null; | |
} | |
try { | |
Class<?> bindingClass = cls.getClassLoader().loadClass(clsName + "_ViewBinding"); | |
//noinspection unchecked | |
bindingCtor = (Constructor<? extends Unbinder>) bindingClass.getConstructor(cls, View.class); | |
if (debug) Log.d(TAG, "HIT: Loaded binding class and constructor."); | |
} catch (ClassNotFoundException e) { | |
if (debug) Log.d(TAG, "Not found. Trying superclass " + cls.getSuperclass().getName()); | |
bindingCtor = findBindingConstructorForClass(cls.getSuperclass()); | |
} catch (NoSuchMethodException e) { | |
throw new RuntimeException("Unable to find binding constructor for " + clsName, e); | |
} | |
BINDINGS.put(cls, bindingCtor); | |
return bindingCtor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment