Package org.codehaus.aspectwerkz.reflect

Examples of org.codehaus.aspectwerkz.reflect.FieldInfo


     * @return the annotations in a list (can be empty)
     */
    public static List getAnnotations(final String annotationName, final Field field) {
        ClassLoader loader = field.getDeclaringClass().getClassLoader();
        ClassInfo classInfo = AsmClassInfo.getClassInfo(field.getDeclaringClass().getName(), loader);
        FieldInfo fieldInfo = classInfo.getField(ReflectHelper.calculateHash(field));
        return AsmAnnotations.getAnnotations(annotationName, fieldInfo);
    }
View Full Code Here


    }

    // ============ pointcut type tests =============
    public void testPointcutTypes() throws Exception {
        MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[]{}));
        FieldInfo field = JavaFieldInfo.getFieldInfo(Target.class.getDeclaredField("modifier1"));
        assertTrue(
                new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, method, null))
        );
        assertFalse(
View Full Code Here

            m_declaringTypeName = name;
            m_mixinFields = new HashMap();

            // populate with fields already present for mixins from previous weaving
            for (int i = 0; i < m_classInfo.getFields().length; i++) {
                FieldInfo fieldInfo = m_classInfo.getFields()[i];
                if (fieldInfo.getName().startsWith(MIXIN_FIELD_NAME)) {
                    m_mixinFields.put(fieldInfo.getType(), fieldInfo);
                }
            }

            // add fields and method for (not already there) mixins
            addMixinMembers();
View Full Code Here

            fieldName.equals(SERIAL_VERSION_UID_FIELD_NAME)) {  // can have been added by the weaver (not safe)
            return;
        }

        int joinPointHash = AsmHelper.calculateFieldHash(fieldName, fieldDesc);
        FieldInfo fieldInfo = getFieldInfo(m_classInfo, m_declaringTypeName, fieldName, fieldDesc, joinPointHash);

        ExpressionContext[] ctxs = new ExpressionContext[]{
            new ExpressionContext(PointcutType.SET, fieldInfo, null),
            new ExpressionContext(PointcutType.GET, fieldInfo, null)
        };
View Full Code Here

    private FieldInfo getFieldInfo(final ClassInfo classInfo,
                                   final String className,
                                   final String fieldName,
                                   final String fieldDesc,
                                   final int joinPointHash) {
        FieldInfo fieldInfo = classInfo.getField(joinPointHash);
        if (fieldInfo == null) {
            throw new Error(
                    "field info metadata structure could not be build for field: "
                    + className
                    + '.'
View Full Code Here

            return true;
        }
        if (!(o instanceof FieldInfo)) {
            return false;
        }
        FieldInfo fieldInfo = (FieldInfo) o;
        if (!m_declaringTypeName.equals(fieldInfo.getDeclaringType().getName().toString())) {
            return false;
        }
        if (!m_member.name.equals(fieldInfo.getName().toString())) {
            return false;
        }
        ClassInfo fieldType = fieldInfo.getType();
        if (!m_type.getName().toString().equals(fieldType.getName().toString())) {
            return false;
        }
        return true;
    }
View Full Code Here

            return true;
        }
        if (!(o instanceof FieldInfo)) {
            return false;
        }
        FieldInfo fieldInfo = (FieldInfo) o;
        if (!m_declaringType.getName().toString().equals(fieldInfo.getDeclaringType().getName().toString())) {
            return false;
        }
        if (!m_member.getName().toString().equals(fieldInfo.getName().toString())) {
            return false;
        }
        ClassInfo fieldType = fieldInfo.getType();
        if (!m_type.getName().toString().equals(fieldType.getName().toString())) {
            return false;
        }
        return true;
    }
View Full Code Here

            case JoinPointType.FIELD_SET:
                Field field = AspectRegistry.getField(declaringClass, joinPointHash);
                FieldSignatureImpl fieldSignature = new FieldSignatureImpl(field.getDeclaringClass(), field);
                tuple.signature = fieldSignature;
                tuple.rtti = new FieldRttiImpl(fieldSignature, thisInstance, targetInstance);
                FieldInfo fieldInfo = JavaFieldInfo.getFieldInfo(field);
                withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ctx = new ExpressionContext(PointcutType.SET, fieldInfo, withinInfo);//AVAJ
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
View Full Code Here

            Type fieldType = Type.getType(fieldDesc);

            int joinPointHash = AsmHelper.calculateFieldHash(fieldName, fieldDesc);
            ClassInfo classInfo = AsmClassInfo.getClassInfo(className.replace('/', '.'), m_loader);
            FieldInfo fieldInfo = getFieldInfo(classInfo, className, fieldName, fieldDesc, joinPointHash);

            if (opcode == PUTFIELD || opcode == PUTSTATIC) {
                ExpressionContext ctx = new ExpressionContext(PointcutType.SET, fieldInfo, m_callerMethodInfo);

                if (fieldFilter(m_ctx.getDefinitions(), ctx, fieldInfo)) {
                    super.visitFieldInsn(opcode, className, fieldName, fieldDesc);
                } else {
                    m_ctx.markAsAdvised();
                    m_sequence++; // single place of incrementation, is used in multiple places

                    createPutFieldWrapperMethod((opcode==PUTSTATIC), fieldName, fieldDesc);

                    String joinPointClassName = JoinPointCompiler.getJoinPointClassName(
                            m_callerClassName,
                            JoinPointType.FIELD_SET,
                            joinPointHash
                    );

                    // load the caller instance (this), or null if in a static context
                    // note that callee instance [optional] and args are already on the stack
                    if (Modifier.isStatic(m_callerMethodInfo.getModifiers())) {
                        visitInsn(ACONST_NULL);
                    } else {
                        visitVarInsn(ALOAD, 0);
                    }

                    // add the call to the join point
                    super.visitMethodInsn(
                            INVOKESTATIC,
                            joinPointClassName,
                            INVOKE_METHOD_NAME,
                            TransformationUtil.getInvokeSignatureForFieldJoinPoints(
                                    fieldInfo.getModifiers(), fieldDesc, m_callerClassName, className
                            )
                    );
                    super.visitInsn(POP);// field is set by the JP

                    // emit the joinpoint
                    m_ctx.addEmittedInlinedJoinPoint(
                            new ContextImpl.EmittedInlinedJoinPoint(
                                    JoinPointType.FIELD_SET,
                                    m_callerClassName,
                                    m_callerMethodName,
                                    m_callerMethodDesc,
                                    m_callerMethodInfo.getModifiers(),
                                    className,
                                    fieldName,
                                    fieldDesc,
                                    fieldInfo.getModifiers(),
                                    m_sequence,
                                    joinPointHash,
                                    joinPointClassName
                            )
                    );
                }
            } else if (opcode == GETFIELD || opcode == GETSTATIC) {
                ExpressionContext ctx = new ExpressionContext(PointcutType.GET, fieldInfo, m_callerMethodInfo);

                if (fieldFilter(m_ctx.getDefinitions(), ctx, fieldInfo)) {
                    super.visitFieldInsn(opcode, className, fieldName, fieldDesc);
                } else {
                    m_ctx.markAsAdvised();
                    m_sequence++; // single place of incrementation, is used in multiple places

                    createGetFieldWrapperMethod((opcode==GETSTATIC), fieldName, fieldDesc);

                    String joinPointClassName = JoinPointCompiler.getJoinPointClassName(
                            m_callerClassName,
                            JoinPointType.FIELD_GET,
                            joinPointHash
                    );

                    // if static context pop the 'this' instance and load NULL
                    if (Modifier.isStatic(m_callerMethodInfo.getModifiers())) {
                        visitInsn(ACONST_NULL);
                    }

                    // no param to field, so pass a default value to the invoke method
                    AsmHelper.addDefaultValue(this, fieldType);

                    // if static context load NULL else 'this'
                    if (Modifier.isStatic(m_callerMethodInfo.getModifiers())) {
                        visitInsn(ACONST_NULL);
                    } else {
                        visitVarInsn(ALOAD, 0);
                    }

                    // add the call to the join point
                    super.visitMethodInsn(
                            INVOKESTATIC,
                            joinPointClassName,
                            INVOKE_METHOD_NAME,
                            TransformationUtil.getInvokeSignatureForFieldJoinPoints(
                                    fieldInfo.getModifiers(), fieldDesc, m_callerClassName, className
                            )
                    );
                    //super.visitInsn(POP);//pop the field value returned from jp.invoke for now

                    // emit the joinpoint
                    m_ctx.addEmittedInlinedJoinPoint(
                            new ContextImpl.EmittedInlinedJoinPoint(
                                    JoinPointType.FIELD_GET,
                                    m_callerClassName,
                                    m_callerMethodName,
                                    m_callerMethodDesc,
                                    m_callerMethodInfo.getModifiers(),
                                    className,
                                    fieldName,
                                    fieldDesc,
                                    fieldInfo.getModifiers(),
                                    m_sequence,
                                    joinPointHash,
                                    joinPointClassName
                            )
                    );
View Full Code Here

        private FieldInfo getFieldInfo(final ClassInfo classInfo,
                                       final String className,
                                       final String fieldName,
                                       final String fieldDesc,
                                       final int joinPointHash) {
            FieldInfo fieldInfo = classInfo.getField(joinPointHash);
            if (fieldInfo == null) {
                // lookup in the class hierarchy
                ClassInfo superClassInfo = classInfo.getSuperClass();
                while (superClassInfo != null) {
                    fieldInfo = superClassInfo.getField(joinPointHash);
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.reflect.FieldInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.