use of com.google.api.expr.v1alpha1.Type in project openwebbeans by apache.
the class InterceptorDecoratorProxyFactory method delegateNonInterceptedMethods.
/**
* Directly delegate all non intercepted nor decorated methods to the internal instance.
*
* @param noninterceptedMethods all methods which are neither intercepted nor decorated
*/
@Override
protected void delegateNonInterceptedMethods(ClassLoader classLoader, ClassWriter cw, String proxyClassFileName, Class<?> classToProxy, Method[] noninterceptedMethods) {
for (Method delegatedMethod : noninterceptedMethods) {
if (unproxyableMethod(delegatedMethod) || isIgnoredMethod(delegatedMethod)) {
continue;
}
int modifiers = delegatedMethod.getModifiers();
if (Modifier.isProtected(modifiers) && !delegatedMethod.getDeclaringClass().getPackage().getName().equals(classToProxy.getPackage().getName())) {
continue;
}
String methodDescriptor = Type.getMethodDescriptor(delegatedMethod);
// X TODO handle generic exception types?
Class[] exceptionTypes = delegatedMethod.getExceptionTypes();
String[] exceptionTypeNames = new String[exceptionTypes.length];
for (int i = 0; i < exceptionTypes.length; i++) {
exceptionTypeNames[i] = Type.getType(exceptionTypes[i]).getInternalName();
}
int targetModifiers = modifiers & (Modifier.PROTECTED | Modifier.PUBLIC | MODIFIER_VARARGS);
MethodVisitor mv = cw.visitMethod(targetModifiers, delegatedMethod.getName(), methodDescriptor, null, exceptionTypeNames);
// fill method body
mv.visitCode();
// load the delegate variable
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitFieldInsn(Opcodes.GETFIELD, proxyClassFileName, FIELD_PROXIED_INSTANCE, Type.getDescriptor(classToProxy));
int offset = 1;
for (Class<?> aClass : delegatedMethod.getParameterTypes()) {
Type type = Type.getType(aClass);
mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), offset);
offset += type.getSize();
}
Type declaringClass = Type.getType(delegatedMethod.getDeclaringClass());
boolean isItf = delegatedMethod.getDeclaringClass().isInterface();
mv.visitMethodInsn(isItf ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, declaringClass.getInternalName(), delegatedMethod.getName(), methodDescriptor, isItf);
generateReturn(mv, delegatedMethod);
mv.visitMaxs(-1, -1);
mv.visitEnd();
}
}
Aggregations