java rt.jar 源码 不全_spring-core-5.0.6.RELEASE-sources.jar中java源代码不全

本文深入剖析了 Spring 的 CGLib 库中 MethodProxy 类的实现,它用于动态代理生成及方法调用。MethodProxy 内部包含了 Signature 对象、FastClass 信息,并提供了创建实例、获取方法签名、调用目标方法等关键功能。通过 FastClass 实现高效的方法调用,是 Spring AOP 中的重要组成部分。
摘要由CSDN通过智能技术生成

//

//Source code recreated from a .class file by IntelliJ IDEA//(powered by Fernflower decompiler)//

packageorg.springframework.cglib.proxy;importjava.lang.reflect.InvocationTargetException;importjava.lang.reflect.Method;importorg.springframework.cglib.core.AbstractClassGenerator;importorg.springframework.cglib.core.CodeGenerationException;importorg.springframework.cglib.core.GeneratorStrategy;importorg.springframework.cglib.core.NamingPolicy;importorg.springframework.cglib.core.Signature;importorg.springframework.cglib.reflect.FastClass;importorg.springframework.cglib.reflect.FastClass.Generator;public classMethodProxy {privateSignature sig1;privateSignature sig2;privateMethodProxy.CreateInfo createInfo;private final Object initLock = newObject();private volatileMethodProxy.FastClassInfo fastClassInfo;public staticMethodProxy create(Class c1, Class c2, String desc, String name1, String name2) {

MethodProxy proxy= newMethodProxy();

proxy.sig1= newSignature(name1, desc);

proxy.sig2= newSignature(name2, desc);

proxy.createInfo= newMethodProxy.CreateInfo(c1, c2);returnproxy;

}private voidinit() {if (this.fastClassInfo == null) {synchronized(this.initLock) {if (this.fastClassInfo == null) {

MethodProxy.CreateInfo ci= this.createInfo;

MethodProxy.FastClassInfo fci= newMethodProxy.FastClassInfo();

fci.f1=helper(ci, ci.c1);

fci.f2=helper(ci, ci.c2);

fci.i1= fci.f1.getIndex(this.sig1);

fci.i2= fci.f2.getIndex(this.sig2);this.fastClassInfo =fci;this.createInfo = null;

}

}

}

}private staticFastClass helper(MethodProxy.CreateInfo ci, Class type) {

Generator g= newGenerator();

g.setType(type);

g.setClassLoader(ci.c2.getClassLoader());

g.setNamingPolicy(ci.namingPolicy);

g.setStrategy(ci.strategy);

g.setAttemptLoad(ci.attemptLoad);returng.create();

}privateMethodProxy() {

}publicSignature getSignature() {return this.sig1;

}publicString getSuperName() {return this.sig2.getName();

}public intgetSuperIndex() {this.init();return this.fastClassInfo.i2;

}

FastClass getFastClass() {this.init();return this.fastClassInfo.f1;

}

FastClass getSuperFastClass() {this.init();return this.fastClassInfo.f2;

}public staticMethodProxy find(Class type, Signature sig) {try{

Method m= type.getDeclaredMethod("CGLIB$findMethodProxy", MethodInterceptorGenerator.FIND_PROXY_TYPES);return (MethodProxy)m.invoke((Object)null, sig);

}catch(NoSuchMethodException var3) {throw new IllegalArgumentException("Class " + type + " does not use a MethodInterceptor");

}catch(IllegalAccessException var4) {throw newCodeGenerationException(var4);

}catch(InvocationTargetException var5) {throw newCodeGenerationException(var5);

}

}public Object invoke(Object obj, Object[] args) throwsThrowable {try{this.init();

MethodProxy.FastClassInfo fci= this.fastClassInfo;returnfci.f1.invoke(fci.i1, obj, args);

}catch(InvocationTargetException var4) {throwvar4.getTargetException();

}catch(IllegalArgumentException var5) {if (this.fastClassInfo.i1 < 0) {throw new IllegalArgumentException("Protected method: " + this.sig1);

}else{throwvar5;

}

}

}public Object invokeSuper(Object obj, Object[] args) throwsThrowable {try{this.init();

MethodProxy.FastClassInfo fci= this.fastClassInfo;returnfci.f2.invoke(fci.i2, obj, args);

}catch(InvocationTargetException var4) {throwvar4.getTargetException();

}

}private static classCreateInfo {

Class c1;

Class c2;

NamingPolicy namingPolicy;

GeneratorStrategy strategy;booleanattemptLoad;publicCreateInfo(Class c1, Class c2) {this.c1 =c1;this.c2 =c2;

AbstractClassGenerator fromEnhancer=AbstractClassGenerator.getCurrent();if (fromEnhancer != null) {this.namingPolicy =fromEnhancer.getNamingPolicy();this.strategy =fromEnhancer.getStrategy();this.attemptLoad =fromEnhancer.getAttemptLoad();

}

}

}private static classFastClassInfo {

FastClass f1;

FastClass f2;inti1;inti2;privateFastClassInfo() {

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值