Java 类com.badlogic.gdx.utils.reflect.ReflectionException 实例源码

项目:Mindustry    文件:ByteSerializer.java   
@Override
public Object read(ByteBuffer byteBuffer) {
    try {
        byte id = byteBuffer.get();
        if(id == -2){
           return FrameworkSerializer.read(byteBuffer);
        }else {
            Class<?> type = Registrator.getByID(id);
            Packet packet = (Packet) ClassReflection.newInstance(type);
            packet.read(byteBuffer);
            return packet;
        }
    }catch (ReflectionException e){
        throw new RuntimeException(e);
    }
}
项目:gdx-cclibs    文件:JsonFieldUpdater.java   
/**
 * Returns the Class matching the name of the JsonValue, or null if there is no match or it's nameless.
 */
private Class getClass(JsonValue value, ObjectMap<String, Class> tagsToClasses) {
    if (value.name() != null && value.name().length() > 0) {
        String className = value.name();
        Class type = tagsToClasses.get(className);
        if (type == null) {
            try {
                type = ClassReflection.forName(className);
            } catch (ReflectionException ex) {
                type = null;
            }
        }
        return type;
    }
    return null;
}
项目:gdx-fireapp    文件:PlatformDistributor.java   
/**
 * Creates platform specific object by reflection.
 * <p>
 * Uses class names given by {@link #getAndroidClassName()} and {@link #getIOSClassName()}
 * <p>
 * If you need to run project on different platform use {@link #setMockObject(Object)} to polyfill platform object.
 *
 * @throws PlatformDistributorException Throws when something is wrong with environment
 */
@SuppressWarnings("unchecked")
protected PlatformDistributor() throws PlatformDistributorException
{
    String className = null;
    if (Gdx.app.getType() == Application.ApplicationType.Android) {
        className = getAndroidClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.iOS) {
        className = getIOSClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        className = getWebGLClassName();
    } else {
        return;
    }
    try {
        Class objClass = ClassReflection.forName(className);
        platformObject = (T) ClassReflection.getConstructor(objClass).newInstance();
    } catch (ReflectionException e) {
        e.printStackTrace();
        throw new PlatformDistributorException("Something wrong with environment");
    }
}
项目:JavityEngine    文件:RemoteInvoker.java   
public void invoke(JGameObject clickTarget) {
    for (Component component : clickTarget.getAllComponents()) {
        if (component.getClass().getName().equals(invokeComponent)) {
            Object[] parameters = args.toArray(new Object[args.size()]);
            Class[] parametersType = new Class[args.size()];
            for (int x = 0; x < parameters.length; x++) {
                parametersType[x] = parameters[x].getClass();
            }

            try {
                Method method = ClassReflection.getDeclaredMethod(component.getClass(), invokeMethod,
                        parametersType);
                method.invoke(component, parameters);
            } catch (ReflectionException e) {
                e.printStackTrace();
            }
        }
    }
}
项目:skin-composer    文件:StyleProperty.java   
@Override
public void read(Json json, JsonValue jsonValue) {
    try {
        name = jsonValue.getString("name");
        optional = jsonValue.getBoolean("optional");
        if (jsonValue.get("value").isNumber()) {
            type = Float.TYPE;
            value = Double.parseDouble(jsonValue.getString("value"));
        } else {
            type = ClassReflection.forName(jsonValue.getString("type"));
            if (jsonValue.get("value").isNull()) {
                value = null;
            } else {
                value = jsonValue.getString("value");
            }
        }
    } catch (ReflectionException ex) {
        Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex);
        DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?");
    }
}
项目:skin-composer    文件:JsonData.java   
@Override
public void read(Json json, JsonValue jsonData) {
    try {
        colors = json.readValue("colors", Array.class, jsonData);
        fonts = json.readValue("fonts", Array.class, jsonData);
        classStyleMap = new OrderedMap<>();
        for (JsonValue data : jsonData.get("classStyleMap").iterator()) {
            classStyleMap.put(ClassReflection.forName(data.name), json.readValue(Array.class, data));
        }
        for (Array<StyleData> styleDatas : classStyleMap.values()) {
            for (StyleData styleData : styleDatas) {
                styleData.jsonData = this;
            }
        }
        customClasses = json.readValue("customClasses", Array.class, CustomClass.class, new Array<>(), jsonData);
        for (CustomClass customClass : customClasses) {
            customClass.setMain(main);
        }
    } catch (ReflectionException e) {
        Gdx.app.log(getClass().getName(), "Error parsing json data during file read", e);
        main.getDialogFactory().showDialogError("Error while reading file...", "Error while attempting to read save file.\nPlease ensure that file is not corrupted.\n\nOpen error log?");
    }
}
项目:Inspiration    文件:Task.java   
/** Clones this task to a new one. If you don't specify a clone strategy through {@link #TASK_CLONER} the new task is
 * instantiated via reflection and {@link #copyTo(Task)} is invoked.
 * @return the cloned task
 * @throws TaskCloneException if the task cannot be successfully cloned. */
@SuppressWarnings("unchecked")
public Task<E> cloneTask () {
    if (TASK_CLONER != null) {
        try {
            return TASK_CLONER.cloneTask(this);
        } catch (Throwable t) {
            throw new TaskCloneException(t);
        }
    }
    try {
        Task<E> clone = copyTo(ClassReflection.newInstance(this.getClass()));
        clone.guard = guard == null ? null : guard.cloneTask();
        return clone;
    } catch (ReflectionException e) {
        throw new TaskCloneException(e);
    }
}
项目:fabulae    文件:XMLUtil.java   
/**
 * Read the actions from the suppled XML element and loads them into the
 * supplied ActionsContainer.
 * 
 * The XML element should contain children in the following format:
 * 
 * <pre>
 * &lt;actionClassName parameter1Name="parameter1Value" parameter2Name="parameter2Value" ... /&gt;
 * </pre>
 * 
 * @param ac
 * @param actionsElement
 */
@SuppressWarnings({ "unchecked" })
public static void readActions(ActionsContainer ac, Element actionsElement) {
    if (actionsElement != null) {
        for (int i = 0; i < actionsElement.getChildCount(); ++i) {
            Element actionElement = actionsElement.getChild(i);
            String implementationClassName = actionElement.getName();
            implementationClassName = Action.class.getPackage().getName() + "."
                    + StringUtil.capitalizeFirstLetter(implementationClassName);
            try {
                Class<? extends Action> actionClass = (Class<? extends Action>) ClassReflection
                        .forName(implementationClassName);
                Action newAction = ac.addAction(actionClass);
                if (newAction != null) {
                    newAction.loadFromXML(actionElement);
                }

            } catch (ReflectionException e) {
                throw new GdxRuntimeException(e);
            }
        }
    }
}
项目:gdx-twitter    文件:TwitterSystemUnitTests.java   
@Test
@SuppressWarnings("static-access")
public void androidIsLoadedWithV4Fragment() {
    androidSetup();

    Mockito.when(classReflectionMock.isAssignableFrom(activityStub.getClass(), Gdx.app.getClass())).thenReturn(false);
    Mockito.when(classReflectionMock.isAssignableFrom(supportFragmentStub.getClass(), Gdx.app.getClass())).thenReturn(true);

    try {
        Mockito.when(constructorMock.newInstance(activityStub, config)).thenReturn(twitterAPIStub);
        Mockito.when(classReflectionMock.forName("android.support.v4.app.Fragment")).thenReturn(supportFragmentStub.getClass());
        Mockito.when(classReflectionMock.getMethod(supportFragmentStub.getClass(), "getActivity")).thenReturn(methodMock);
        Mockito.when(methodMock.invoke(Gdx.app)).thenReturn(activityStub);

    } catch (ReflectionException e) {
    }

    fixture = new TwitterSystem(config);

    assertEquals(twitterAPIStub, fixture.getTwitterAPI());
}
项目:gdx-twitter    文件:TwitterSystemUnitTests.java   
@Test
@SuppressWarnings("static-access")
public void androidIsLoadedWithFragment() {
    androidSetup();

    Mockito.when(classReflectionMock.isAssignableFrom(activityStub.getClass(), Gdx.app.getClass())).thenReturn(false);
    Mockito.when(classReflectionMock.isAssignableFrom(supportFragmentStub.getClass(), Gdx.app.getClass())).thenReturn(false);
    Mockito.when(classReflectionMock.isAssignableFrom(fragmentStub.getClass(), Gdx.app.getClass())).thenReturn(true);

    try {
        Mockito.when(constructorMock.newInstance(activityStub, config)).thenReturn(twitterAPIStub);
        Mockito.when(classReflectionMock.forName("android.app.Fragment")).thenReturn(fragmentStub.getClass());
        Mockito.when(classReflectionMock.getMethod(fragmentStub.getClass(), "getActivity")).thenReturn(methodMock);
        Mockito.when(methodMock.invoke(Gdx.app)).thenReturn(activityStub);

    } catch (ReflectionException e) {
    }

    fixture = new TwitterSystem(config);
    assertEquals(twitterAPIStub, fixture.getTwitterAPI());
}
项目:gdx-twitter    文件:TwitterSystem.java   
private void tryLoadHTMLTwitterAPI() {
    if (Gdx.app.getType() != ApplicationType.WebGL) {
        Gdx.app.debug(TAG, "Skip loading gdx-twitter for HTML. Not running HTML. \n");
        return;
    }

    try {

        final Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.html.HTMLTwitterAPI");
        Object twitter = ClassReflection.getConstructor(twitterClazz, TwitterConfig.class).newInstance(config);

        twitterAPI = (TwitterAPI) twitter;

        Gdx.app.debug(TAG, "gdx-twitter for HTML loaded successfully.");

    } catch (ReflectionException e) {
        Gdx.app.debug(TAG, "Error creating gdx-twitter for HTML (are the gdx-twitter **.jar files installed?). \n");
        e.printStackTrace();
    }

}
项目:gdx-twitter    文件:TwitterSystem.java   
private void tryLoadIOSTWitterAPI() {

        if (Gdx.app.getType() != ApplicationType.iOS) {
            Gdx.app.debug(TAG, "Skip loading gdx-twitter for iOS. Not running iOS. \n");
            return;
        }
        try {

            // Class<?> activityClazz =
            // ClassReflection.forName("com.badlogic.gdx.backends.iosrobovm.IOSApplication");
            final Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.ios.IOSTwitterAPI");

            Object twitter = ClassReflection.getConstructor(twitterClazz, TwitterConfig.class).newInstance(config);

            twitterAPI = (TwitterAPI) twitter;

            Gdx.app.debug(TAG, "gdx-twitter for iOS loaded successfully.");

        } catch (ReflectionException e) {
            Gdx.app.debug(TAG, "Error creating gdx-twitter for iOS (are the gdx-twitter **.jar files installed?). \n");
            e.printStackTrace();
        }

    }
项目:gdx-lml    文件:AssetService.java   
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);
    }
}
项目:gdx-facebook    文件:GDXFacebookLoaderUnitTests.java   
@Test
public void returnAndroidGDXFacebookWhenOnAndroid_core_app_Fragment() {

    androidPremocking();

    when(ClassReflection.isAssignableFrom(Activity.class, mockObject.getClass())).thenReturn(false);

    try {
        when(ClassReflection.forName("android.support.v4.app.Fragment")).thenReturn(null);
        when(ClassReflection.forName("android.app.Fragment")).thenReturn(android.app.Fragment.class);

        when(ClassReflection.isAssignableFrom(android.app.Fragment.class, mockObject.getClass())).thenReturn(true);
        when(ClassReflection.getMethod(android.app.Fragment.class, "getActivity")).thenReturn(mockMethod);
        when(mockMethod.invoke(mockObject)).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    androidPostmocking();

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof AndroidGDXFacebook);
}
项目:gdx-facebook    文件:GDXFacebookLoaderUnitTests.java   
@Test
public void returnIOSGDXFacebookWhenOnIOS() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(IOSGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_IOS)).thenReturn(IOSGDXFacebook.class);
        when(ClassReflection.getConstructor(IOSGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof IOSGDXFacebook);
}
项目:gdx-facebook    文件:GDXFacebookLoaderUnitTests.java   
@Test
public void returnDesktopGDXFacebookWhenOnDesktop() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.Desktop);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(DesktopGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_DESKTOP)).thenReturn(DesktopGDXFacebook.class);
        when(ClassReflection.getConstructor(DesktopGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof DesktopGDXFacebook);
}
项目:gdx-facebook    文件:GDXFacebookLoaderUnitTests.java   
@Test
public void returnHTMLGDXFacebookWhenOnWebGL() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.WebGL);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(HTMLGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_HTML)).thenReturn(HTMLGDXFacebook.class);
        when(ClassReflection.getConstructor(HTMLGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof HTMLGDXFacebook);
}
项目:gdx-lml    文件:ObjectMapAssetInjection.java   
@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);
    }
}
项目:Roguelike    文件:AbstractOnDeathEffect.java   
public static AbstractOnDeathEffect load(Element xml)
{
    Class<AbstractOnDeathEffect> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractOnDeathEffect type = null;

    try
    {
        type = (AbstractOnDeathEffect)ClassReflection.newInstance(c);
    }
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:Roguelike    文件:AbstractSpreadStyle.java   
public static AbstractSpreadStyle load(Element xml)
{       
    Class<AbstractSpreadStyle> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractSpreadStyle type = null;

    try
    {
        type = (AbstractSpreadStyle)ClassReflection.newInstance(c);
    } 
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:Roguelike    文件:AbstractDurationStyle.java   
public static AbstractDurationStyle load(Element xml)
{       
    Class<AbstractDurationStyle> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractDurationStyle type = null;

    try
    {
        type = (AbstractDurationStyle)ClassReflection.newInstance(c);
    } 
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:Roguelike    文件:AbstractTownEvent.java   
public static AbstractTownEvent load(XmlReader.Element xml )
{
    Class<AbstractTownEvent> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractTownEvent type = null;

    try
    {
        type = (AbstractTownEvent) ClassReflection.newInstance( c );
    }
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:Roguelike    文件:AbstractHitType.java   
public static AbstractHitType load(XmlReader.Element xml )
{
    Class<AbstractHitType> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractHitType type = null;

    try
    {
        type = (AbstractHitType) ClassReflection.newInstance( c );
    }
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:Roguelike    文件:AbstractTargetingType.java   
public static AbstractTargetingType load(Element xml)
{
    Class<AbstractTargetingType> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractTargetingType type = null;

    try
    {
        type = (AbstractTargetingType)ClassReflection.newInstance(c);
    }
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:Roguelike    文件:AbstractCostType.java   
public static AbstractCostType load(Element xml)
{       
    Class<AbstractCostType> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractCostType type = null;

    try
    {
        type = (AbstractCostType)ClassReflection.newInstance(c);
    } 
    catch (ReflectionException e)
    {
        e.printStackTrace();
    }

    type.parse(xml);

    return type;
}
项目:gdx-lml    文件:AndroidClassScanner.java   
private static void processClassName(final Iterable<Class<? extends Annotation>> annotations,
        final Array<Class<?>> result, final String packageName, final String className) {
    if (!className.startsWith(packageName)) {
        return;
    }
    try {
        final Class<?> classToProcess = ClassReflection.forName(className);
        for (final Class<? extends Annotation> annotation : annotations) {
            if (ClassReflection.isAnnotationPresent(classToProcess, annotation)) {
                result.add(classToProcess);
                return;
            }
        }
    } catch (final ReflectionException exception) {
        exception.printStackTrace(); // Unexpected. Classes should be present.
    }
}
项目:gdx-lml    文件:ObjectSetAssetInjection.java   
@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);
    }
}
项目:gdx-dialogs    文件:GDXDialogsSystem.java   
private void installDesktopGDXDialogs() {
    if (Gdx.app.getType() != ApplicationType.Desktop) {
        showDebugSkipInstall(ApplicationType.Desktop.name());
        return;
    }
    try {

        final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.desktop.DesktopGDXDialogs");

        Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance();

        this.gdxDialogs = (GDXDialogs) dialogManager;

        showDebugInstallSuccessful(ApplicationType.Desktop.name());

    } catch (ReflectionException e) {
        showErrorInstall(ApplicationType.Desktop.name(), "desktop");
        e.printStackTrace();
    }

}
项目:gdx-dialogs    文件:GDXDialogsSystem.java   
private void installHTMLGDXDialogs() {
    if (Gdx.app.getType() != ApplicationType.WebGL) {
        showDebugSkipInstall(ApplicationType.WebGL.name());
        return;
    }

    try {

        final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.html.HTMLGDXDialogs");
        Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance();

        this.gdxDialogs = (GDXDialogs) dialogManager;
        showDebugInstallSuccessful(ApplicationType.WebGL.name());

    } catch (ReflectionException e) {
        showErrorInstall(ApplicationType.WebGL.name(), "html");
        e.printStackTrace();
    }

}
项目:gdx-autumn    文件:FallbackDesktopClassScanner.java   
private static Array<Class<?>> extractFromBinaries(final Iterable<Class<? extends Annotation>> annotations,
        final String mainPackageName, final Queue<Pair<File, Integer>> filesWithDepthsToProcess)
                throws ReflectionException {
    final Array<Class<?>> result = GdxArrays.newArray();
    while (!filesWithDepthsToProcess.isEmpty()) {
        final Pair<File, Integer> classPathFileWithDepth = filesWithDepthsToProcess.poll();
        final File classPathFile = classPathFileWithDepth.getFirst();
        final int depth = classPathFileWithDepth.getSecond();
        if (classPathFile.isDirectory()) {
            addAllChildren(filesWithDepthsToProcess, classPathFile, depth);
        } else {
            final String className = getBinaryClassName(mainPackageName, classPathFile, depth);
            if (!isFromPackage(mainPackageName, className)) {
                continue;
            }
            final Class<?> classToProcess = ClassReflection.forName(className);
            processClass(annotations, result, classToProcess);
        }
    }
    return result;
}
项目:gdx-autumn-mvc    文件:LmlMacroAnnotationProcessor.java   
@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);
    }
}
项目:gdx-autumn-mvc    文件:SkinAssetAnnotationProcessor.java   
/** 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;
}
项目:gdx-autumn-mvc    文件:LmlParserSyntaxAnnotationProcessor.java   
@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);
    }
}
项目:gdx-autumn-mvc    文件:ObjectMapAssetInjection.java   
@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);
    }
}
项目:gdx-autumn-mvc    文件:ArrayAssetInjection.java   
@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);
    }
}
项目:gdx-autumn-mvc    文件:AssetService.java   
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);
    }
}
项目:gdx-autumn-mvc    文件:AssetService.java   
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));
    }
}
项目:gdx-autumn-mvc    文件:AssetService.java   
@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));
    }
}
项目:gdx-autumn-mvc    文件:AvailableLocalesAnnotationProcessor.java   
@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);
    }
}
项目:gdx-lml    文件:AbstractLmlParser.java   
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);
        }
    }
}