Package org.faktorips.util
Class MethodAccess
java.lang.Object
org.faktorips.util.MethodAccess
Wraps access to a method. Allows
checks on the method and its
invocation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassOffers multiple checks on aMethodAccessin a fluent API.static class -
Method Summary
Modifier and TypeMethodDescriptionCreates a newMethodAccess.Checkobject for this class and method name.booleanexists()Returns whether the wrapped method actually exists.<T> TInvokes the wrapped method on the given object with the given arguments.<T> TinvokeStatic(String methodDescription, Object... args) Invokes the wrapped static method on the wrapped class with the given arguments.static final MethodAccessCreates aMethodAccessfor the given class and method name.toString()
-
Method Details
-
of
Creates aMethodAccessfor the given class and method name.If the method can not be found,
checksandinvocationswill fail when called.- Parameters:
clazz- a classmethodName- the name of a method of the given class- Throws:
NullPointerException- if no class or method name is givenIllegalArgumentException- if the method name is empty
-
invoke
Invokes the wrapped method on the given object with the given arguments.- Type Parameters:
T- the expected type of the return value- Parameters:
methodDescription- a description of what the method does, like "to find a value by name", that will be included in an exception's message if one is thrownobject- an instance of the wrapped class on which the method should be invokedargs- the arguments (if any) to be passed to the method- Returns:
- the method's return value
- Throws:
MethodAccess.MethodAccessException- if invocation of the method fails
-
invokeStatic
Invokes the wrapped static method on the wrapped class with the given arguments.- Type Parameters:
T- the expected type of the return value- Parameters:
methodDescription- a description of what the method does, like "to find a value by name", that will be included in an exception's message if one is thrownargs- the arguments (if any) to be passed to the method- Returns:
- the method's return value
- Throws:
MethodAccess.MethodAccessException- if invocation of the method fails
-
exists
public boolean exists()Returns whether the wrapped method actually exists. -
toString
-
check
public MethodAccess.Check check(org.faktorips.runtime.MessageList messageList, String msgCodePrefix) Creates a newMethodAccess.Checkobject for this class and method name.All checks called on the
MethodAccess.Checkobject report problems to the givenMessageListusing the given prefix for their message codes.The first check to be called should be
MethodAccess.Check.exists(), because other checks won't work if there is no method to check.- Parameters:
messageList- a list of messages to which this check can report problemsmsgCodePrefix- a prefix to be used for message codes
-