Add comments on the two new match. #78
This commit is contained in:
parent
c0cb0c85b3
commit
a1f4e82fc4
|
|
@ -13,9 +13,15 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
|||
* Created by wusheng on 2017/1/3.
|
||||
*/
|
||||
public enum AllObjectDefaultMethodsMatch implements ElementMatcher<MethodDescription> {
|
||||
/**
|
||||
* Stay in singleton.
|
||||
*/
|
||||
INSTANCE;
|
||||
|
||||
private ElementMatcher.Junction<MethodDescription> matcher;
|
||||
/**
|
||||
* The matcher will be init in constructor and stay permanent.
|
||||
*/
|
||||
private final ElementMatcher.Junction<MethodDescription> matcher;
|
||||
|
||||
AllObjectDefaultMethodsMatch() {
|
||||
ElementMatcher.Junction<MethodDescription>[] allDefaultMethods = new ElementMatcher.Junction[] {named("finalize").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
|
||||
|
|
@ -30,13 +36,16 @@ public enum AllObjectDefaultMethodsMatch implements ElementMatcher<MethodDescrip
|
|||
named("notify").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic()),
|
||||
named("notifyAll").and(takesArguments(0)).and(ElementMatchers.<MethodDescription>isPublic())};
|
||||
|
||||
ElementMatcher.Junction<MethodDescription> newMatcher = null;
|
||||
for (int i = 0; i < allDefaultMethods.length; i++) {
|
||||
if(i == 0){
|
||||
matcher = allDefaultMethods[i];
|
||||
newMatcher = allDefaultMethods[i];
|
||||
}else{
|
||||
matcher.or(allDefaultMethods[i]);
|
||||
newMatcher = newMatcher.or(allDefaultMethods[i]);
|
||||
}
|
||||
}
|
||||
|
||||
matcher = newMatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,18 +4,39 @@ import net.bytebuddy.description.method.MethodDescription;
|
|||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
/**
|
||||
* Argument Type match.
|
||||
* Similar with {@link net.bytebuddy.matcher.ElementMatchers#takesArgument},
|
||||
* the only different between them is this match use {@link String} to declare the type, instead of {@link Class}.
|
||||
* This can avoid the classloader risk.
|
||||
*
|
||||
* Created by wusheng on 2016/12/1.
|
||||
*/
|
||||
public class ArgumentTypeNameMatch implements ElementMatcher<MethodDescription> {
|
||||
/**
|
||||
* the index of arguments list.
|
||||
*/
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* the target argument type at {@link ArgumentTypeNameMatch#index} of the arguments list.
|
||||
*/
|
||||
private String argumentTypeName;
|
||||
|
||||
/**
|
||||
* declare the match target method with the certain index and type.
|
||||
* @param index the index of arguments list.
|
||||
* @param argumentTypeName target argument type
|
||||
*/
|
||||
private ArgumentTypeNameMatch(int index, String argumentTypeName) {
|
||||
this.index = index;
|
||||
this.argumentTypeName = argumentTypeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the target method.
|
||||
* @param target target method description.
|
||||
* @return true if matched. or false.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(MethodDescription target) {
|
||||
if (target.getParameters().size() > index) {
|
||||
|
|
@ -25,6 +46,14 @@ public class ArgumentTypeNameMatch implements ElementMatcher<MethodDescription>
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The static method to create {@link ArgumentTypeNameMatch}
|
||||
* This is a delegate method to follow byte-buddy {@link ElementMatcher<MethodDescription>}'s code style.
|
||||
*
|
||||
* @param index the index of arguments list.
|
||||
* @param argumentTypeName target argument type
|
||||
* @return new {@link ArgumentTypeNameMatch} instance.
|
||||
*/
|
||||
public static ElementMatcher<MethodDescription> takesArgumentWithType(int index, String argumentTypeName){
|
||||
return new ArgumentTypeNameMatch(index, argumentTypeName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2.define;
|
||||
|
||||
import com.a.eye.skywalking.plugin.bytebuddy.AllObjectDefaultMethodsMatch;
|
||||
import com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch;
|
||||
import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
|
|
|||
Loading…
Reference in New Issue