Search in sources :

Example 86 with Type

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();
    }
}
Also used : AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Type(org.apache.xbean.asm9.Type) Method(java.lang.reflect.Method) MethodVisitor(org.apache.xbean.asm9.MethodVisitor)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 Test (org.junit.Test)16 MapType (com.google.api.expr.v1alpha1.Type.MapType)15 Type (edu.stanford.CVC4.Type)14 Type (com.google.spanner.v1.Type)12 Test (org.junit.jupiter.api.Test)12 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)11 ByteString (com.google.protobuf.ByteString)11 ArrayType (edu.stanford.CVC4.ArrayType)11 BitVectorType (edu.stanford.CVC4.BitVectorType)11 Expr (edu.stanford.CVC4.Expr)11 ArrayList (java.util.ArrayList)11 Type (org.apache.xbean.asm9.Type)10 Expr (com.google.api.expr.v1alpha1.Expr)9 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)9 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 ListValue (com.google.protobuf.ListValue)7 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)7 CheckerEnv.dynElementType (org.projectnessie.cel.checker.CheckerEnv.dynElementType)7 CheckerEnv.getObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType)7