All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.lang.reflect.MethodInjector Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
package panda.lang.reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Type;

import panda.lang.Exceptions;
import panda.lang.Injector;
import panda.lang.Objects;

public class MethodInjector implements Injector {
	private Method method;

	/**
	 * @param method the method
	 */
	public MethodInjector(Method method) {
		this.method = method;

		if (!method.isAccessible()) {
			method.setAccessible(true);
		}
	}

	@Override
	public Type type(Object obj) {
		return Methods.getParameterType(method, 0);
	}
	
	@Override
	public void inject(Object obj, Object value) {
		try {
			method.invoke(obj, value);
		}
		catch (Exception e) {
			throw Exceptions.wrapThrow(e);
		}
	}

	@Override
	public String toString() {
		return Objects.toStringBuilder()
				.append("method", method)
				.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy