Java Code Examples for com.badlogic.gdx.utils.reflect.ReflectionException#printStackTrace()

The following examples show how to use com.badlogic.gdx.utils.reflect.ReflectionException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomInputModule.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void attachModuleToMyInput(AbstractModule module, int mySlot, int targetSlot) {
    addInputSlot(slotCount++);
    super.attachModuleToMyInput(module, mySlot, targetSlot);

    // let's figure out the type
    if(valueType == null) {
        valueType = module.getOutputSlot(targetSlot).getValue().getClass();
    } else {
        Class newValueType = module.getOutputSlot(targetSlot).getValue().getClass();
        if(valueType != newValueType) {
            // changing value detaching all previous values
            // detach code goes here
            valueType = newValueType;
        }
    }
    // re init all previous values
    try {
        for(Slot slot : getInputSlots().values()) {
            slot.setValue((Value) ClassReflection.newInstance(valueType));
        }
        getOutputSlot(0).setValue((Value) ClassReflection.newInstance(valueType));
    } catch (ReflectionException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@Test
public void returnAndroidGDXFacebookWhenOnAndroid_core_support_v4_app_Fragment() {

    androidPremocking();

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

    try {
        when(ClassReflection.forName("android.support.v4.app.Fragment")).thenReturn(Fragment.class);
        when(ClassReflection.isAssignableFrom(Fragment.class, mockObject.getClass())).thenReturn(true);
        when(ClassReflection.getMethod(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);
}
 
Example 3
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 6
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 7
Source File: GDXDialogsSystem.java    From gdx-dialogs with Apache License 2.0 6 votes vote down vote up
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();
	}

}
 
Example 8
Source File: GDXDialogsSystem.java    From gdx-dialogs with Apache License 2.0 6 votes vote down vote up
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();
	}

}
 
Example 9
Source File: ModuleBoardWidget.java    From talos with Apache License 2.0 5 votes vote down vote up
public <T extends AbstractModule> ModuleWrapper createModuleWrapper (T module, float x, float y) {
    ModuleWrapper<T> moduleWrapper = null;

    if (module == null) return null;

    Class<T> moduleClazz = (Class<T>)module.getClass();

    try {
        moduleWrapper = ClassReflection.newInstance(WrapperRegistry.get(moduleClazz));
        int id = getUniqueIdForModuleWrapper();
        moduleWrapper.setModule(module);
        moduleWrapper.setId(id);
        module.setIndex(id);
        moduleWrapper.setBoard(this);

        tmp.set(x, Gdx.graphics.getHeight() - y);
        moduleContainer.screenToLocalCoordinates(tmp);

        moduleWrapper.setPosition(tmp.x - moduleWrapper.getWidth()/2f, tmp.y - moduleWrapper.getHeight()/2f);
        getModuleWrappers().add(moduleWrapper);
        moduleContainer.addActor(moduleWrapper);

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


    // check if there was connect request
    tryAndConnectLasCC(moduleWrapper);


    return moduleWrapper;
}
 
Example 10
Source File: ModuleListPopup.java    From talos with Apache License 2.0 5 votes vote down vote up
private void registerModule(XmlReader.Element module) {
    try {
        Class moduleClazz = ClassReflection.forName("com.talosvfx.talos.runtime.modules." + module.getText());
        Class wrapperClazz =ClassReflection.forName("com.talosvfx.talos.editor.wrappers." + module.getAttribute("wrapper"));
        WrapperRegistry.reg(moduleClazz, wrapperClazz);
        TalosMain.Instance().moduleNames.put(wrapperClazz, module.getAttribute("name"));
    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    WrapperRegistry.reg(EmitterModule.class, EmitterModuleWrapper.class);
}
 
Example 11
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
private void androidPremocking() {

        Application mockApplication = mock(Application.class);
        when(mockApplication.getType()).thenReturn(Application.ApplicationType.Android);
        Gdx.app = mockApplication;

        try {
            mockConstructor = PowerMockito.mock(Constructor.class);
            mockFacebook = mock(AndroidGDXFacebook.class);
            mockField = mock(Field.class);
            mockObject = mock(Object.class);
            mockMethod = mock(Method.class);

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


            when(ClassReflection.forName("com.badlogic.gdx.Gdx")).thenReturn(Gdx.class);
            when(ClassReflection.getField(Gdx.class, "app")).thenReturn(mockField);
            when(mockField.get(null)).thenReturn(mockObject);


            when(ClassReflection.forName("com.badlogic.gdx.backends.android.AndroidEventListener")).thenReturn(AndroidEventListener.class);
            when(ClassReflection.forName("android.app.Activity")).thenReturn(Activity.class);

        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    }
 
Example 12
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
private void androidPostmocking() {
    try {

        when(ClassReflection.getConstructor(AndroidGDXFacebook.class, Activity.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject(), any(GDXFacebookConfig.class))).thenReturn(mockFacebook);
        when(ClassReflection.getMethod(mockObject.getClass(), "addAndroidEventListener", AndroidEventListener.class)).thenReturn(mockMethod);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }
}
 
Example 13
Source File: GDXDialogsSystem.java    From gdx-dialogs with Apache License 2.0 5 votes vote down vote up
private void installGdxReflections() {

		try {
			gdxClazz = ClassReflection.forName("com.badlogic.gdx.Gdx");
			gdxAppObject = ClassReflection.getField(gdxClazz, "app").get(null);

		} catch (ReflectionException e) {
			e.printStackTrace();
			throw new RuntimeException("No libGDX environment. \n");
		}

	}