protected T newObject () { try { return (T)constructor.newInstance((Object[])null); } catch (Exception ex) { throw new GdxRuntimeException("Unable to create new instance: " + constructor.getDeclaringClass().getName(), ex); } } }
protected T newObject () { try { return (T)constructor.newInstance((Object[])null); } catch (Exception ex) { throw new GdxRuntimeException("Unable to create new instance: " + constructor.getDeclaringClass().getName(), ex); } } }
private Object copy(Object object) { try { Constructor theConstructor = null; for (Constructor constructor : ClassReflection.getConstructors(object.getClass())) { if (constructor.getParameterTypes().length == 1 && ClassReflection.isAssignableFrom(constructor.getParameterTypes()[0], object.getClass())) { theConstructor = constructor; break; } } return theConstructor.newInstance(object); } catch (Throwable ex) { throw new GdxRuntimeException(ex); } }
protected Object newInstance (Class type) { try { return ClassReflection.newInstance(type); } catch (Exception ex) { try { // Try a private constructor. Constructor constructor = ClassReflection.getDeclaredConstructor(type); constructor.setAccessible(true); return constructor.newInstance(); } catch (SecurityException ignored) { } catch (ReflectionException ignored) { if (ClassReflection.isAssignableFrom(Enum.class, type)) { if (type.getEnumConstants() == null) type = type.getSuperclass(); return type.getEnumConstants()[0]; } if (type.isArray()) throw new SerializationException("Encountered JSON object when expected array of type: " + type.getName(), ex); else if (ClassReflection.isMemberClass(type) && !ClassReflection.isStaticClass(type)) throw new SerializationException("Class cannot be created (non-static member class): " + type.getName(), ex); else throw new SerializationException("Class cannot be created (missing no-arg constructor): " + type.getName(), ex); } catch (Exception privateConstructorException) { ex = privateConstructorException; } throw new SerializationException("Error constructing instance of class: " + type.getName(), ex); } }
protected Object newInstance (Class type) { try { return ClassReflection.newInstance(type); } catch (Exception ex) { try { // Try a private constructor. Constructor constructor = ClassReflection.getDeclaredConstructor(type); constructor.setAccessible(true); return constructor.newInstance(); } catch (SecurityException ignored) { } catch (ReflectionException ignored) { if (ClassReflection.isAssignableFrom(Enum.class, type)) { if (type.getEnumConstants() == null) type = type.getSuperclass(); return type.getEnumConstants()[0]; } if (type.isArray()) throw new SerializationException("Encountered JSON object when expected array of type: " + type.getName(), ex); else if (ClassReflection.isMemberClass(type) && !ClassReflection.isStaticClass(type)) throw new SerializationException("Class cannot be created (non-static member class): " + type.getName(), ex); else throw new SerializationException("Class cannot be created (missing no-arg constructor): " + type.getName(), ex); } catch (Exception privateConstructorException) { ex = privateConstructorException; } throw new SerializationException("Error constructing instance of class: " + type.getName(), ex); } }
Vector2 fromCopyConstructor = (Vector2)copyConstroctor.newInstance(fromDefaultConstructor); println("From copy constructor: " + fromCopyConstructor);
protected T newObject () { try { return (T)constructor.newInstance((Object[])null); } catch (Exception ex) { throw new GdxRuntimeException("Unable to create new instance: " + constructor.getDeclaringClass().getName(), ex); } } }
@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."); }
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).newInstance(); return (T) dialogObject; } catch (Exception e) { e.printStackTrace(); } } throw new RuntimeException(cls.getName() + "is not registered."); }
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).newInstance(); return (T) dialogObject; } catch (Exception e) { e.printStackTrace(); } } throw new RuntimeException(cls.getName() + "is not registered."); }
protected Object newInstance (Class type) { try { return ClassReflection.newInstance(type); } catch (Exception ex) { try { // Try a private constructor. Constructor constructor = ClassReflection.getDeclaredConstructor(type); constructor.setAccessible(true); return constructor.newInstance(); } catch (SecurityException ignored) { } catch (ReflectionException ignored) { if (ClassReflection.isAssignableFrom(Enum.class, type)) { if (type.getEnumConstants() == null) type = type.getSuperclass(); return type.getEnumConstants()[0]; } if (type.isArray()) throw new SerializationException("Encountered JSON object when expected array of type: " + type.getName(), ex); else if (ClassReflection.isMemberClass(type) && !ClassReflection.isStaticClass(type)) throw new SerializationException("Class cannot be created (non-static member class): " + type.getName(), ex); else throw new SerializationException("Class cannot be created (missing no-arg constructor): " + type.getName(), ex); } catch (Exception privateConstructorException) { ex = privateConstructorException; } throw new SerializationException("Error constructing instance of class: " + type.getName(), ex); } }
+ "Activity or Fragment classes or Activity is not available at the moment"); Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz, activityClazz).newInstance(activity);
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(); } }
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(); } }
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(); } }
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(); } }
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(); } } }
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(); } } }
loaderCls = ClassReflection.forName("de.tomgrill.gdxfirebase.iosmoe.database.IOSMOEFirebaseDatabase"); Object loaderObj = ClassReflection.getConstructor(loaderCls).newInstance(); GDXFirebase.setFirebaseDatabase(name, (FirebaseDatabase) loaderObj); Gdx.app.debug("gdx-firebase", "Realtime Database for " + Gdx.app.getType() + " installed successfully."); Object loaderObj = ClassReflection.getConstructor(loaderCls, String.class, FirebaseConfiguration.class).newInstance(name, firebaseConfiguration); GDXFirebase.setFirebaseDatabase(name, (FirebaseDatabase) loaderObj); Gdx.app.debug("gdx-firebase", "Realtime Database for " + Gdx.app.getType() + " installed successfully.");
loaderObj = ClassReflection.getConstructor(loaderCls).newInstance();