Silk DI 0.6


se.jbee.inject.bootstrap
Class Inspect

Object
  extended by se.jbee.inject.bootstrap.Inspect
All Implemented Interfaces:
Inspector

public class Inspect
extends Object
implements Inspector

The basic Inspector implementations. It allows to chose Constructors and Methods based on the Annotations present, the Types a method returns or the Packages they are defined in.

Author:
Jan Bernitt (jan@jbee.se)

Field Summary
static Inspect DEFAULT
          By default just the constructor is inspected.
 
Method Summary
static Inspect all()
           
static Inspect allStatic()
           
 Inspect annotatedWith(Class<? extends Annotation> annotation)
           
<T> Constructor<T>
constructorFor(Class<T> type)
          Picks the Constructor to use to construct objects of a given Class.
 Inspect constructors()
           
static
<T> Constructor<T>
defaultConstructor(Class<T> declaringClass)
          Returns the constructor usually should be used.
 Inspect methods()
           
<T> Method[]
methodsIn(Class<T> implementor)
           
static Inspect methodsReturn(Type<?> returnType)
           
 Inspect namedBy(Class<? extends Annotation> annotation)
           
 Name nameFor(AccessibleObject obj)
           
static
<T> Constructor<T>
noArgsConstructor(Class<T> declaringClass)
           
 Parameter<?>[] parametersFor(AccessibleObject obj)
           
 Inspect returnTypeAssignableTo(Type<?> supertype)
           
 Inspect returnTypeIn(Packages packages)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final Inspect DEFAULT
By default just the constructor is inspected. The Inspector will pick the defaultConstructor(Class).

Method Detail

all

public static Inspect all()
Returns:
a Inspector that will result in all methods and a constructor for all given implementation classes. The result can be further restricted using any combination of the instance methods of Inject.

allStatic

public static Inspect allStatic()
Returns:
same as all() but result is already restricted to just static methods.

methodsReturn

public static Inspect methodsReturn(Type<?> returnType)

parametersFor

public Parameter<?>[] parametersFor(AccessibleObject obj)
Specified by:
parametersFor in interface Inspector
Returns:
The Parameter hints for the construction/invocation of the given object. Use a zero length array if there are no hits.

nameFor

public Name nameFor(AccessibleObject obj)
Specified by:
nameFor in interface Inspector
Returns:
The Name of the instance provided by the given object. Use Name.DEFAULT for no specific name.

constructorFor

public <T> Constructor<T> constructorFor(Class<T> type)
Description copied from interface: Inspector
Picks the Constructor to use to construct objects of a given Class.

Specified by:
constructorFor in interface Inspector
Returns:
The Constructor considered to be the reasonable or right way to construct a object of the given type. In case one with parameters is returned the process will try to resolve them.

methodsIn

public <T> Method[] methodsIn(Class<T> implementor)
Specified by:
methodsIn in interface Inspector
Returns:
The Members that should be bound from the given implementor.

methods

public Inspect methods()
Returns:
a Inspector restricted to inspect just methods (no constructors).

constructors

public Inspect constructors()
Returns:
a Inspector restricted to inspect just constructors (no methods).

annotatedWith

public Inspect annotatedWith(Class<? extends Annotation> annotation)
Parameters:
annotation - An annotation available at runtime
Returns:
a Inspector restricted to inspect just constructors and/or methods where the given annotation is present.

namedBy

public Inspect namedBy(Class<? extends Annotation> annotation)
Parameters:
annotation - An annotation available at runtime having at least one property of type String.
Returns:
a Inspector that tries to extract an instance name from the given annotation.

returnTypeIn

public Inspect returnTypeIn(Packages packages)
Parameters:
packages - The set of Packages the return type of a method or the class constructed by a constructor should be contained in.
Returns:
a Inspector restricted to inspect just methods having a return type or a constructor of a type that is a member of the set given.

returnTypeAssignableTo

public Inspect returnTypeAssignableTo(Type<?> supertype)
Parameters:
supertype - any Type
Returns:
a Inspector restricted to inspect just methods or constructors that return a Type that is assignable to the given super-type.

defaultConstructor

public static <T> Constructor<T> defaultConstructor(Class<T> declaringClass)
Returns the constructor usually should be used.

Parameters:
declaringClass - constructed type
Returns:
The constructor with the most parameters.
Throws:
NoSuchMethodException - in case the type is not constructible (has no constructors at all)

noArgsConstructor

public static <T> Constructor<T> noArgsConstructor(Class<T> declaringClass)

Silk DI 0.6