本文整理匯總了Java中com.badlogic.gdx.utils.reflect.ClassReflection.forName方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassReflection.forName方法的具體用法?Java ClassReflection.forName怎麽用?Java ClassReflection.forName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.utils.reflect.ClassReflection
的用法示例。
在下文中一共展示了ClassReflection.forName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getClass
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的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;
}
示例2: PlatformDistributor
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的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");
}
}
示例3: get
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private Bundlable get() {
try {
String clName = getString( CLASS_NAME );
if (aliases.containsKey( clName )) {
clName = aliases.get( clName );
}
Class<?> cl = ClassReflection.forName( clName );
if (cl != null) {
Bundlable object = (Bundlable) ClassReflection.newInstance(cl);
object.restoreFromBundle( this );
return object;
} else {
return null;
}
} catch (Exception e) {
e = null;
return null;
}
}
示例4: read
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的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?");
}
}
示例5: readActions
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的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>
* <actionClassName parameter1Name="parameter1Value" parameter2Name="parameter2Value" ... />
* </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);
}
}
}
}
示例6: tryLoadDesktopTwitterAPI
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void tryLoadDesktopTwitterAPI() {
if (Gdx.app.getType() != ApplicationType.Desktop) {
Gdx.app.debug(TAG, "Skip loading Twitter API for Desktop. Not running Desktop. \n");
return;
}
try {
final Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.desktop.DesktopTwitterAPI");
Object twitter = ClassReflection.getConstructor(twitterClazz, TwitterConfig.class).newInstance(config);
twitterAPI = (TwitterAPI) twitter;
Gdx.app.debug(TAG, "gdx-twitter for Desktop loaded successfully.");
} catch (ReflectionException e) {
Gdx.app.debug(TAG, "Error creating gdx-twitter for Desktop (are the gdx-twitter **.jar files installed?). \n");
e.printStackTrace();
}
}
示例7: tryLoadHTMLTwitterAPI
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的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();
}
}
示例8: tryLoadIOSTWitterAPI
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的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();
}
}
示例9: newDialog
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
@Override
public <T> T newDialog(Class<T> cls) {
String className = cls.getName();
if (registeredDialogs.containsKey(className)) {
try {
final Class<T> dialogClazz = ClassReflection.forName(registeredDialogs.get(className));
Object dialogObject = ClassReflection.getConstructor(dialogClazz, Activity.class).newInstance(activity);
return dialogClazz.cast(dialogObject);
} catch (Exception e) {
e.printStackTrace();
}
}
throw new RuntimeException(cls.getName() + "is not registered.");
}
示例10: installDesktopGDXDialogs
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
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();
}
}
示例11: installHTMLGDXDialogs
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
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();
}
}
示例12: extractFromBinaries
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
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;
}
示例13: findClassesAnnotatedWith
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
@Override
public Array<Class<?>> findClassesAnnotatedWith(final Class<?> root,
final Iterable<Class<? extends Annotation>> annotations) {
final Array<Class<?>> result = GdxArrays.newArray();
final String packageName = extractPackageName(root);
for (final String className : JTranscReflection.getAllClasses()) {
if (Strings.isNotEmpty(className) && className.startsWith(packageName)) {
try {
final Class<?> processed = ClassReflection.forName(className);
if (isAnnotatedWithAny(processed, annotations)) {
result.add(processed);
}
} catch (final Exception exception) {
Gdx.app.debug("JTransc", "Error thrown during processing of class: " + className, exception);
}
}
}
return result;
}
示例14: processClassName
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
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.
}
}
示例15: findClass
import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private static Class<?> findClass(String name) {
try {
return ClassReflection.forName(name);
} catch (Exception e) {
return null;
}
}