com.badlogic.gdx.utils.reflect.ConstructorEmu Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of backend-teavm Show documentation
Show all versions of backend-teavm Show documentation
Tool to generate libgdx to javascript using teaVM
package com.badlogic.gdx.utils.reflect;
import com.github.xpenatan.gdx.backends.teavm.gen.Emulate;
import java.lang.reflect.InvocationTargetException;
/**
* Provides information about, and access to, a single constructor for a Class.
*
* @author nexsoftware
*/
@Emulate(Constructor.class)
public final class ConstructorEmu {
private final java.lang.reflect.Constructor constructor;
ConstructorEmu(java.lang.reflect.Constructor constructor) {
this.constructor = constructor;
}
/**
* Returns an array of Class objects that represent the formal parameter types, in declaration order, of the constructor.
*/
public Class[] getParameterTypes() {
return constructor.getParameterTypes();
}
/**
* Returns the Class object representing the class or interface that declares the constructor.
*/
public Class getDeclaringClass() {
return constructor.getDeclaringClass();
}
public boolean isAccessible() {
return constructor.isAccessible();
}
public void setAccessible(boolean accessible) {
constructor.setAccessible(accessible);
}
/**
* Uses the constructor to create and initialize a new instance of the constructor's declaring class, with the supplied
* initialization parameters.
*/
public Object newInstance(Object... args) throws ReflectionException {
if(args == null) {
args = new Object[0];
}
try {
return constructor.newInstance(args);
}
catch(IllegalArgumentException e) {
throw new ReflectionException("Illegal argument(s) supplied to constructor for class: " + getDeclaringClass().getName(),
e);
}
catch(InstantiationException e) {
throw new ReflectionException("Could not instantiate instance of class: " + getDeclaringClass().getName(), e);
}
catch(IllegalAccessException e) {
throw new ReflectionException("Could not instantiate instance of class: " + getDeclaringClass().getName(), e);
}
catch(InvocationTargetException e) {
throw new ReflectionException("Exception occurred in constructor for class: " + getDeclaringClass().getName(), e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy