當前位置: 首頁>>代碼示例>>Java>>正文


Java Reflection.getFieldValue方法代碼示例

本文整理匯總了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.
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn,代碼行數:17,代碼來源:DisposeAnnotationProcessor.java

示例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);
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:24,代碼來源:LmlMacroAnnotationProcessor.java

示例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);
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:18,代碼來源:LmlParserSyntaxAnnotationProcessor.java

示例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);
    }
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:17,代碼來源:ObjectMapAssetInjection.java

示例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);
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:17,代碼來源:ObjectSetAssetInjection.java

示例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));
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:27,代碼來源:AssetService.java

示例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);
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:25,代碼來源:AvailableLocalesAnnotationProcessor.java

示例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);
    }
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:23,代碼來源:LmlMacroAnnotationProcessor.java

示例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);
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:11,代碼來源:StageViewportAnnotationProcessor.java

示例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));
    }
}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:9,代碼來源:LazyAssetInjection.java

示例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);
    }
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:11,代碼來源:I18nBundleAnnotationProcessor.java

示例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);
    }

}
 
開發者ID:gdx-libs,項目名稱:gdx-autumn-mvc,代碼行數:16,代碼來源:LocaleService.java

示例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);
    }
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:10,代碼來源:FieldActorConsumer.java

示例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);
    }
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:9,代碼來源:ReflectionPreference.java


注:本文中的com.github.czyzby.kiwi.util.gdx.reflection.Reflection.getFieldValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。