/** Returns the Class object associated with the class or interface with the supplied string name. */ static public Class forName (String name) throws ReflectionException { try { return Class.forName(name); } catch (ClassNotFoundException e) { throw new ReflectionException("Class not found: " + name, e); } }
public static GdxSample newSample (String testName) { try { return ClassReflection.newInstance(forName(testName)); } catch (ReflectionException e) { e.printStackTrace(); } return null; } }
private <T> void setEnumField(Field field, Class<?> fieldClass, T object, String value) throws SerializationException { if(field.isFinal()) { throw new SerializationException("Cannot use @Field on final enum fields. Use the @ConstructorArg method instead."); } try { field.set(object, Enum.valueOf((Class<Enum>) fieldClass, value)); } catch (ReflectionException e) { throw new SerializationException(e.getMessage(), e); } }
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"); } }
throw e; } catch (ReflectionException e) { throw new SerializationException(e.getMessage(), e); } catch (XMLStreamException e) { throw new SerializationException(e.getMessage(), e);
/** Returns the Class object associated with the class or interface with the supplied string name. */ static public Class forName (String name) throws ReflectionException { try { return Class.forName(name); } catch (ClassNotFoundException e) { throw new ReflectionException("Class not found: " + name, e); } }
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"); } }
throw new SerializationException(e.getMessage(), e); } catch (ReflectionException e) { throw new SerializationException(e.getMessage(), e); } catch (XMLStreamException e) { throw new SerializationException(e.getMessage(), e);
/** Creates a new instance of the class represented by the supplied Class. */ static public <T> T newInstance (Class<T> c) throws ReflectionException { try { return c.newInstance(); } catch (InstantiationException e) { throw new ReflectionException("Could not instantiate instance of class: " + c.getName(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Could not instantiate instance of class: " + c.getName(), e); } }
protected void step() { if (requestedReset) { requestedReset = false; try { requestedScene = ClassReflection.newInstance(sceneClass); switchScene(); } catch (ReflectionException e) { e.printStackTrace(); } } update(); }
/** Creates a new instance of the class represented by the supplied Class. */ static public <T> T newInstance (Class<T> c) throws ReflectionException { try { return c.newInstance(); } catch (InstantiationException e) { throw new ReflectionException("Could not instantiate instance of class: " + c.getName(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Could not instantiate instance of class: " + c.getName(), e); } }
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(); } }
/** Returns a {@link Field} that represents the specified public member field for the supplied class. */ static public Field getField (Class c, String name) throws ReflectionException { try { return new Field(c.getField(name)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting field: " + name + ", for class: " + c.getName(), e); } catch (NoSuchFieldException e) { throw new ReflectionException("Field not found: " + name + ", for class: " + c.getName(), e); } }
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(); } }
/** Returns a {@link Method} that represents the method declared by the supplied class which takes the supplied parameter types. */ static public Method getDeclaredMethod (Class c, String name, Class... parameterTypes) throws ReflectionException { try { return new Method(c.getDeclaredMethod(name, parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting method: " + name + ", for class: " + c.getName(), e); } catch (NoSuchMethodException e) { throw new ReflectionException("Method not found: " + name + ", for class: " + c.getName(), e); } }
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(); } }
/** Returns a {@link Constructor} that represents the constructor for the supplied class which takes the supplied parameter * types. */ static public Constructor getDeclaredConstructor (Class c, Class... parameterTypes) throws ReflectionException { try { return new Constructor(c.getDeclaredConstructor(parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation while getting constructor for class: " + c.getName(), e); } catch (NoSuchMethodException e) { throw new ReflectionException("Constructor not found for class: " + c.getName(), e); } }
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(); } }
/** Returns a {@link Constructor} that represents the public constructor for the supplied class which takes the supplied * parameter types. */ static public Constructor getConstructor (Class c, Class... parameterTypes) throws ReflectionException { try { return new Constructor(c.getConstructor(parameterTypes)); } catch (SecurityException e) { throw new ReflectionException("Security violation occurred while getting constructor for class: '" + c.getName() + "'.", e); } catch (NoSuchMethodException e) { throw new ReflectionException("Constructor not found for class: " + c.getName(), e); } }
private void installIOSGDXDialogs() { if (Gdx.app.getType() != ApplicationType.iOS) { showDebugSkipInstall(ApplicationType.iOS.name()); return; } // there doesn't seem to be an easy way to tell robovm and moe apart try { final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.ios.IOSGDXDialogs"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance(); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.iOS.name()+"-robovm"); } catch (ReflectionException e) { try { final Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.iosmoe.IOSMOEGDXDialogs"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz).newInstance(); this.gdxDialogs = (GDXDialogs) dialogManager; showDebugInstallSuccessful(ApplicationType.iOS.name() + "-moe"); } catch (ReflectionException ex) { showErrorInstall(ApplicationType.iOS.name(), "ios"); e.printStackTrace(); showErrorInstall(ApplicationType.iOS.name(), "ios-moe"); ex.printStackTrace(); } } }