@NullArgsAllowed private static String getArgAsString(final Object obj, final Annotation[] annotations) { if (hasDontLogMeAnnotation(annotations)) { return "*"; } else { return getArgAsString(obj); } }
String shortString = getArgsAsString(args); if (shortString.length() < 20) { return shortString; sb.append(getArgAsShortString(args[0])); int n = args.length; if (n > 3) { sb.append(getArgAsShortString(args[i]));
/** * The Java compiler generates something like OuterClass$InnerClass * as name for the inner class. So if a name contains a '$' it is * probably an inner class. * * @param jp the jp * * @return true if joinpoint belongs to an inner class */ public static boolean isInnerClass(JoinPoint jp) { return isInnerClass(jp.getSignature()); }
private static void trace(final int level, final String prefix, final JoinPoint joinpoint, final String suffix) { if (LOG.isTraceEnabled()) { String loc = getLocation(joinpoint); LOG.trace(indent(level) + prefix + JoinPointHelper.getAsLongString(joinpoint) + suffix + loc); } else if (LOG.isDebugEnabled()) { LOG.debug(indent(level) + prefix + JoinPointHelper.getAsShortString(joinpoint) + suffix); } }
/** * Gets the given joinpoint as string. * * @param joinpoint * the joinpoint * * @return the as string */ public static String getAsString(final JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); Object[] args = joinpoint.getArgs(); if (sig instanceof FieldSignature) { if (args.length == 0) { return "get " + sig.toShortString(); } else { return "set " + sig.toShortString() + " = " + getArgAsString(args[0]); } } else if (sig instanceof CodeSignature) { Annotation[][] paramAnnotations = getParameterAnnotations(joinpoint); return SignatureHelper.getAsString(sig.getDeclaringTypeName(), sig) + getArgsAsString(args, paramAnnotations); } else { return SignatureHelper.getAsString(sig.getDeclaringTypeName(), sig) + getArgsAsString(args); } }
/** * Gets the as long string. * * @param joinpoint * the joinpoint * * @return the as short string */ public static String getAsLongString(final JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); if (sig instanceof FieldSignature) { return getAsString(joinpoint); } Object[] args = joinpoint.getArgs(); return SignatureHelper.getAsString(sig.getDeclaringType().getName(), sig) + getArgsAsString(args); }
@NullArgsAllowed private static String getArgsAsString(final Object[] args, final Annotation[][] annotations) { if ((args == null) || (args.length == 0)) { return "()"; } String s = "(" + getArgAsString(args[0], annotations[0]); for (int i = 1; i < args.length; i++) { s += ", " + getArgAsString(args[i], annotations[i]); } return s + ")"; }
/** * Gets the as short string. * * @param joinpoint * the joinpoint * * @return the as short string */ public static String getAsShortString(final JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); if (sig instanceof FieldSignature) { return getAsString(joinpoint); } Object[] args = joinpoint.getArgs(); if (sig instanceof CatchClauseSignature) { return SignatureHelper.getAsString(sig.getDeclaringType().getSimpleName(), sig) + "(" + args[0].getClass().getName() + ")"; } return SignatureHelper.getAsString(sig.getDeclaringType().getSimpleName(), sig) + getArgsAsShortString(args); }
/** * Gets the parameter annotations. * * @param joinpoint should be a Method- or Constructor-Signature * * @return the annotations of a method or constructor, otherwise null */ @MayReturnNull public static Annotation[][] getParameterAnnotations(JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); if (sig instanceof MethodSignature) { MethodSignature methodSig = (MethodSignature) sig; return methodSig.getMethod().getParameterAnnotations(); } else if (sig instanceof ConstructorSignature) { ConstructorSignature ctorSig = (ConstructorSignature) sig; return getParameterAnnotations(ctorSig); } else { return null; } }
/** * Gets the args as string. * * @return the args as string */ public String getArgsAsString() { return Converter.toShortString(JoinPointHelper.getArgsAsString(this.args)); }
/** * Both things are logged with this method: the call of a method (joinPoint) * and the return value of this method. Constructors or method of type * 'void' are not recorded because the have no return value. * <p> * Because the given joinPoint cannot be used as key for a map in * {@link ObjectPlayer} it is saved as string. As a side effect this will * speedup the serialization stuff and shorten the generated record file. * </p> * * @param joinPoint * the joinpoint * @param returnValue * the return value */ @NullArgsAllowed public void log(final JoinPoint joinPoint, final Object returnValue) { String statement = JoinPointHelper.getAsLongString(joinPoint); try { save(statement, returnValue); } catch (IOException ioe) { LOG.debug("Logging to {} failed:", objStream, ioe); LOG.info("{} = {}", statement, returnValue); } }
/** * Gets the as string. * * @param joinpoint the joinpoint * * @return the as string */ public static String getAsString(JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); Object[] args = joinpoint.getArgs(); if (sig instanceof FieldSignature) { if (args.length == 0) { return "get " + sig.toShortString(); } else { return "set " + sig.toShortString() + " = " + getArgAsString(args[0]); } } else if (sig instanceof CodeSignature) { Annotation[][] paramAnnotations = getParameterAnnotations(joinpoint); return SignatureHelper.getAsString(sig.getDeclaringTypeName(), sig) + getArgsAsString(args, paramAnnotations); } else { return SignatureHelper.getAsString(sig.getDeclaringTypeName(), sig) + getArgsAsString(args); } }
/** * Gets the as short string. * * @param joinpoint the joinpoint * * @return the as short string */ public static String getAsShortString(JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); if (sig instanceof FieldSignature) { return getAsString(joinpoint); } Object[] args = joinpoint.getArgs(); return SignatureHelper.getAsString(sig.getDeclaringType() .getSimpleName(), sig) + getArgsAsString(args); }
/** * Gets the args as string. * * @param args the args * * @return the args as string */ @NullArgsAllowed public static String getArgsAsString(final Object[] args) { if ((args == null) || (args.length == 0)) { return "()"; } String s = "(" + getArgAsString(args[0]); for (int i = 1; i < args.length; i++) { s += ", " + getArgAsString(args[i]); } return s + ")"; }
/** * Gets the parameter annotations. * * @param joinpoint * should be a Method- or Constructor-Signature * * @return the annotations of a method or constructor, otherwise null */ @MayReturnNull public static Annotation[][] getParameterAnnotations(final JoinPoint joinpoint) { Signature sig = joinpoint.getSignature(); if (sig instanceof MethodSignature) { Method method = ((MethodSignature) sig).getMethod(); if (method == null) { return new Annotation[0][0]; } return method.getParameterAnnotations(); } else if (sig instanceof ConstructorSignature) { ConstructorSignature ctorSig = (ConstructorSignature) sig; return getParameterAnnotations(ctorSig); } else { return new Annotation[0][0]; } }
/** * Gets the return value for the given joinpoint. The return values are * returned in the same order as the were recorded. I.e. if for the same * joinpoint first the value "1" and then the value "2" is recorded you'll * get first "1", then "2" as the return value. * * @param joinPoint * the join point * @return the return value */ public Object getReturnValue(final JoinPoint joinPoint) { String statement = JoinPointHelper.getAsLongString(joinPoint); if (SignatureHelper.hasReturnType(joinPoint.getSignature())) { return getReturnValue(statement); } LOG.debug("REPLAY: {}", statement); return null; }
@NullArgsAllowed private static String getArgAsString(final Object obj, final Annotation[] annotations) { if (hasDontLogMeAnnotation(annotations)) { return "*"; } else { return getArgAsString(obj); } }
/** * The Java compiler generates something like OuterClass$InnerClass as name * for the inner class. So if a name contains a '$' it is probably an inner * class. * * @param jp * the jp * * @return true if joinpoint belongs to an inner class */ public static boolean isInnerClass(final JoinPoint jp) { return isInnerClass(jp.getSignature()); }
@NullArgsAllowed private static String getArgsAsString(final Object[] args, final Annotation[][] annotations) { if ((args == null) || (args.length == 0)) { return "()"; } StringBuilder sb = new StringBuilder("("); sb.append(getArgAsString(args[0], annotations[0])); for (int i = 1; i < args.length; i++) { sb.append(", "); sb.append(getArgAsString(args[i], annotations[i])); } sb.append(")"); return sb.toString(); }
@NullArgsAllowed public void log(final JoinPoint joinPoint, final Object returnValue) { String statement = JoinPointHelper.getAsLongString(joinPoint); if ((returnValue != null) && (SignatureHelper.hasReturnType(joinPoint.getSignature()))) { try {