Author: ravn Date: Sun Oct 5 17:19:23 2008 New Revision: 1186 Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java
Log: now takes synchronized parameter in consideration and is more robust of lack of information Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java ============================================================================== --- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java (original) +++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/instrumentation/JavassistHelper.java Sun Oct 5 17:19:23 2008 @@ -12,7 +12,7 @@ public static String returnValue(CtBehavior method) throws NotFoundException { - + String returnValue = ""; if (methodReturnsValue(method)) { returnValue = " returns: \" + $_ + \""; @@ -22,30 +22,34 @@ private static boolean methodReturnsValue(CtBehavior method) throws NotFoundException { - + if (method instanceof CtMethod == false) { return false; } - + CtClass returnType = ((CtMethod) method).getReturnType(); String returnTypeName = returnType.getName(); boolean isVoidMethod = "void".equals(returnTypeName); - + boolean methodReturnsValue = isVoidMethod == false; return methodReturnsValue; } public static String getSignature(CtBehavior method) throws NotFoundException { - + CtClass parameterTypes[] = method.getParameterTypes(); CodeAttribute codeAttribute = method.getMethodInfo().getCodeAttribute(); - LocalVariableAttribute locals = (LocalVariableAttribute) codeAttribute - .getAttribute("LocalVariableTable"); - + LocalVariableAttribute locals = null; + + if (codeAttribute != null) { + locals = (LocalVariableAttribute) codeAttribute + .getAttribute("LocalVariableTable"); + } + String methodName = method.getName(); StringBuffer sb = new StringBuffer(methodName + "(\" "); @@ -85,18 +89,26 @@ if (locals == null) { return Integer.toString(i + 1); } - int modifiers = method.getModifiers(); - + int j = i; - - - + + if (Modifier.isSynchronized(modifiers)) { + // skip object to synchronize upon. + j++; + // System.err.println("Synchronized"); + } if (Modifier.isStatic(modifiers) == false) { - // skip #0 which is "this" + // skip "this" j++; + // System.err.println("Instance"); + } + String variableName = locals.variableName(j); + if (variableName.equals("this")) { + System.err.println("this returned as a parameter name for " + + method.getName() + ", names are probably shifted."); } - return locals.variableName(j); + return variableName; } } _______________________________________________ dev mailing list dev@slf4j.org http://www.slf4j.org/mailman/listinfo/dev