本文整理匯總了Java中com.github.czyzby.kiwi.util.gdx.reflection.Reflection類的典型用法代碼示例。如果您正苦於以下問題:Java Reflection類的具體用法?Java Reflection怎麽用?Java Reflection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Reflection類屬於com.github.czyzby.kiwi.util.gdx.reflection包,在下文中一共展示了Reflection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dispose
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@Override
public void dispose() {
try {
final Object value = Reflection.getFieldValue(field, fieldOwner);
if (value instanceof Disposable) {
((Disposable) value).dispose();
} else if (value instanceof Lazy<?>) {
final Lazy<?> lazy = (Lazy<?>) value;
if (lazy.isInitialized() && lazy.get() instanceof Disposable) {
((Disposable) lazy.get()).dispose();
}
}
} catch (final Exception exception) {
Exceptions.ignore(exception); // Ignored. Closing the application, invalid objects can occur.
}
}
示例2: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@Override
public void processField(final Field field, final LmlMacro annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object macroData = Reflection.getFieldValue(field, component);
final LmlParser parser = interfaceService.get().getParser();
final FileType fileType = annotation.fileType();
if (macroData instanceof String) {
parser.parseTemplate(Gdx.files.getFileHandle((String) macroData, fileType));
} else if (macroData instanceof String[]) {
for (final String macroPath : (String[]) macroData) {
parser.parseTemplate(Gdx.files.getFileHandle(macroPath, fileType));
}
} else {
throw new GdxRuntimeException("Invalid type of LML macro definition in component: " + component
+ ". String or String[] expected, received: " + macroData + ".");
}
} catch (final ReflectionException exception) {
throw new GdxRuntimeException(
"Unable to extract macro paths from field: " + field + " of component: " + component + ".",
exception);
}
}
示例3: injectFields
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
/** Invoked when all skins are loaded. Injects skin assets.
*
* @param interfaceService used to retrieve skins.
* @return {@link OnMessage#REMOVE}. */
@SuppressWarnings("unchecked")
@OnMessage(AutumnMessage.SKINS_LOADED)
public boolean injectFields(final InterfaceService interfaceService) {
for (final Entry<Pair<String, String>, Array<Pair<Field, Object>>> entry : fieldsToInject) {
final Skin skin = interfaceService.getParser().getData().getSkin(entry.key.getSecond());
final String assetId = entry.key.getFirst();
if (skin == null) {
throw new ContextInitiationException(
"Unable to inject asset: " + assetId + ". Unknown skin ID: " + entry.key.getSecond());
}
for (final Pair<Field, Object> injection : entry.value) {
try {
Reflection.setFieldValue(injection.getFirst(), injection.getSecond(),
skin.get(assetId, injection.getFirst().getType()));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject skin asset: " + assetId + " from skin: " + skin
+ " to field: " + injection.getFirst() + " of component: " + injection.getSecond(),
exception);
}
}
}
fieldsToInject.clear();
return OnMessage.REMOVE;
}
示例4: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@Override
public void processField(final Field field, final LmlParserSyntax annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object syntax = Reflection.getFieldValue(field, component);
if (syntax instanceof LmlSyntax) {
interfaceService.getParser().setSyntax((LmlSyntax) syntax);
} else {
throw new ContextInitiationException(
"LmlParserSyntax-annotated fields need to contain an instance of LmlSyntax. Found: " + syntax
+ " in field: " + field + " of component: " + component);
}
} catch (final ReflectionException exception) {
throw new ContextInitiationException(
"Unable to extract LML syntax from field: " + field + " of component: " + component, exception);
}
}
示例5: injectAssets
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void injectAssets(final AssetService assetService) {
try {
ObjectSet set = (ObjectSet) Reflection.getFieldValue(field, component);
if (set == null) {
set = GdxSets.newSet();
}
for (final String assetPath : assetPaths) {
set.add(assetService.get(assetPath, assetType));
}
Reflection.setFieldValue(field, component, set);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject set of assets into component: " + component + ".",
exception);
}
}
示例6: injectAssets
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void injectAssets(final AssetService assetService) {
try {
ObjectMap map = (ObjectMap) Reflection.getFieldValue(field, component);
if (map == null) {
map = GdxMaps.newObjectMap();
}
for (int assetIndex = 0; assetIndex < assetPaths.length; assetIndex++) {
map.put(assetKeys[assetIndex], assetService.get(assetPaths[assetIndex], assetType));
}
Reflection.setFieldValue(field, component, map);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject map of assets into component: " + component + ".",
exception);
}
}
示例7: injectAssets
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void injectAssets(final AssetService assetService) {
try {
Array array = (Array) Reflection.getFieldValue(field, component);
if (array == null) {
array = GdxArrays.newArray();
}
for (final String assetPath : assetPaths) {
array.add(assetService.get(assetPath, assetType));
}
Reflection.setFieldValue(field, component, array);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject array of assets into component: " + component + ".",
exception);
}
}
示例8: handleLazyAssetInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
private void handleLazyAssetInjection(final Object component, final Field field, final Asset assetData) {
if (Annotations.isNotVoid(assetData.lazyCollection())) {
handleLazyAssetCollectionInjection(component, field, assetData);
return;
} else if (assetData.value().length != 1) {
throw new GdxRuntimeException(
"Lazy wrapper can contain only one asset if lazy collection type is not provided. Found multiple assets in field: "
+ field + " of component: " + component);
}
final String assetPath = assetData.value()[0];
if (!assetData.loadOnDemand()) {
load(assetPath, assetData.type());
}
try {
Reflection.setFieldValue(field, component,
Lazy.providedBy(new AssetProvider(this, assetPath, assetData.type(), assetData.loadOnDemand())));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject lazy asset.", exception);
}
}
示例9: handleRegularAssetInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
private void handleRegularAssetInjection(final Object component, final Field field, final Asset assetData) {
if (assetData.value().length != 1) {
throw new GdxRuntimeException(
"Regular fields can store only 1 asset. If the field is a collection, its type is not currently supported: only LibGDX Array, ObjectSet and ObjectMap are permitted. Regular arrays will not be supported. Found multiple assets in field: "
+ field + " of component: " + component);
}
final String assetPath = assetData.value()[0];
if (assetData.loadOnDemand()) {
// Loaded immediately.
@SuppressWarnings("unchecked") final Object asset = finishLoading(assetPath, field.getType());
try {
Reflection.setFieldValue(field, component, asset);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject asset loaded on demand.", exception);
}
} else {
load(assetPath, field.getType());
// Scheduled to be loaded, delayed injection.
assetInjections.add(new StandardAssetInjection(field, assetPath, component));
}
}
示例10: handleMapInjection
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
private void handleMapInjection(final Object component, final Field field, final Asset assetData) {
if (assetData.loadOnDemand()) {
final String[] assetPaths = assetData.value();
final String[] assetKeys = assetData.keys().length == 0 ? assetData.value() : assetData.keys();
try {
ObjectMap assets = (ObjectMap) Reflection.getFieldValue(field, component);
if (assets == null) {
assets = GdxMaps.newObjectMap();
}
for (int assetIndex = 0; assetIndex < assetPaths.length; assetIndex++) {
assets.put(assetKeys[assetIndex], finishLoading(assetPaths[assetIndex], assetData.type()));
}
Reflection.setFieldValue(field, component, assets);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to inject array of assets into: " + component, exception);
}
} else {
for (final String assetPath : assetData.value()) {
load(assetPath, assetData.type());
}
// Scheduled to be loaded, delayed injection.
assetInjections.add(new ObjectMapAssetInjection(assetData.value(), assetData.keys(), assetData.type(),
field, component));
}
}
示例11: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@Override
public void processField(final Field field, final AvailableLocales annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object locales = Reflection.getFieldValue(field, component);
if (locales instanceof String[]) {
final String[] availableLocales = (String[]) locales;
final LmlParser parser = interfaceService.getParser();
parser.getData().addArgument(annotation.viewArgumentName(), availableLocales);
for (final String locale : availableLocales) {
parser.getData().addActorConsumer(annotation.localeChangeMethodPrefix() + locale,
new LocaleChangingAction(localeService, LocaleService.toLocale(locale)));
}
return;
}
throw new GdxRuntimeException("Invalid field annotated with @AvailableLocales in component " + component
+ ". Expected String[], received: " + locales + ".");
} catch (final ReflectionException exception) {
throw new GdxRuntimeException(
"Unable to read available locales from field: " + field + " of component: " + component + ".",
exception);
}
}
示例12: processLmlActorAnnotation
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
protected <View> void processLmlActorAnnotation(final View view, final Field field) {
if (Reflection.isAnnotationPresent(field, LmlActor.class)) {
final LmlActor actorData = Reflection.getAnnotation(field, LmlActor.class);
String[] actorIds = actorData.value();
if (actorIds.length == 0) {
actorIds = new String[] { field.getName() };
}
if (Reflection.isExtending(field.getType(), Array.class)) {
injectArrayOfActors(view, field, actorIds);
} else if (Reflection.isExtending(field.getType(), ObjectSet.class)) {
injectSetOfActors(view, field, actorIds);
} else if (Reflection.isExtending(field.getType(), ObjectMap.class)) {
injectMapOfActors(view, field, actorIds);
} else {
injectSingleActor(view, field, actorIds);
}
}
}
示例13: 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);
}
}
}
示例14: mapClassFields
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
private void mapClassFields(final Class<?> containerClass) {
if (!Lml.EXTRACT_FIELDS_AS_METHODS) {
return;
}
for (final Field field : ClassReflection.getDeclaredFields(containerClass)) {
final LmlAction actionData = Reflection.getAnnotation(field, LmlAction.class);
if (actionData != null) {
final String[] ids = actionData.value();
if (ids.length > 0) {
for (final String actionId : ids) {
annotatedFields.put(actionId, field);
}
} else {
annotatedFields.put(field.getName(), field);
}
}
}
}
示例15: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入依賴的package包/類
@Override
public void processField(final Field field, final LmlMacro annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object macroData = Reflection.getFieldValue(field, component);
final FileType fileType = annotation.fileType();
if (macroData instanceof String) {
macros.add(Gdx.files.getFileHandle((String) macroData, fileType));
} else if (macroData instanceof String[]) {
for (final String macroPath : (String[]) macroData) {
macros.add(Gdx.files.getFileHandle(macroPath, fileType));
}
} else {
throw new GdxRuntimeException("Invalid type of LML macro definition in component: " + component
+ ". String or String[] expected, received: " + macroData + ".");
}
} catch (final ReflectionException exception) {
throw new GdxRuntimeException(
"Unable to extract macro paths from field: " + field + " of component: " + component + ".",
exception);
}
}