本文整理汇总了Java中com.nick.scalpel.core.utils.ReflectionUtils.findField方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.findField方法的具体用法?Java ReflectionUtils.findField怎么用?Java ReflectionUtils.findField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.nick.scalpel.core.utils.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.findField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wire
import com.nick.scalpel.core.utils.ReflectionUtils; //导入方法依赖的package包/类
@Override
public void wire(Object o) {
RequireRoot autoRequireRoot = o.getClass().getAnnotation(RequireRoot.class);
RequireRoot.Mode mode = autoRequireRoot.mode();
switch (mode) {
case Sync:
logV("Requesting root sync.");
mRequester.requestRoot();
break;
case Async:
RequireRoot.Callback callback;
String callbackStr = autoRequireRoot.callback();
Preconditions.checkState(!TextUtils.isEmpty(callbackStr), "Should specify a callback when using Async mode.");
switch (callbackStr) {
case "this":
Preconditions.checkState(o instanceof RequireRoot.Callback, "Invalid callback reference.");
callback = (RequireRoot.Callback) o;
break;
default:
Field field = ReflectionUtils.findField(o, callbackStr);
Preconditions.checkNotNull(field, "No field named:" + field);
Object fieldObject = ReflectionUtils.getField(field, o);
Preconditions.checkNotNull(fieldObject, "Null field:" + field);
Preconditions.checkState(fieldObject instanceof RequireRoot.Callback, "Invalid callback reference.");
callback = (RequireRoot.Callback) fieldObject;
break;
}
logV("Requesting root async, callback:" + callback);
SharedExecutor.get().execute(new AsyncRootRequester(callback));
}
}
示例2: getCallback
import com.nick.scalpel.core.utils.ReflectionUtils; //导入方法依赖的package包/类
@Nullable
@Override
protected Handler.Callback getCallback(Object object, Field field) {
MainThreadHandler handler = field.getAnnotation(MainThreadHandler.class);
String callbackStr = handler.callback();
if (TextUtils.isEmpty(callbackStr)) return null;
Object fieldObj;
switch (callbackStr) {
case ThisThatNull.THIS:
fieldObj = object;
break;
default:
Field callbackField = ReflectionUtils.findField(object, callbackStr);
Preconditions.checkNotNull(callbackField);
ReflectionUtils.makeAccessible(callbackField);
fieldObj = ReflectionUtils.getField(callbackField, object);
Preconditions.checkNotNull(fieldObj);
break;
}
boolean isCallback = fieldObj instanceof Handler.Callback;
Preconditions.checkState(isCallback);
return (Handler.Callback) fieldObj;
}
示例3: getCallback
import com.nick.scalpel.core.utils.ReflectionUtils; //导入方法依赖的package包/类
@Nullable
@Override
protected Handler.Callback getCallback(Object object, Field field) {
WorkerThreadHandler handler = field.getAnnotation(WorkerThreadHandler.class);
String callbackStr = handler.callback();
if (TextUtils.isEmpty(callbackStr)) return null;
Object fieldObj;
switch (callbackStr) {
case ThisThatNull.THIS:
fieldObj = object;
break;
default:
Field callbackField = ReflectionUtils.findField(object, callbackStr);
Preconditions.checkNotNull(callbackField);
ReflectionUtils.makeAccessible(callbackField);
fieldObj = ReflectionUtils.getField(callbackField, object);
Preconditions.checkNotNull(fieldObj);
break;
}
boolean isCallback = fieldObj instanceof Handler.Callback;
Preconditions.checkState(isCallback);
return (Handler.Callback) fieldObj;
}
示例4: autoWire
import com.nick.scalpel.core.utils.ReflectionUtils; //导入方法依赖的package包/类
private void autoWire(final Object o, Field field) {
logD("Auto wiring: " + field.getName());
Object fieldObjectWired = ReflectionUtils.getField(field, o);
if (fieldObjectWired == null) return;
boolean isView = fieldObjectWired instanceof View;
if (!isView)
throw new IllegalArgumentException("Object " + fieldObjectWired + " is not instance of View.");
View view = (View) fieldObjectWired;
OnTouch onClick = field.getAnnotation(OnTouch.class);
String listener = onClick.listener();
String action = onClick.action();
if (!TextUtils.isEmpty(listener)) {
Field onTouchListenerField = ReflectionUtils.findField(o, listener);
if (onTouchListenerField == null)
throw new NullPointerException("No such listener:" + listener);
ReflectionUtils.makeAccessible(onTouchListenerField);
Object onTouchListenerObj = ReflectionUtils.getField(onTouchListenerField, o);
if (onTouchListenerObj == null)
throw new NullPointerException("Null listener:" + listener);
boolean isListener = onTouchListenerObj instanceof View.OnTouchListener;
if (!isListener)
throw new IllegalArgumentException("Object " + onTouchListenerObj + " is not instance of OnTouchListener.");
View.OnTouchListener onTouchListener = (View.OnTouchListener) onTouchListenerObj;
view.setOnTouchListener(onTouchListener);
logD("OnTouchWirer listener, Auto wired: " + field.getName());
} else if (!TextUtils.isEmpty(action)) {
final String[] args = onClick.args();
Class[] argClz = new Class[args.length];
for (int i = 0; i < args.length; i++) {
argClz[i] = String.class;
}
Method actionMethod = ReflectionUtils.findMethod(o.getClass(), action, argClz);
if (actionMethod == null)
throw new NullPointerException("No such method:" + action + " with args:" + Arrays.toString(argClz));
ReflectionUtils.makeAccessible(actionMethod);
final Method finalActionMethod = actionMethod;
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Object result = ReflectionUtils.invokeMethod(finalActionMethod, o, args);
logD("OnTouchWirer onTouch invoked: " + result);
return true;
}
});
logD("OnTouchWirer actions, Auto wired: " + field.getName());
}
}
示例5: autoWire
import com.nick.scalpel.core.utils.ReflectionUtils; //导入方法依赖的package包/类
private void autoWire(final Object o, Field field) {
logD("Auto wiring: " + field.getName());
Object fieldObjectWired = ReflectionUtils.getField(field, o);
if (fieldObjectWired == null) return;
boolean isView = fieldObjectWired instanceof View;
if (!isView)
throw new IllegalArgumentException("Object " + fieldObjectWired + " is not instance of View.");
View view = (View) fieldObjectWired;
OnClick onClick = field.getAnnotation(OnClick.class);
String listener = onClick.listener();
String action = onClick.action();
if (!TextUtils.isEmpty(listener)) {
Field onClickListenerField = ReflectionUtils.findField(o, listener);
if (onClickListenerField == null)
throw new NullPointerException("No such listener:" + listener);
ReflectionUtils.makeAccessible(onClickListenerField);
Object onClickListenerObj = ReflectionUtils.getField(onClickListenerField, o);
if (onClickListenerObj == null)
throw new NullPointerException("Null listener:" + listener);
boolean isListener = onClickListenerObj instanceof View.OnClickListener;
if (!isListener)
throw new IllegalArgumentException("Object " + onClickListenerObj + " is not instance of OnClickListener.");
View.OnClickListener onClickListener = (View.OnClickListener) onClickListenerObj;
view.setOnClickListener(onClickListener);
logD("OnClickWirer listener, Auto wired: " + field.getName());
} else if (!TextUtils.isEmpty(action)) {
final String[] args = onClick.args();
Class[] argClz = new Class[args.length];
for (int i = 0; i < args.length; i++) {
argClz[i] = String.class;
}
Method actionMethod = ReflectionUtils.findMethod(o.getClass(), action, argClz);
if (actionMethod == null)
throw new NullPointerException("No such method:" + action + " with args:" + Arrays.toString(argClz));
ReflectionUtils.makeAccessible(actionMethod);
final Method finalActionMethod = actionMethod;
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ReflectionUtils.invokeMethod(finalActionMethod, o, args);
}
});
logD("OnClickWirer actions, Auto wired: " + field.getName());
}
}
示例6: doExtendedHelp
import com.nick.scalpel.core.utils.ReflectionUtils; //导入方法依赖的package包/类
@Override
public void doExtendedHelp(final ListView view, Field field, Object targetObj) {
DataProvider provider = field.getAnnotation(DataProvider.class);
if (provider == null) return;
String providerName = provider.name();
Preconditions.checkState(!TextUtils.isEmpty(providerName));
Object listViewDataProviderObj;
switch (providerName) {
case ThisThatNull.THIS:
listViewDataProviderObj = targetObj;
break;
default:
Field providerField = ReflectionUtils.findField(targetObj, providerName);
Preconditions.checkNotNull(providerField);
ReflectionUtils.makeAccessible(providerField);
listViewDataProviderObj = ReflectionUtils.getField(providerField, targetObj);
Preconditions.checkNotNull(listViewDataProviderObj);
}
Preconditions.checkState(listViewDataProviderObj instanceof ListViewDataProvider);
final ListViewDataProvider listViewDataProvider = (ListViewDataProvider) listViewDataProviderObj;
ListViewViewProvider listViewViewProvider = null;
ViewProvider viewProvider = field.getAnnotation(ViewProvider.class);
if (viewProvider != null) {
final int id = viewProvider.id();
listViewViewProvider = new ListViewViewProvider() {
@Override
public int getItemViewId() {
return id;
}
};
}
final ListViewViewProvider finalListViewViewProvider = listViewViewProvider;
SharedExecutor.get().execute(new Runnable() {
@Override
public void run() {
listViewDataProvider.loadInBackground();
mHandler.post(new Runnable() {
@Override
public void run() {
QuickAdapter quickAdapter = new QuickAdapter(listViewDataProvider,
finalListViewViewProvider, view.getContext());// Using view.context to keep the activity theme.
view.setAdapter(quickAdapter);
}
});
}
});
}