本文整理匯總了Java中com.github.czyzby.kiwi.util.gdx.reflection.Reflection.newInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Reflection.newInstance方法的具體用法?Java Reflection.newInstance怎麽用?Java Reflection.newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.czyzby.kiwi.util.gdx.reflection.Reflection
的用法示例。
在下文中一共展示了Reflection.newInstance方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processLmlInjectAnnotation
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
protected <View> void processLmlInjectAnnotation(final View view, final Field field) {
if (Reflection.isAnnotationPresent(field, LmlInject.class)) {
try {
final LmlInject injectionData = Reflection.getAnnotation(field, LmlInject.class);
final Class<?> injectedValueType = getLmlInjectedValueType(field, injectionData);
if (LmlParser.class.equals(injectedValueType)) {
// Injected type equals LmlParser - parser injection was requested:
Reflection.setFieldValue(field, view, this);
return;
}
Object value = Reflection.getFieldValue(field, view);
if (value == null || injectionData.newInstance()) {
value = Reflection.newInstance(injectedValueType);
Reflection.setFieldValue(field, view, value);
}
// Processing field's value annotations:
processViewFieldAnnotations(value);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException(
"Unable to inject value of LmlInject-annotated field: " + field + " of view: " + view,
exception);
}
}
}
示例2: provide
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** @param dependencyClass required class.
* @return an instance of the class. If there is a component of this class in the context, component will be
* returned. If there is a provider that provides instances of this class, provider's result will be
* returned. If {@link #setCreateMissingDependencies(boolean)} is set to true, a new instance of the class
* will be created with no-arg constructor. Otherwise, an exception is thrown.
* @throws GdxRuntimeException if there are multiple components or providers mapped to the same class, if unable to
* create a new instance with no-arg constructor or if unable to provide an instance at all.
* @param <Type> type of the provided object. */
@SuppressWarnings("unchecked")
public <Type> Type provide(final Class<Type> dependencyClass) {
if (isPresent(dependencyClass)) {
// Components are mapped by their type, safe to cast.
return (Type) getComponent(dependencyClass);
} else if (isProviderPresentFor(dependencyClass)) {
return getProvider(dependencyClass).provide();
} else if (createMissingDependencies) {
return Reflection.newInstance(dependencyClass);
}
throw new GdxRuntimeException("Unable to provide an instance of: " + dependencyClass
+ ". Not available in context and no provider selected.");
}
示例3: createRenderer
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private ViewRenderer createRenderer() {
if (ViewRenderer.class.equals(viewData.renderer())) {
if (wrappedObject instanceof ViewRenderer) {
return (ViewRenderer) wrappedObject;
}
return InterfaceService.DEFAULT_VIEW_RENDERER;
} else if (wrappedObject.getClass().equals(viewData.renderer())) {
return (ViewRenderer) wrappedObject; // Safe to cast, wrapped has to implement VR.
}
return Reflection.newInstance(viewData.renderer());
}
示例4: createResizer
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private ViewResizer createResizer() {
if (ViewResizer.class.equals(viewData.resizer())) {
if (wrappedObject instanceof ViewResizer) {
return (ViewResizer) wrappedObject;
}
return InterfaceService.DEFAULT_VIEW_RESIZER;
} else if (wrappedObject.getClass().equals(viewData.resizer())) {
return (ViewResizer) wrappedObject; // Safe to cast, wrapped has to implement VR.
}
return Reflection.newInstance(viewData.resizer());
}
示例5: createPauser
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private ViewPauser createPauser() {
if (ViewPauser.class.equals(viewData.pauser())) {
if (wrappedObject instanceof ViewPauser) {
return (ViewPauser) wrappedObject;
}
return InterfaceService.DEFAULT_VIEW_PAUSER;
} else if (wrappedObject.getClass().equals(viewData.pauser())) {
return (ViewPauser) wrappedObject; // Safe to cast, wrapped has to implement VP.
}
return Reflection.newInstance(viewData.pauser());
}
示例6: createShower
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private ViewShower createShower() {
if (ViewShower.class.equals(viewData.shower())) {
if (wrappedObject instanceof ViewShower) {
return (ViewShower) wrappedObject;
}
return InterfaceService.DEFAULT_VIEW_SHOWER;
} else if (wrappedObject.getClass().equals(viewData.shower())) {
return (ViewShower) wrappedObject; // Safe to cast, wrapped has to implement VS.
}
return Reflection.newInstance(viewData.shower());
}
示例7: createInitializer
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
private ViewInitializer createInitializer() {
if (ViewInitializer.class.equals(viewData.initializer())) {
if (wrappedObject instanceof ViewInitializer) {
return (ViewInitializer) wrappedObject;
}
return InterfaceService.DEFAULT_VIEW_INITIALIZER;
} else if (wrappedObject.getClass().equals(viewData.initializer())) {
return (ViewInitializer) wrappedObject; // Safe to cast, wrapped has to implement VI.
}
return Reflection.newInstance(viewData.initializer());
}
示例8: createView
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public <View> View createView(final Class<View> viewClass, final String lmlTemplate) {
final View view = Reflection.newInstance(viewClass);
createView(view, lmlTemplate);
return view;
}
示例9: getInstanceOf
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
/** @param viewClass {@link AbstractLmlView} extension that represents a single view. Its instance is requested.
* @return a new instance of the passed class. By default, the instance is created using the default no-argument
* constructor using reflection. Override this method to change the view creation way. */
protected AbstractLmlView getInstanceOf(final Class<? extends AbstractLmlView> viewClass) {
return Reflection.newInstance(viewClass);
}