Package org.panda_lang.utilities.inject
Interface Injector
public interface Injector
-
Method Summary
Modifier and TypeMethodDescriptionduplicate(InjectorController controller) Duplicate (clone) resources<T> ConstructorInjector<T>forConstructor(Class<T> type) Create injector for the given type<T> ConstructorInjector<T>forConstructor(Constructor<T> constructor) Create injector for the given constructor<T> FieldsInjector<T>Create injector for fields (and constructor)forGeneratedMethod(Method method) Generate injector for the given methodfork(InjectorController controller) Create a fork of resources.Create injector for the given methodGet resources of injector<T> TinvokeMethod(Method method, @Nullable Object instance, Object... injectorArgs) Invoke the method using Injector<T> TinvokeParameter(Parameter parameter, Object... injectorArgs) Get injected value of the given parameter<T> TnewInstance(Class<T> type, Object... injectorArgs) Create a new instance of the specified type using Injector<T> TnewInstanceWithFields(Class<T> type, Object... injectorArgs) Create a new instance of the specified type using Injector with support for field injection
-
Method Details
-
newInstance
Create a new instance of the specified type using Injector- Type Parameters:
T- the type- Parameters:
type- the class to instantiate- Returns:
- a new instance
- Throws:
Throwable- if anything happen in constructor
-
forConstructor
Create injector for the given type- Type Parameters:
T- type of class- Parameters:
type- the type to process- Returns:
- constructor injector
-
forConstructor
Create injector for the given constructor- Type Parameters:
T- type of class- Parameters:
constructor- the constructor to process- Returns:
- constructor injector
-
newInstanceWithFields
Create a new instance of the specified type using Injector with support for field injection- Type Parameters:
T- the type- Parameters:
type- the class to instantiate- Returns:
- a new instance
- Throws:
Throwable- if anything happen in constructor
-
forFields
Create injector for fields (and constructor)- Type Parameters:
T- type of class- Parameters:
type- the type to process- Returns:
- fields injector
-
invokeMethod
@Nullable <T> T invokeMethod(Method method, @Nullable @Nullable Object instance, Object... injectorArgs) throws Throwable Invoke the method using Injector- Type Parameters:
T- the return type- Parameters:
method- the method to invokeinstance- the instance to use (nullable for static context)- Returns:
- the return value
- Throws:
Throwable- if anything happen in the invoked method
-
forMethod
Create injector for the given method- Parameters:
method- the method to process- Returns:
- injector for the given method
-
forGeneratedMethod
Generate injector for the given method- Parameters:
method- the method to process (works only for public properties)- Returns:
- injector for the given method
- Throws:
Exception- if anything happen during the generation of method wrapper
-
invokeParameter
Get injected value of the given parameter- Type Parameters:
T- type of expected value- Parameters:
parameter- the parameter invoke- Returns:
- the associated binding value
- Throws:
Throwable- if anything happen
-
fork
Create a fork of resources. The current resources will be used as a parent of a new instance.- Parameters:
controller- initializer for a new instance of resources- Returns:
- a forked instance of resources
-
duplicate
Duplicate (clone) resources- Parameters:
controller- initializer for a new instance of resources- Returns:
- a duplicated instance of resources
-
getResources
Resources getResources()Get resources of injector- Returns:
- the resources
-