1. 完善toString方法
This commit is contained in:
parent
e1a3de2ab7
commit
f4d20579f8
|
|
@ -121,8 +121,8 @@ public class EnhanceClazz4Interceptor {
|
|||
interceptor);
|
||||
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
logger.debug("prepare to enhance class {} method [{}] ",
|
||||
enhanceOriginClassName, methodMatcher.getMethodMatchDescribe());
|
||||
logger.debug("prepare to enhance class {} {}",
|
||||
enhanceOriginClassName, methodMatcher);
|
||||
newClassBuilder = newClassBuilder.method(
|
||||
methodMatcher.builderMatcher()).intercept(
|
||||
MethodDelegation.to(classMethodInterceptor));
|
||||
|
|
|
|||
|
|
@ -90,4 +90,35 @@ public abstract class MethodMatcher {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder(" the method named " + getMethodMatchDescribe());
|
||||
if (getModifier() != null) {
|
||||
stringBuilder.append(" with " + getModifier() + " modifier");
|
||||
}
|
||||
|
||||
if (getArgNum() > -1) {
|
||||
stringBuilder.append("," + getArgNum() + " arguments");
|
||||
}
|
||||
|
||||
if (getArgTypeArray() != null) {
|
||||
stringBuilder.append(",argument type are ");
|
||||
for (Class argType : getArgTypeArray()) {
|
||||
stringBuilder.append(argType.getName());
|
||||
}
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
protected int getArgNum() {
|
||||
return argNum;
|
||||
}
|
||||
|
||||
protected Class<?>[] getArgTypeArray() {
|
||||
return argTypeArray;
|
||||
}
|
||||
|
||||
protected Modifier getModifier() {
|
||||
return modifier;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,16 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
|
|||
public class AnyMethodMatcher extends MethodMatcher {
|
||||
|
||||
public AnyMethodMatcher() {
|
||||
super("*");
|
||||
super("any method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> builderMatcher() {
|
||||
return any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMethodMatchDescribe();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,28 @@ public class MethodExclusiveMatcher extends MethodMatcher {
|
|||
ElementMatcher.Junction<MethodDescription> matcher = named(getMethodMatchDescribe());
|
||||
return not(mergeArgumentsIfNecessary(matcher));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder("any method exclude ");
|
||||
|
||||
stringBuilder.append(" method named " + getMethodMatchDescribe());
|
||||
|
||||
if (getModifier() != null) {
|
||||
stringBuilder.append(getModifier());
|
||||
}
|
||||
|
||||
if (getArgNum() > -1) {
|
||||
stringBuilder.append(" with " + getArgNum() + " arguments");
|
||||
}
|
||||
|
||||
if (getArgTypeArray() != null) {
|
||||
stringBuilder.append(" with ");
|
||||
for (Class argType : getArgTypeArray()) {
|
||||
stringBuilder.append(argType.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,5 @@ public class MethodRegexMatcher extends MethodMatcher {
|
|||
ElementMatcher.Junction<MethodDescription> matcher = nameMatches(getMethodMatchDescribe());
|
||||
return mergeArgumentsIfNecessary(matcher);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,19 @@ public class MethodsExclusiveMatcher extends MethodMatcher {
|
|||
return not(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder("any method exclude the method(s) as follow:\n ");
|
||||
int i = 0;
|
||||
for (MethodMatcher methodMatcher : matchers) {
|
||||
if (i == 0) {
|
||||
stringBuilder.append(methodMatcher.toString() + " or ");
|
||||
i++;
|
||||
} else {
|
||||
stringBuilder.append(methodMatcher.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.matcher;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.any;
|
||||
|
||||
public class PrivateMethodMatcher extends MethodMatcher {
|
||||
public PrivateMethodMatcher() {
|
||||
super("any private method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> builderMatcher() {
|
||||
return any().and(ElementMatchers.<MethodDescription>isPrivate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMethodMatchDescribe();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor;
|
|||
import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.MethodsExclusiveMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
||||
/**
|
||||
|
|
@ -18,8 +19,9 @@ public class TestMatcherDefine implements InterceptorDefine {
|
|||
@Override
|
||||
public MethodMatcher[] getBeInterceptedMethodsMatchers() {
|
||||
return new MethodMatcher[]{
|
||||
new MethodsExclusiveMatcher("set", "get"),
|
||||
new SimpleMethodMatcher(MethodMatcher.Modifier.Private, "set")
|
||||
new PrivateMethodMatcher(),
|
||||
new MethodsExclusiveMatcher(new SimpleMethodMatcher("set"), new SimpleMethodMatcher(MethodMatcher.Modifier.Public,"get")),
|
||||
new SimpleMethodMatcher(MethodMatcher.Modifier.Private, "set", 1)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue