/** * Adds the <code>String</code> representation of the method return value * to the supplied <code>StringBuffer</code>. Correctly handles * <code>null</code> and <code>void</code> results. * @param methodInvocation the <code>MethodInvocation</code> that returned the value * @param matcher the <code>Matcher</code> containing the matched placeholder * @param output the <code>StringBuffer</code> to write output to * @param returnValue the value returned by the method invocatio. */ private void appendReturnValue( MethodInvocation methodInvocation, Matcher matcher, StringBuffer output, Object returnValue) { if (methodInvocation.getMethod().getReturnType() == void.class) { matcher.appendReplacement(output, "void"); } else if (returnValue == null) { matcher.appendReplacement(output, "null"); } else { matcher.appendReplacement(output, escape(returnValue.toString())); } }
/** * Adds a comma-separated list of the short <code>Class</code> names of the * method argument types to the output. For example, if a method has signature * <code>put(java.lang.String, java.lang.Object)</code> then the value returned * will be <code>String, Object</code>. * @param methodInvocation the <code>MethodInvocation</code> being logged. * Arguments will be retreived from the corresponding <code>Method</code>. * @param matcher the <code>Matcher</code> containing the state of the output * @param output the <code>StringBuffer</code> containing the output */ private void appendArgumentTypes(MethodInvocation methodInvocation, Matcher matcher, StringBuffer output) { Class[] argumentTypes = methodInvocation.getMethod().getParameterTypes(); String[] argumentTypeShortNames = new String[argumentTypes.length]; for (int i = 0; i < argumentTypeShortNames.length; i++) { argumentTypeShortNames[i] = ClassUtils.getShortName(argumentTypes[i]); } matcher.appendReplacement(output, escape(StringUtils.arrayToCommaDelimitedString(argumentTypeShortNames))); }
String targetClassName = escape(methodInvocation.getThis().getClass().getName()); matcher.appendReplacement(output, targetClassName); matcher.appendReplacement(output, escape(ClassUtils.getShortName(methodInvocation.getThis().getClass()))); matcher.appendReplacement(output, escape(StringUtils.arrayToCommaDelimitedString(methodInvocation.getArguments())));