mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-07 19:00:45 +08:00
use pre-check to reduce unnecessary verbose parameter calculation
This commit is contained in:
parent
196dffc73d
commit
f8450d7047
@ -67,8 +67,10 @@ public class SourceClassHandler extends BaseClassHandler {
|
||||
if (invokeOps.contains(instructions[i].getOpcode())) {
|
||||
MethodInsnNode node = (MethodInsnNode)instructions[i];
|
||||
if (CONSTRUCTOR.equals(node.name)) {
|
||||
LogUtil.verbose(" Line %d, constructing \"%s\"", getLineNum(instructions, i),
|
||||
MethodUtil.toJavaMethodDesc(node.owner, node.desc));
|
||||
if (LogUtil.isVerboseEnabled()) {
|
||||
LogUtil.verbose(" Line %d, constructing \"%s\"", getLineNum(instructions, i),
|
||||
MethodUtil.toJavaMethodDesc(node.owner, node.desc));
|
||||
}
|
||||
MethodInfo newOperatorInjectMethod = getNewOperatorInjectMethod(newOperatorInjectMethods, node);
|
||||
if (newOperatorInjectMethod != null) {
|
||||
// it's a new operation and an inject method for it exist
|
||||
@ -82,8 +84,10 @@ public class SourceClassHandler extends BaseClassHandler {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogUtil.verbose(" Line %d, invoking \"%s\"", getLineNum(instructions, i),
|
||||
MethodUtil.toJavaMethodDesc(node.owner, node.name, node.desc));
|
||||
if (LogUtil.isVerboseEnabled()) {
|
||||
LogUtil.verbose(" Line %d, invoking \"%s\"", getLineNum(instructions, i),
|
||||
MethodUtil.toJavaMethodDesc(node.owner, node.name, node.desc));
|
||||
}
|
||||
MethodInfo mockMethod = getMemberInjectMethodName(memberInjectMethods, node);
|
||||
if (mockMethod != null) {
|
||||
// it's a member or static method and an inject method for it exist
|
||||
|
@ -86,12 +86,16 @@ public class MockClassParser {
|
||||
for (AnnotationNode an : mn.visibleAnnotations) {
|
||||
String fullClassName = toDotSeparateFullClassName(an.desc);
|
||||
if (fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
|
||||
LogUtil.verbose(" Mock constructor \"%s\" as \"%s\"", mn.name,
|
||||
MethodUtil.toJavaMethodDesc(MethodUtil.getReturnType(mn.desc), mn.desc));
|
||||
if (LogUtil.isVerboseEnabled()) {
|
||||
LogUtil.verbose(" Mock constructor \"%s\" as \"%s\"", mn.name, MethodUtil.toJavaMethodDesc(
|
||||
ClassUtil.toDotSeparateFullClassName(MethodUtil.getReturnType(mn.desc)), mn.desc));
|
||||
}
|
||||
addMockConstructor(methodInfos, cn, mn);
|
||||
} else if (fullClassName.equals(ConstPool.MOCK_METHOD) && AnnotationUtil.isValidMockMethod(mn, an)) {
|
||||
LogUtil.verbose(" Mock method \"%s\" as \"%s\"", mn.name, MethodUtil.toJavaMethodDesc(
|
||||
getTargetMethodOwner(mn, an), getTargetMethodName(mn, an), getTargetMethodDesc(mn, an)));
|
||||
if (LogUtil.isVerboseEnabled()) {
|
||||
LogUtil.verbose(" Mock method \"%s\" as \"%s\"", mn.name, MethodUtil.toJavaMethodDesc(
|
||||
getTargetMethodOwner(mn, an), getTargetMethodName(mn, an), getTargetMethodDesc(mn, an)));
|
||||
}
|
||||
String targetMethod = AnnotationUtil.getAnnotationParameter(
|
||||
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
|
||||
if (CONSTRUCTOR.equals(targetMethod)) {
|
||||
|
@ -113,8 +113,9 @@ public class MethodUtil {
|
||||
* @return java style constructor descriptor
|
||||
*/
|
||||
public static String toJavaMethodDesc(String owner, String desc) {
|
||||
String ownerInDotFormat = ClassUtil.toDotSeparatedName(owner);
|
||||
String parameters = toJavaParameterDesc(extractParameters(desc));
|
||||
return String.format("%s(%s)", owner, parameters);
|
||||
return String.format("%s(%s)", ownerInDotFormat, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ public class LogUtil {
|
||||
private static LogLevel currentLogLevel = LogLevel.LEVEL_WARN;
|
||||
|
||||
public static void verbose(String msg, Object... args) {
|
||||
if (currentLogLevel.level >= LogLevel.LEVEL_VERBOSE.level) {
|
||||
if (isVerboseEnabled()) {
|
||||
System.out.println(String.format("[VERBOSE] " + msg, args));
|
||||
}
|
||||
}
|
||||
@ -54,6 +54,13 @@ public class LogUtil {
|
||||
System.err.println(String.format("[ERROR] " + msg, args));
|
||||
}
|
||||
|
||||
/**
|
||||
* a pre-check method for reduce verbose parameter calculation
|
||||
*/
|
||||
public static boolean isVerboseEnabled() {
|
||||
return currentLogLevel.level >= LogLevel.LEVEL_VERBOSE.level;
|
||||
}
|
||||
|
||||
public static void setLevel(LogLevel level) {
|
||||
currentLogLevel = level;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user