本文整理汇总了Java中com.badlogic.gdx.utils.reflect.Method.invoke方法的典型用法代码示例。如果您正苦于以下问题:Java Method.invoke方法的具体用法?Java Method.invoke怎么用?Java Method.invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.reflect.Method
的用法示例。
在下文中一共展示了Method.invoke方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的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();
}
}
}
}
示例2: doneLoading
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
@Override
public void doneLoading(AssetManager manager) {
super.doneLoading(manager);
// Set static coordinates to position
coordinates.getEquatorialCartesianCoordinates(null, pos);
// Initialize transform
if (transformName != null) {
Class<Coordinates> c = Coordinates.class;
try {
Method m = ClassReflection.getMethod(c, transformName);
Matrix4d trf = (Matrix4d) m.invoke(null);
coordinateSystem = new Matrix4();
trf.putIn(coordinateSystem);
} catch (ReflectionException e) {
Logger.error(this.getClass().getName(), "Error getting/invoking method Coordinates." + transformName + "()");
}
} else {
// Equatorial, nothing
}
// Model
mc.doneLoading(manager, localTransform, null);
}
示例3: setTransformName
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
public void setTransformName(String transformName) {
this.transformName = transformName;
if (transformName != null) {
Class<Coordinates> c = Coordinates.class;
try {
Method m = ClassReflection.getMethod(c, transformName);
Matrix4d transform = (Matrix4d) m.invoke(null);
trf = new Matrix4d(transform);
} catch (ReflectionException e) {
Logger.error(this.getClass().getName(), "Error getting/invoking method Coordinates." + transformName + "()");
}
} else {
// Equatorial, nothing
}
}
示例4: invokeMethod
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
/** @param method will be set accessible and invoked.
* @param methodOwner will have the method invoked. Can be null (static methods).
* @param resultType result will be casted to this type.
* @param arguments method arguments.
* @return result of method invocation.
* @throws ReflectionException when unable to invoke the method. */
@SuppressWarnings("unchecked")
public static <ResultType> ResultType invokeMethod(final Method method, final Object methodOwner,
final Class<ResultType> resultType, final Object... arguments) throws ReflectionException {
method.setAccessible(true);
return (ResultType) method.invoke(methodOwner, arguments);
}
示例5: processMethod
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
@Override
public void processMethod(final Method method, final MyCustomAnnotation annotation, final Object component,
final Context context, final ContextInitializer initializer, final ContextDestroyer contextDestroyer) {
// Invoking annotated method with ID from annotation as parameter:
Object result = null;
try {
method.setAccessible(true);
result = method.invoke(component, annotation.id());
} catch (final ReflectionException exception) {
LOGGER.error(exception, "Unable to invoke method.");
}
LOGGER.info("{0} had method '{1}' annotated with @MyCustomAnnotation. Method invocation result: {2}.",
component, method.getName(), result);
}
示例6: doneLoading
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
@Override
public void doneLoading(AssetManager manager) {
super.doneLoading(manager);
// Initialize transform.
localTransform.scl(size);
if (transformName != null) {
Class<Coordinates> c = Coordinates.class;
try {
Method m = ClassReflection.getMethod(c, transformName);
Matrix4d trf = (Matrix4d) m.invoke(null);
Matrix4 aux = trf.putIn(new Matrix4());
localTransform.mul(aux);
} catch (ReflectionException e) {
Logger.error(Mw.class.getName(), "Error getting/invoking method Coordinates." + transformName + "()");
}
} else {
// Equatorial, nothing
}
// Must rotate due to orientation of createCylinder
localTransform.rotate(0, 1, 0, 90);
// Model
mc.doneLoading(manager, localTransform, null);
}
示例7: doneLoading
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
@Override
public void doneLoading(AssetManager manager) {
Material material = new Material(new BlendingAttribute(cc[3]), new ColorAttribute(ColorAttribute.Diffuse, cc[0], cc[1], cc[2], cc[3]));
// Load model
ModelBuilder2 modelBuilder = ModelCache.cache.mb;
modelBuilder.begin();
// create part
MeshPartBuilder2 bPartBuilder = modelBuilder.part("sph", GL20.GL_LINES, Usage.Position, material);
bPartBuilder.sphere(1, 1, 1, divisionsU, divisionsV);
Model model = (modelBuilder.end());
// Initialize transform
localTransform.scl(size);
if (transformName != null) {
Class<Coordinates> c = Coordinates.class;
try {
Method m = ClassReflection.getMethod(c, transformName);
Matrix4d trf = (Matrix4d) m.invoke(null);
Matrix4 aux = new Matrix4();
trf.putIn(aux);
localTransform.mul(aux);
} catch (ReflectionException e) {
Logger.error(Grid.class.getName(), "Error getting/invoking method Coordinates." + transformName + "()");
}
} else {
// Equatorial, nothing
}
mc.instance = new ModelInstance(model, this.localTransform);
float pl = .5f;
labelColor = new float[] { Math.min(1, cc[0] + pl), Math.min(1, cc[1] + pl), Math.min(1, cc[2] + pl), Math.min(1, cc[3] + pl) };
font = GlobalResources.skin.getFont("grid-annotation");
}
示例8: setTransformFunction
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
public void setTransformFunction(String transformFunction) {
if (transformFunction != null && !transformFunction.isEmpty()) {
try {
Method m = ClassReflection.getMethod(Coordinates.class, transformFunction);
this.transformFunction = (Matrix4d) m.invoke(null);
} catch (Exception e) {
Logger.error(e);
}
}
}
示例9: initializeBehavior
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
/**
* Default implementation relies in reflection to set the attributes
*/
protected void initializeBehavior(S event, Class eventClass,
T runtimeBehavior) {
Method[] methods = ClassReflection.getDeclaredMethods(eventClass);
for (Method get : methods) {
String getPrefix = get.getName().startsWith("get") ? "get" : "is";
if (get.getName().startsWith("get")
|| get.getName().startsWith("is")) {
// Search equivalent set method in runtimeBehavior
String setMethodName = "set"
+ get.getName().substring(getPrefix.length());
Class returningType = get.getReturnType();
try {
Method set = ClassReflection.getDeclaredMethod(
runtimeBehavior.getClass(), setMethodName,
returningType);
if (set != null) {
set.invoke(runtimeBehavior, get.invoke(event));
}
} catch (ReflectionException e) {
Gdx.app.error("BehaviorComponent",
"Error initializing behavior", e);
}
}
}
if (eventClass.getSuperclass() != null
&& eventClass.getSuperclass() != Object.class) {
initializeBehavior(event, eventClass.getSuperclass(),
runtimeBehavior);
}
}
示例10: callPostDeserializeMethods
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
private <T> void callPostDeserializeMethods(T object, Class<?> clazz) throws SerializationException {
Class<?> currentClass = clazz;
while (currentClass != null && !currentClass.equals(Object.class)) {
for(Method method : ClassReflection.getDeclaredMethods(currentClass)) {
if(method.isAnnotationPresent(PostDeserialize.class)) {
try {
method.invoke(object);
} catch (ReflectionException e) {
throw new SerializationException(e);
}
}
}
currentClass = currentClass.getSuperclass();
}
}
示例11: invokeMethod
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
/** @param method will be set as accessible and invoked.
* @param methodOwner instance of class with the method. Will have the method invoked. Can be null (static methods).
* @param arguments method arguments.
* @return result of method invocation.
* @throws ReflectionException when unable to invoke the method. */
public static Object invokeMethod(final Method method, final Object methodOwner, final Object... arguments)
throws ReflectionException {
method.setAccessible(true);
return method.invoke(methodOwner, arguments);
}
示例12: create
import com.badlogic.gdx.utils.reflect.Method; //导入方法依赖的package包/类
@Override
public void create () {
font = new BitmapFont();
batch = new SpriteBatch();
try {
Vector2 fromDefaultConstructor = ClassReflection.newInstance(Vector2.class);
println("From default constructor: " + fromDefaultConstructor);
Method mSet = ClassReflection.getMethod(Vector2.class, "set", float.class, float.class);
mSet.invoke(fromDefaultConstructor, 10, 11);
println("Set to 10/11: " + fromDefaultConstructor);
Constructor copyConstroctor = ClassReflection.getConstructor(Vector2.class, Vector2.class);
Vector2 fromCopyConstructor = (Vector2)copyConstroctor.newInstance(fromDefaultConstructor);
println("From copy constructor: " + fromCopyConstructor);
Method mMul = ClassReflection.getMethod(Vector2.class, "scl", float.class);
println("Multiplied by 2; " + mMul.invoke(fromCopyConstructor, 2));
Method mNor = ClassReflection.getMethod(Vector2.class, "nor");
println("Normalized: " + mNor.invoke(fromCopyConstructor));
Vector2 fieldCopy = new Vector2();
Field fx = ClassReflection.getField(Vector2.class, "x");
Field fy = ClassReflection.getField(Vector2.class, "y");
fx.set(fieldCopy, fx.get(fromCopyConstructor));
fy.set(fieldCopy, fy.get(fromCopyConstructor));
println("Copied field by field: " + fieldCopy);
Json json = new Json();
String jsonString = json.toJson(fromCopyConstructor);
Vector2 fromJson = json.fromJson(Vector2.class, jsonString);
println("JSON serialized: " + jsonString);
println("JSON deserialized: " + fromJson);
fromJson.x += 1;
fromJson.y += 1;
println("JSON deserialized + 1/1: " + fromJson);
Object array = ArrayReflection.newInstance(int.class, 5);
ArrayReflection.set(array, 0, 42);
println("Array int: length=" + ArrayReflection.getLength(array) + ", access=" + ArrayReflection.get(array, 0));
array = ArrayReflection.newInstance(String.class, 5);
ArrayReflection.set(array, 0, "test string");
println("Array String: length=" + ArrayReflection.getLength(array) + ", access=" + ArrayReflection.get(array, 0));
} catch (Exception e) {
message = "FAILED: " + e.getMessage() + "\n";
message += e.getClass();
}
}