本文整理匯總了Java中com.github.czyzby.kiwi.util.gdx.reflection.Reflection.getFieldValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Reflection.getFieldValue方法的具體用法?Java Reflection.getFieldValue怎麽用?Java Reflection.getFieldValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.czyzby.kiwi.util.gdx.reflection.Reflection
的用法示例。
在下文中一共展示了Reflection.getFieldValue方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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);
}
}
示例4: 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);
}
}
示例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: 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));
}
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public void processField(final Field field, final StageViewport annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object provider = Reflection.getFieldValue(field, component);
setViewportProvider(provider);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to extract viewport provider.", exception);
}
}
示例10: injectAsset
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void injectAsset(final AssetService assetService) throws ReflectionException {
final Lazy lazyAsset = (Lazy) Reflection.getFieldValue(field, component);
if (!lazyAsset.isInitialized()) {
lazyAsset.set(assetService.get(assetPath, assetClass));
}
}
示例11: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public void processField(final Field field, final I18nBundle annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object bundleField = Reflection.getFieldValue(field, component);
interfaceService.addBundleFile(annotation.value(), extractBundleFile(annotation, bundleField));
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to extract i18n bundle path.", exception);
}
}
示例12: processField
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public void processField(final Field field, final I18nLocale annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
try {
final Object locale = Reflection.getFieldValue(field, component);
if (locale instanceof Locale) {
currentLocale.set((Locale) locale);
} else if (locale instanceof String) {
extractLocaleFromAnnotatedString(annotation, (String) locale);
}
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to extract application's locale.", exception);
}
}
示例13: consume
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public Object consume(final Object actor) {
try {
return Reflection.getFieldValue(field, fieldOwner);
} catch (final Exception exception) {
throw new GdxRuntimeException(
"Unable to extract field value from field: " + field + " of object: " + fieldOwner, exception);
}
}
示例14: get
import com.github.czyzby.kiwi.util.gdx.reflection.Reflection; //導入方法依賴的package包/類
@Override
public Object get() {
try {
return Reflection.getFieldValue(field, owner);
} catch (final ReflectionException exception) {
throw new GdxRuntimeException("Unable to extract field value from component: " + owner, exception);
}
}