当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionException类代码示例

本文整理汇总了Java中com.badlogic.gdx.utils.reflect.ReflectionException的典型用法代码示例。如果您正苦于以下问题:Java ReflectionException类的具体用法?Java ReflectionException怎么用?Java ReflectionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReflectionException类属于com.badlogic.gdx.utils.reflect包,在下文中一共展示了ReflectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: read

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:Anuken,项目名称:Mindustry,代码行数:17,代码来源:ByteSerializer.java

示例2: getClass

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:CypherCove,项目名称:gdx-cclibs,代码行数:19,代码来源:JsonFieldUpdater.java

示例3: PlatformDistributor

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
/**
 * 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");
    }
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:31,代码来源:PlatformDistributor.java

示例4: invoke

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
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();
			}
		}
	}
}
 
开发者ID:Radomiej,项目名称:JavityEngine,代码行数:20,代码来源:RemoteInvoker.java

示例5: read

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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?");
    }
}
 
开发者ID:raeleus,项目名称:skin-composer,代码行数:22,代码来源:StyleProperty.java

示例6: read

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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?");
    }
}
 
开发者ID:raeleus,项目名称:skin-composer,代码行数:24,代码来源:JsonData.java

示例7: cloneTask

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
/** 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);
	}
}
 
开发者ID:Mignet,项目名称:Inspiration,代码行数:22,代码来源:Task.java

示例8: readActions

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
/**
 * 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);
			}
		}
	}
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:36,代码来源:XMLUtil.java

示例9: androidIsLoadedWithV4Fragment

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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());
}
 
开发者ID:TomGrill,项目名称:gdx-twitter,代码行数:22,代码来源:TwitterSystemUnitTests.java

示例10: androidIsLoadedWithFragment

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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());
}
 
开发者ID:TomGrill,项目名称:gdx-twitter,代码行数:22,代码来源:TwitterSystemUnitTests.java

示例11: tryLoadHTMLTwitterAPI

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
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();
	}

}
 
开发者ID:TomGrill,项目名称:gdx-twitter,代码行数:22,代码来源:TwitterSystem.java

示例12: tryLoadIOSTWitterAPI

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
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();
		}

	}
 
开发者ID:TomGrill,项目名称:gdx-twitter,代码行数:25,代码来源:TwitterSystem.java

示例13: handleLazyAssetInjection

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的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);
    }
}
 
开发者ID:czyzby,项目名称:gdx-lml,代码行数:21,代码来源:AssetService.java

示例14: returnAndroidGDXFacebookWhenOnAndroid_core_app_Fragment

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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);
}
 
开发者ID:TomGrill,项目名称:gdx-facebook,代码行数:25,代码来源:GDXFacebookLoaderUnitTests.java

示例15: returnIOSGDXFacebookWhenOnIOS

import com.badlogic.gdx.utils.reflect.ReflectionException; //导入依赖的package包/类
@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);
}
 
开发者ID:TomGrill,项目名称:gdx-facebook,代码行数:22,代码来源:GDXFacebookLoaderUnitTests.java


注:本文中的com.badlogic.gdx.utils.reflect.ReflectionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。