动态代理实现源码剖析 —— 附录: cglib生成代理类

前言

本篇主要贴一下cglib生成的代理类源码,详细的分析过程参考动态代理实现源码剖析 —— 深入分析cglib动态代理

附录

附录1

package net.sf.cglib.proxy;

import net.sf.cglib.core.KeyFactory;
import net.sf.cglib.core.WeakCacheKey;
import net.sf.cglib.proxy.Enhancer.EnhancerKey;
import org.objectweb.asm.Type;

public class Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72 extends KeyFactory implements EnhancerKey {
    private final String FIELD_0;
    private final String[] FIELD_1;
    private final WeakCacheKey FIELD_2;
    private final Type[] FIELD_3;
    private final boolean FIELD_4;
    private final boolean FIELD_5;
    private final Long FIELD_6;

    public Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72() {
    }

    public Object newInstance(String var1, String[] var2, WeakCacheKey var3, Type[] var4, boolean var5, boolean var6, Long var7) {
        return new Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72(var1, var2, var3, var4, var5, var6, var7);
    }

    public Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72(String var1, String[] var2, WeakCacheKey var3, Type[] var4, boolean var5, boolean var6, Long var7) {
        this.FIELD_0 = var1;
        this.FIELD_1 = var2;
        this.FIELD_2 = var3;
        this.FIELD_3 = var4;
        this.FIELD_4 = var5;
        this.FIELD_5 = var6;
        this.FIELD_6 = var7;
    }

    public int hashCode() {
        int var10002 = 19289 * 641371;
        String var10001 = this.FIELD_0;
        int var10000 = var10002 + (var10001 != null ? var10001.hashCode() : 0);
        String[] var5 = this.FIELD_1;
        if (var5 != null) {
            String[] var1 = var5;

            for(int var2 = 0; var2 < var1.length; ++var2) {
                var10000 = var10000 * 641371 + (var1[var2] != null ? var1[var2].hashCode() : 0);
            }
        }

        var10002 = var10000 * 641371;
        WeakCacheKey var6 = this.FIELD_2;
        var10000 = var10002 + (var6 != null ? var6.hashCode() : 0);
        Type[] var7 = this.FIELD_3;
        if (var7 != null) {
            Type[] var3 = var7;

            for(int var4 = 0; var4 < var3.length; ++var4) {
                var10000 = var10000 * 641371 + (var3[var4] != null ? var3[var4].hashCode() : 0);
            }
        }

        var10002 = ((var10000 * 641371 + (this.FIELD_4 ^ 1)) * 641371 + (this.FIELD_5 ^ 1)) * 641371;
        Long var8 = this.FIELD_6;
        return var10002 + (var8 != null ? var8.hashCode() : 0);
    }

    public boolean equals(Object var1) {
        if (var1 instanceof Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72) {
            String var10000 = this.FIELD_0;
            String var10001 = ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_0;
            if (var10001 == null) {
                if (var10000 != null) {
                    return false;
                }
            } else if (var10000 == null || !var10000.equals(var10001)) {
                return false;
            }

            String[] var8 = this.FIELD_1;
            String[] var10 = ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_1;
            if (var10 == null) {
                if (var8 != null) {
                    return false;
                }
            } else {
                label178: {
                    if (var8 != null) {
                        if (var10.length == var8.length) {
                            String[] var2 = var10;
                            String[] var3 = var8;
                            int var4 = 0;

                            while(true) {
                                if (var4 >= var2.length) {
                                    break label178;
                                }

                                var10000 = var2[var4];
                                var10001 = var3[var4];
                                if (var3[var4] == null) {
                                    if (var10000 != null) {
                                        return false;
                                    }
                                } else if (var10000 == null || !var10000.equals(var10001)) {
                                    return false;
                                }

                                ++var4;
                            }
                        }
                    }

                    return false;
                }
            }

            WeakCacheKey var9 = this.FIELD_2;
            WeakCacheKey var13 = ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_2;
            if (var13 == null) {
                if (var9 != null) {
                    return false;
                }
            } else if (var9 == null || !var9.equals(var13)) {
                return false;
            }

            Type[] var11 = this.FIELD_3;
            Type[] var15 = ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_3;
            if (var15 == null) {
                if (var11 != null) {
                    return false;
                }
            } else {
                if (var11 == null) {
                    return false;
                }

                if (var15.length != var11.length) {
                    return false;
                }

                Type[] var5 = var15;
                Type[] var6 = var11;

                for(int var7 = 0; var7 < var5.length; ++var7) {
                    Type var12 = var5[var7];
                    Type var16 = var6[var7];
                    if (var6[var7] == null) {
                        if (var12 != null) {
                            return false;
                        }
                    } else if (var12 == null || !var12.equals(var16)) {
                        return false;
                    }
                }
            }

            if (this.FIELD_4 == ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_4 && this.FIELD_5 == ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_5) {
                Long var14 = this.FIELD_6;
                Long var17 = ((Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72)var1).FIELD_6;
                if (var17 == null) {
                    if (var14 == null) {
                        return true;
                    }
                } else if (var14 != null && var14.equals(var17)) {
                    return true;
                }
            }
        }

        return false;
    }

    public String toString() {
        StringBuffer var10000 = new StringBuffer();
        String var10001 = this.FIELD_0;
        var10000 = (var10001 != null ? var10000.append(var10001.toString()) : var10000.append("null")).append(", ");
        String[] var6 = this.FIELD_1;
        if (var6 != null) {
            var10000 = var10000.append("{");
            String[] var1 = var6;

            for(int var2 = 0; var2 < var1.length; ++var2) {
                var10000 = (var1[var2] != null ? var10000.append(var1[var2].toString()) : var10000.append("null")).append(", ");
            }

            var10000.setLength(var10000.length() - 2);
            var10000 = var10000.append("}");
        } else {
            var10000 = var10000.append("null");
        }

        var10000 = var10000.append(", ");
        WeakCacheKey var9 = this.FIELD_2;
        var10000 = (var9 != null ? var10000.append(var9.toString()) : var10000.append("null")).append(", ");
        Type[] var10 = this.FIELD_3;
        if (var10 != null) {
            var10000 = var10000.append("{");
            Type[] var3 = var10;

            for(int var4 = 0; var4 < var3.length; ++var4) {
                var10000 = (var3[var4] != null ? var10000.append(var3[var4].toString()) : var10000.append("null")).append(", ");
            }

            var10000.setLength(var10000.length() - 2);
            var10000 = var10000.append("}");
        } else {
            var10000 = var10000.append("null");
        }

        var10000 = var10000.append(", ").append(this.FIELD_4).append(", ").append(this.FIELD_5).append(", ");
        Long var13 = this.FIELD_6;
        return (var13 != null ? var10000.append(var13.toString()) : var10000.append("null")).toString();
    }
}

附录2

import java.lang.reflect.Method;
import net.sf.cglib.core.ReflectUtils;
import net.sf.cglib.core.Signature;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Factory;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class SomeClass$$EnhancerByCGLIB$$4ef3bf64 extends SomeClass implements Factory {
    private boolean CGLIB$BOUND;
    public static Object CGLIB$FACTORY_DATA;
    private static final ThreadLocal CGLIB$THREAD_CALLBACKS;
    private static final Callback[] CGLIB$STATIC_CALLBACKS;
    private MethodInterceptor CGLIB$CALLBACK_0;
    private MethodInterceptor CGLIB$CALLBACK_1;
    private static Object CGLIB$CALLBACK_FILTER;
    private static final Method CGLIB$doOtherthing$0$Method;
    private static final MethodProxy CGLIB$doOtherthing$0$Proxy;
    private static final Object[] CGLIB$emptyArgs;
    private static final Method CGLIB$doSomething$1$Method;
    private static final MethodProxy CGLIB$doSomething$1$Proxy;
    private static final Method CGLIB$equals$2$Method;
    private static final MethodProxy CGLIB$equals$2$Proxy;
    private static final Method CGLIB$toString$3$Method;
    private static final MethodProxy CGLIB$toString$3$Proxy;
    private static final Method CGLIB$hashCode$4$Method;
    private static final MethodProxy CGLIB$hashCode$4$Proxy;
    private static final Method CGLIB$clone$5$Method;
    private static final MethodProxy CGLIB$clone$5$Proxy;

    static void CGLIB$STATICHOOK1() {
        CGLIB$THREAD_CALLBACKS = new ThreadLocal();
        CGLIB$emptyArgs = new Object[0];
        Class var0 = Class.forName("com.kuaishou.is.proxy.SomeClass$$EnhancerByCGLIB$$4ef3bf64");
        Class var1;
        Method[] var10000 = ReflectUtils.findMethods(new String[]{"equals", "(Ljava/lang/Object;)Z", "toString", "()Ljava/lang/String;", "hashCode", "()I", "clone", "()Ljava/lang/Object;"}, (var1 = Class.forName("java.lang.Object")).getDeclaredMethods());
        CGLIB$equals$2$Method = var10000[0];
        CGLIB$equals$2$Proxy = MethodProxy.create(var1, var0, "(Ljava/lang/Object;)Z", "equals", "CGLIB$equals$2");
        CGLIB$toString$3$Method = var10000[1];
        CGLIB$toString$3$Proxy = MethodProxy.create(var1, var0, "()Ljava/lang/String;", "toString", "CGLIB$toString$3");
        CGLIB$hashCode$4$Method = var10000[2];
        CGLIB$hashCode$4$Proxy = MethodProxy.create(var1, var0, "()I", "hashCode", "CGLIB$hashCode$4");
        CGLIB$clone$5$Method = var10000[3];
        CGLIB$clone$5$Proxy = MethodProxy.create(var1, var0, "()Ljava/lang/Object;", "clone", "CGLIB$clone$5");
        var10000 = ReflectUtils.findMethods(new String[]{"doOtherthing", "()V", "doSomething", "()V"}, (var1 = Class.forName("com.kuaishou.is.proxy.SomeClass")).getDeclaredMethods());
        CGLIB$doOtherthing$0$Method = var10000[0];
        CGLIB$doOtherthing$0$Proxy = MethodProxy.create(var1, var0, "()V", "doOtherthing", "CGLIB$doOtherthing$0");
        CGLIB$doSomething$1$Method = var10000[1];
        CGLIB$doSomething$1$Proxy = MethodProxy.create(var1, var0, "()V", "doSomething", "CGLIB$doSomething$1");
    }

    final void CGLIB$doOtherthing$0() {
        super.doOtherthing();
    }

    public final void doOtherthing() {
        MethodInterceptor var10000 = this.CGLIB$CALLBACK_1;
        if (var10000 == null) {
            CGLIB$BIND_CALLBACKS(this);
            var10000 = this.CGLIB$CALLBACK_1;
        }

        if (var10000 != null) {
            var10000.intercept(this, CGLIB$doOtherthing$0$Method, CGLIB$emptyArgs, CGLIB$doOtherthing$0$Proxy);
        } else {
            super.doOtherthing();
        }
    }

    final void CGLIB$doSomething$1() {
        super.doSomething();
    }

    public final void doSomething() {
        MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
        if (var10000 == null) {
            CGLIB$BIND_CALLBACKS(this);
            var10000 = this.CGLIB$CALLBACK_0;
        }

        if (var10000 != null) {
            var10000.intercept(this, CGLIB$doSomething$1$Method, CGLIB$emptyArgs, CGLIB$doSomething$1$Proxy);
        } else {
            super.doSomething();
        }
    }

    final boolean CGLIB$equals$2(Object var1) {
        return super.equals(var1);
    }

    public final boolean equals(Object var1) {
        MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
        if (var10000 == null) {
            CGLIB$BIND_CALLBACKS(this);
            var10000 = this.CGLIB$CALLBACK_0;
        }

        if (var10000 != null) {
            Object var2 = var10000.intercept(this, CGLIB$equals$2$Method, new Object[]{var1}, CGLIB$equals$2$Proxy);
            return var2 == null ? false : (Boolean)var2;
        } else {
            return super.equals(var1);
        }
    }

    final String CGLIB$toString$3() {
        return super.toString();
    }

    public final String toString() {
        MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
        if (var10000 == null) {
            CGLIB$BIND_CALLBACKS(this);
            var10000 = this.CGLIB$CALLBACK_0;
        }

        return var10000 != null ? (String)var10000.intercept(this, CGLIB$toString$3$Method, CGLIB$emptyArgs, CGLIB$toString$3$Proxy) : super.toString();
    }

    final int CGLIB$hashCode$4() {
        return super.hashCode();
    }

    public final int hashCode() {
        MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
        if (var10000 == null) {
            CGLIB$BIND_CALLBACKS(this);
            var10000 = this.CGLIB$CALLBACK_0;
        }

        if (var10000 != null) {
            Object var1 = var10000.intercept(this, CGLIB$hashCode$4$Method, CGLIB$emptyArgs, CGLIB$hashCode$4$Proxy);
            return var1 == null ? 0 : ((Number)var1).intValue();
        } else {
            return super.hashCode();
        }
    }

    final Object CGLIB$clone$5() throws CloneNotSupportedException {
        return super.clone();
    }

    protected final Object clone() throws CloneNotSupportedException {
        MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
        if (var10000 == null) {
            CGLIB$BIND_CALLBACKS(this);
            var10000 = this.CGLIB$CALLBACK_0;
        }

        return var10000 != null ? var10000.intercept(this, CGLIB$clone$5$Method, CGLIB$emptyArgs, CGLIB$clone$5$Proxy) : super.clone();
    }

    public static MethodProxy CGLIB$findMethodProxy(Signature var0) {
        String var10000 = var0.toString();
        switch(var10000.hashCode()) {
        case -508378822:
            if (var10000.equals("clone()Ljava/lang/Object;")) {
                return CGLIB$clone$5$Proxy;
            }
            break;
        case 1294226444:
            if (var10000.equals("doOtherthing()V")) {
                return CGLIB$doOtherthing$0$Proxy;
            }
            break;
        case 1826985398:
            if (var10000.equals("equals(Ljava/lang/Object;)Z")) {
                return CGLIB$equals$2$Proxy;
            }
            break;
        case 1913648695:
            if (var10000.equals("toString()Ljava/lang/String;")) {
                return CGLIB$toString$3$Proxy;
            }
            break;
        case 1984935277:
            if (var10000.equals("hashCode()I")) {
                return CGLIB$hashCode$4$Proxy;
            }
            break;
        case 2121560294:
            if (var10000.equals("doSomething()V")) {
                return CGLIB$doSomething$1$Proxy;
            }
        }

        return null;
    }

    public SomeClass$$EnhancerByCGLIB$$4ef3bf64() {
        CGLIB$BIND_CALLBACKS(this);
    }

    public static void CGLIB$SET_THREAD_CALLBACKS(Callback[] var0) {
        CGLIB$THREAD_CALLBACKS.set(var0);
    }

    public static void CGLIB$SET_STATIC_CALLBACKS(Callback[] var0) {
        CGLIB$STATIC_CALLBACKS = var0;
    }

    private static final void CGLIB$BIND_CALLBACKS(Object var0) {
        SomeClass$$EnhancerByCGLIB$$4ef3bf64 var1 = (SomeClass$$EnhancerByCGLIB$$4ef3bf64)var0;
        if (!var1.CGLIB$BOUND) {
            var1.CGLIB$BOUND = true;
            Object var10000 = CGLIB$THREAD_CALLBACKS.get();
            if (var10000 == null) {
                var10000 = CGLIB$STATIC_CALLBACKS;
                if (var10000 == null) {
                    return;
                }
            }

            Callback[] var10001 = (Callback[])var10000;
            var1.CGLIB$CALLBACK_1 = (MethodInterceptor)((Callback[])var10000)[1];
            var1.CGLIB$CALLBACK_0 = (MethodInterceptor)var10001[0];
        }

    }

    public Object newInstance(Callback[] var1) {
        CGLIB$SET_THREAD_CALLBACKS(var1);
        SomeClass$$EnhancerByCGLIB$$4ef3bf64 var10000 = new SomeClass$$EnhancerByCGLIB$$4ef3bf64();
        CGLIB$SET_THREAD_CALLBACKS((Callback[])null);
        return var10000;
    }

    public Object newInstance(Callback var1) {
        throw new IllegalStateException("More than one callback object required");
    }

    public Object newInstance(Class[] var1, Object[] var2, Callback[] var3) {
        CGLIB$SET_THREAD_CALLBACKS(var3);
        SomeClass$$EnhancerByCGLIB$$4ef3bf64 var10000 = new SomeClass$$EnhancerByCGLIB$$4ef3bf64;
        switch(var1.length) {
        case 0:
            var10000.();
            CGLIB$SET_THREAD_CALLBACKS((Callback[])null);
            return var10000;
        default:
            throw new IllegalArgumentException("Constructor not found");
        }
    }

    public Callback getCallback(int var1) {
        CGLIB$BIND_CALLBACKS(this);
        MethodInterceptor var10000;
        switch(var1) {
        case 0:
            var10000 = this.CGLIB$CALLBACK_0;
            break;
        case 1:
            var10000 = this.CGLIB$CALLBACK_1;
            break;
        default:
            var10000 = null;
        }

        return var10000;
    }

    public void setCallback(int var1, Callback var2) {
        switch(var1) {
        case 0:
            this.CGLIB$CALLBACK_0 = (MethodInterceptor)var2;
            break;
        case 1:
            this.CGLIB$CALLBACK_1 = (MethodInterceptor)var2;
        }

    }

    public Callback[] getCallbacks() {
        CGLIB$BIND_CALLBACKS(this);
        return new Callback[]{this.CGLIB$CALLBACK_0, this.CGLIB$CALLBACK_1};
    }

    public void setCallbacks(Callback[] var1) {
        this.CGLIB$CALLBACK_0 = (MethodInterceptor)var1[0];
        this.CGLIB$CALLBACK_1 = (MethodInterceptor)var1[1];
    }

    static {
        CGLIB$STATICHOOK1();
    }
}

附录3

package net.sf.cglib.core;

import net.sf.cglib.core.MethodWrapper.MethodWrapperKey;

public class MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7 extends KeyFactory implements MethodWrapperKey {
    private final String FIELD_0;
    private final String[] FIELD_1;
    private final String FIELD_2;

    public MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7() {
    }

    public Object newInstance(String var1, String[] var2, String var3) {
        return new MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7(var1, var2, var3);
    }

    public MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7(String var1, String[] var2, String var3) {
        this.FIELD_0 = var1;
        this.FIELD_1 = var2;
        this.FIELD_2 = var3;
    }

    public int hashCode() {
        int var10002 = 938313161 * 362693231;
        String var10001 = this.FIELD_0;
        int var10000 = var10002 + (var10001 != null ? var10001.hashCode() : 0);
        String[] var3 = this.FIELD_1;
        if (var3 != null) {
            String[] var1 = var3;

            for(int var2 = 0; var2 < var1.length; ++var2) {
                var10000 = var10000 * 362693231 + (var1[var2] != null ? var1[var2].hashCode() : 0);
            }
        }

        var10002 = var10000 * 362693231;
        var10001 = this.FIELD_2;
        return var10002 + (var10001 != null ? var10001.hashCode() : 0);
    }

    public boolean equals(Object var1) {
        if (var1 instanceof MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7) {
            String var10000 = this.FIELD_0;
            String var10001 = ((MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7)var1).FIELD_0;
            if (var10001 == null) {
                if (var10000 != null) {
                    return false;
                }
            } else if (var10000 == null || !var10000.equals(var10001)) {
                return false;
            }

            String[] var5 = this.FIELD_1;
            String[] var6 = ((MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7)var1).FIELD_1;
            if (var6 == null) {
                if (var5 != null) {
                    return false;
                }
            } else {
                label104: {
                    if (var5 != null) {
                        if (var6.length == var5.length) {
                            String[] var2 = var6;
                            String[] var3 = var5;
                            int var4 = 0;

                            while(true) {
                                if (var4 >= var2.length) {
                                    break label104;
                                }

                                var10000 = var2[var4];
                                var10001 = var3[var4];
                                if (var3[var4] == null) {
                                    if (var10000 != null) {
                                        return false;
                                    }
                                } else if (var10000 == null || !var10000.equals(var10001)) {
                                    return false;
                                }

                                ++var4;
                            }
                        }
                    }

                    return false;
                }
            }

            var10000 = this.FIELD_2;
            var10001 = ((MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$d45e49f7)var1).FIELD_2;
            if (var10001 == null) {
                if (var10000 == null) {
                    return true;
                }
            } else if (var10000 != null && var10000.equals(var10001)) {
                return true;
            }
        }

        return false;
    }

    public String toString() {
        StringBuffer var10000 = new StringBuffer();
        String var10001 = this.FIELD_0;
        var10000 = (var10001 != null ? var10000.append(var10001.toString()) : var10000.append("null")).append(", ");
        String[] var4 = this.FIELD_1;
        if (var4 != null) {
            var10000 = var10000.append("{");
            String[] var1 = var4;

            for(int var2 = 0; var2 < var1.length; ++var2) {
                var10000 = (var1[var2] != null ? var10000.append(var1[var2].toString()) : var10000.append("null")).append(", ");
            }

            var10000.setLength(var10000.length() - 2);
            var10000 = var10000.append("}");
        } else {
            var10000 = var10000.append("null");
        }

        var10000 = var10000.append(", ");
        var10001 = this.FIELD_2;
        return (var10001 != null ? var10000.append(var10001.toString()) : var10000.append("null")).toString();
    }
}

附录4

import java.lang.reflect.InvocationTargetException;
import net.sf.cglib.core.Signature;
import net.sf.cglib.reflect.FastClass;

public class SomeClass$$FastClassByCGLIB$$a7b28414 extends FastClass {
    public SomeClass$$FastClassByCGLIB$$a7b28414(Class var1) {
        super(var1);
    }

    public int getIndex(Signature var1) {
        String var10000 = var1.toString();
        switch(var10000.hashCode()) {
        case 1294226444:
            if (var10000.equals("doOtherthing()V")) {
                return 0;
            }
            break;
        case 1826985398:
            if (var10000.equals("equals(Ljava/lang/Object;)Z")) {
                return 2;
            }
            break;
        case 1913648695:
            if (var10000.equals("toString()Ljava/lang/String;")) {
                return 3;
            }
            break;
        case 1984935277:
            if (var10000.equals("hashCode()I")) {
                return 4;
            }
            break;
        case 2121560294:
            if (var10000.equals("doSomething()V")) {
                return 1;
            }
        }

        return -1;
    }

    public int getIndex(String var1, Class[] var2) {
        switch(var1.hashCode()) {
        case -1776922004:
            if (var1.equals("toString")) {
                switch(var2.length) {
                case 0:
                    return 3;
                }
            }
            break;
        case -1295482945:
            if (var1.equals("equals")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("java.lang.Object")) {
                        return 2;
                    }
                }
            }
            break;
        case -39459127:
            if (var1.equals("doOtherthing")) {
                switch(var2.length) {
                case 0:
                    return 0;
                }
            }
            break;
        case 147696667:
            if (var1.equals("hashCode")) {
                switch(var2.length) {
                case 0:
                    return 4;
                }
            }
            break;
        case 1794410543:
            if (var1.equals("doSomething")) {
                switch(var2.length) {
                case 0:
                    return 1;
                }
            }
        }

        return -1;
    }

    public int getIndex(Class[] var1) {
        switch(var1.length) {
        case 0:
            return 0;
        default:
            return -1;
        }
    }

    public Object invoke(int var1, Object var2, Object[] var3) throws InvocationTargetException {
        SomeClass var10000 = (SomeClass)var2;
        int var10001 = var1;

        try {
            switch(var10001) {
            case 0:
                var10000.doOtherthing();
                return null;
            case 1:
                var10000.doSomething();
                return null;
            case 2:
                return new Boolean(var10000.equals(var3[0]));
            case 3:
                return var10000.toString();
            case 4:
                return new Integer(var10000.hashCode());
            }
        } catch (Throwable var4) {
            throw new InvocationTargetException(var4);
        }

        throw new IllegalArgumentException("Cannot find matching method/constructor");
    }

    public Object newInstance(int var1, Object[] var2) throws InvocationTargetException {
        SomeClass var10000 = new SomeClass;
        SomeClass var10001 = var10000;
        int var10002 = var1;

        try {
            switch(var10002) {
            case 0:
                var10001.();
                return var10000;
            }
        } catch (Throwable var3) {
            throw new InvocationTargetException(var3);
        }

        throw new IllegalArgumentException("Cannot find matching method/constructor");
    }

    public int getMaxIndex() {
        return 4;
    }
}

附录5

import com.kuaishou.is.proxy.SomeClass..EnhancerByCGLIB..4ef3bf64;
import java.lang.reflect.InvocationTargetException;
import net.sf.cglib.core.Signature;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.reflect.FastClass;

public class SomeClass$$EnhancerByCGLIB$$4ef3bf64$$FastClassByCGLIB$$87e87332 extends FastClass {
    public SomeClass$$EnhancerByCGLIB$$4ef3bf64$$FastClassByCGLIB$$87e87332(Class var1) {
        super(var1);
    }

    public int getIndex(Signature var1) {
        String var10000 = var1.toString();
        switch(var10000.hashCode()) {
        case -2055565910:
            if (var10000.equals("CGLIB$SET_THREAD_CALLBACKS([Lnet/sf/cglib/proxy/Callback;)V")) {
                return 4;
            }
            break;
        case -1457535688:
            if (var10000.equals("CGLIB$STATICHOOK1()V")) {
                return 18;
            }
            break;
        case -1411812934:
            if (var10000.equals("CGLIB$hashCode$4()I")) {
                return 16;
            }
            break;
        case -1002730531:
            if (var10000.equals("CGLIB$doOtherthing$0()V")) {
                return 19;
            }
            break;
        case -894172689:
            if (var10000.equals("newInstance(Lnet/sf/cglib/proxy/Callback;)Ljava/lang/Object;")) {
                return 12;
            }
            break;
        case -713858116:
            if (var10000.equals("CGLIB$doSomething$1()V")) {
                return 20;
            }
            break;
        case -623122092:
            if (var10000.equals("CGLIB$findMethodProxy(Lnet/sf/cglib/core/Signature;)Lnet/sf/cglib/proxy/MethodProxy;")) {
                return 1;
            }
            break;
        case -508378822:
            if (var10000.equals("clone()Ljava/lang/Object;")) {
                return 10;
            }
            break;
        case -419626537:
            if (var10000.equals("setCallbacks([Lnet/sf/cglib/proxy/Callback;)V")) {
                return 21;
            }
            break;
        case 374345669:
            if (var10000.equals("CGLIB$equals$2(Ljava/lang/Object;)Z")) {
                return 14;
            }
            break;
        case 560567118:
            if (var10000.equals("setCallback(ILnet/sf/cglib/proxy/Callback;)V")) {
                return 2;
            }
            break;
        case 811063227:
            if (var10000.equals("newInstance([Ljava/lang/Class;[Ljava/lang/Object;[Lnet/sf/cglib/proxy/Callback;)Ljava/lang/Object;")) {
                return 11;
            }
            break;
        case 973717575:
            if (var10000.equals("getCallbacks()[Lnet/sf/cglib/proxy/Callback;")) {
                return 6;
            }
            break;
        case 1221173700:
            if (var10000.equals("newInstance([Lnet/sf/cglib/proxy/Callback;)Ljava/lang/Object;")) {
                return 13;
            }
            break;
        case 1230699260:
            if (var10000.equals("getCallback(I)Lnet/sf/cglib/proxy/Callback;")) {
                return 5;
            }
            break;
        case 1294226444:
            if (var10000.equals("doOtherthing()V")) {
                return 0;
            }
            break;
        case 1517819849:
            if (var10000.equals("CGLIB$toString$3()Ljava/lang/String;")) {
                return 15;
            }
            break;
        case 1584330438:
            if (var10000.equals("CGLIB$SET_STATIC_CALLBACKS([Lnet/sf/cglib/proxy/Callback;)V")) {
                return 3;
            }
            break;
        case 1826985398:
            if (var10000.equals("equals(Ljava/lang/Object;)Z")) {
                return 7;
            }
            break;
        case 1913648695:
            if (var10000.equals("toString()Ljava/lang/String;")) {
                return 8;
            }
            break;
        case 1984935277:
            if (var10000.equals("hashCode()I")) {
                return 9;
            }
            break;
        case 2011844968:
            if (var10000.equals("CGLIB$clone$5()Ljava/lang/Object;")) {
                return 17;
            }
            break;
        case 2121560294:
            if (var10000.equals("doSomething()V")) {
                return 22;
            }
        }

        return -1;
    }

    public int getIndex(String var1, Class[] var2) {
        switch(var1.hashCode()) {
        case -1776922004:
            if (var1.equals("toString")) {
                switch(var2.length) {
                case 0:
                    return 8;
                }
            }
            break;
        case -1295482945:
            if (var1.equals("equals")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("java.lang.Object")) {
                        return 7;
                    }
                }
            }
            break;
        case -1053468136:
            if (var1.equals("getCallbacks")) {
                switch(var2.length) {
                case 0:
                    return 6;
                }
            }
            break;
        case -124978608:
            if (var1.equals("CGLIB$equals$2")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("java.lang.Object")) {
                        return 14;
                    }
                }
            }
            break;
        case -73848680:
            if (var1.equals("CGLIB$doOtherthing$0")) {
                switch(var2.length) {
                case 0:
                    return 19;
                }
            }
            break;
        case -60403779:
            if (var1.equals("CGLIB$SET_STATIC_CALLBACKS")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("[Lnet.sf.cglib.proxy.Callback;")) {
                        return 3;
                    }
                }
            }
            break;
        case -39459127:
            if (var1.equals("doOtherthing")) {
                switch(var2.length) {
                case 0:
                    return 0;
                }
            }
            break;
        case -29025554:
            if (var1.equals("CGLIB$hashCode$4")) {
                switch(var2.length) {
                case 0:
                    return 16;
                }
            }
            break;
        case 85179481:
            if (var1.equals("CGLIB$SET_THREAD_CALLBACKS")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("[Lnet.sf.cglib.proxy.Callback;")) {
                        return 4;
                    }
                }
            }
            break;
        case 94756189:
            if (var1.equals("clone")) {
                switch(var2.length) {
                case 0:
                    return 10;
                }
            }
            break;
        case 147696667:
            if (var1.equals("hashCode")) {
                switch(var2.length) {
                case 0:
                    return 9;
                }
            }
            break;
        case 161998109:
            if (var1.equals("CGLIB$STATICHOOK1")) {
                switch(var2.length) {
                case 0:
                    return 18;
                }
            }
            break;
        case 180909337:
            if (var1.equals("CGLIB$doSomething$1")) {
                switch(var2.length) {
                case 0:
                    return 20;
                }
            }
            break;
        case 495524492:
            if (var1.equals("setCallbacks")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("[Lnet.sf.cglib.proxy.Callback;")) {
                        return 21;
                    }
                }
            }
            break;
        case 1154623345:
            if (var1.equals("CGLIB$findMethodProxy")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("net.sf.cglib.core.Signature")) {
                        return 1;
                    }
                }
            }
            break;
        case 1543336190:
            if (var1.equals("CGLIB$toString$3")) {
                switch(var2.length) {
                case 0:
                    return 15;
                }
            }
            break;
        case 1794410543:
            if (var1.equals("doSomething")) {
                switch(var2.length) {
                case 0:
                    return 22;
                }
            }
            break;
        case 1811874389:
            if (var1.equals("newInstance")) {
                switch(var2.length) {
                case 1:
                    String var10001 = var2[0].getName();
                    switch(var10001.hashCode()) {
                    case -845341380:
                        if (var10001.equals("net.sf.cglib.proxy.Callback")) {
                            return 12;
                        }
                        break;
                    case 1730110032:
                        if (var10001.equals("[Lnet.sf.cglib.proxy.Callback;")) {
                            return 13;
                        }
                    }
                case 2:
                default:
                    break;
                case 3:
                    if (var2[0].getName().equals("[Ljava.lang.Class;") && var2[1].getName().equals("[Ljava.lang.Object;") && var2[2].getName().equals("[Lnet.sf.cglib.proxy.Callback;")) {
                        return 11;
                    }
                }
            }
            break;
        case 1817099975:
            if (var1.equals("setCallback")) {
                switch(var2.length) {
                case 2:
                    if (var2[0].getName().equals("int") && var2[1].getName().equals("net.sf.cglib.proxy.Callback")) {
                        return 2;
                    }
                }
            }
            break;
        case 1905679803:
            if (var1.equals("getCallback")) {
                switch(var2.length) {
                case 1:
                    if (var2[0].getName().equals("int")) {
                        return 5;
                    }
                }
            }
            break;
        case 1951977611:
            if (var1.equals("CGLIB$clone$5")) {
                switch(var2.length) {
                case 0:
                    return 17;
                }
            }
        }

        return -1;
    }

    public int getIndex(Class[] var1) {
        switch(var1.length) {
        case 0:
            return 0;
        default:
            return -1;
        }
    }

    public Object invoke(int var1, Object var2, Object[] var3) throws InvocationTargetException {
        4ef3bf64 var10000 = (4ef3bf64)var2;
        int var10001 = var1;

        try {
            switch(var10001) {
            case 0:
                var10000.doOtherthing();
                return null;
            case 1:
                return 4ef3bf64.CGLIB$findMethodProxy((Signature)var3[0]);
            case 2:
                var10000.setCallback(((Number)var3[0]).intValue(), (Callback)var3[1]);
                return null;
            case 3:
                4ef3bf64.CGLIB$SET_STATIC_CALLBACKS((Callback[])var3[0]);
                return null;
            case 4:
                4ef3bf64.CGLIB$SET_THREAD_CALLBACKS((Callback[])var3[0]);
                return null;
            case 5:
                return var10000.getCallback(((Number)var3[0]).intValue());
            case 6:
                return var10000.getCallbacks();
            case 7:
                return new Boolean(var10000.equals(var3[0]));
            case 8:
                return var10000.toString();
            case 9:
                return new Integer(var10000.hashCode());
            case 10:
                return var10000.clone();
            case 11:
                return var10000.newInstance((Class[])var3[0], (Object[])var3[1], (Callback[])var3[2]);
            case 12:
                return var10000.newInstance((Callback)var3[0]);
            case 13:
                return var10000.newInstance((Callback[])var3[0]);
            case 14:
                return new Boolean(var10000.CGLIB$equals$2(var3[0]));
            case 15:
                return var10000.CGLIB$toString$3();
            case 16:
                return new Integer(var10000.CGLIB$hashCode$4());
            case 17:
                return var10000.CGLIB$clone$5();
            case 18:
                4ef3bf64.CGLIB$STATICHOOK1();
                return null;
            case 19:
                var10000.CGLIB$doOtherthing$0();
                return null;
            case 20:
                var10000.CGLIB$doSomething$1();
                return null;
            case 21:
                var10000.setCallbacks((Callback[])var3[0]);
                return null;
            case 22:
                var10000.doSomething();
                return null;
            }
        } catch (Throwable var4) {
            throw new InvocationTargetException(var4);
        }

        throw new IllegalArgumentException("Cannot find matching method/constructor");
    }

    public Object newInstance(int var1, Object[] var2) throws InvocationTargetException {
        4ef3bf64 var10000 = new 4ef3bf64;
        4ef3bf64 var10001 = var10000;
        int var10002 = var1;

        try {
            switch(var10002) {
            case 0:
                var10001.();
                return var10000;
            }
        } catch (Throwable var3) {
            throw new InvocationTargetException(var3);
        }

        throw new IllegalArgumentException("Cannot find matching method/constructor");
    }

    public int getMaxIndex() {
        return 22;
    }
}

你可能感兴趣的:(动态代理实现源码剖析 —— 附录: cglib生成代理类)