Search in sources :

Example 1 with FieldVisitor

use of act.asm.FieldVisitor in project actframework by actframework.

the class ConfigurationByteCodeScanner method byteCodeVisitor.

@Override
public ByteCodeVisitor byteCodeVisitor() {
    return new ByteCodeVisitor() {

        @Override
        public FieldVisitor visitField(int access, final String name, String desc, String signature, Object value) {
            FieldVisitor fv = super.visitField(access, name, desc, signature, value);
            boolean isStatic = AsmTypes.isStatic(access);
            if (!isStatic) {
                return fv;
            }
            final String fieldName = name;
            return new FieldVisitor(ASM5, fv) {

                @Override
                public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
                    AnnotationVisitor av = super.visitAnnotation(desc, visible);
                    if (S.eq(CONF_DESC, desc)) {
                        return new AnnotationVisitor(ASM5, av) {

                            @Override
                            public void visit(String name, Object value) {
                                staticConfigurationFields.put(fieldName, S.string(value));
                                super.visit(name, value);
                            }
                        };
                    }
                    return av;
                }
            };
        }
    };
}
Also used : ByteCodeVisitor(act.util.ByteCodeVisitor) AnnotationVisitor(act.asm.AnnotationVisitor) FieldVisitor(act.asm.FieldVisitor)

Example 2 with FieldVisitor

use of act.asm.FieldVisitor in project act-ebean by actframework.

the class TimestampAuditorEnhancer method visitField.

@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    FieldVisitor fv = super.visitField(access, name, desc, signature, value);
    if (null == createdAt && null == lastModifiedAt) {
        return fv;
    }
    final boolean isCreatedAt = name.equals(createdAt);
    final boolean isLastModified = !isCreatedAt && name.equals(lastModifiedAt);
    if (!isCreatedAt && !isLastModified) {
        return fv;
    }
    return new FieldVisitor(ASM5, fv) {

        @Override
        public void visitEnd() {
            AnnotationVisitor av;
            if (isCreatedAt) {
                av = fv.visitAnnotation("Lcom/avaje/ebean/annotation/WhenCreated;", true);
            } else {
                av = fv.visitAnnotation("Lcom/avaje/ebean/annotation/WhenModified;", true);
            }
            av.visitEnd();
            super.visitEnd();
        }
    };
}
Also used : AnnotationVisitor(act.asm.AnnotationVisitor) FieldVisitor(act.asm.FieldVisitor)

Aggregations

AnnotationVisitor (act.asm.AnnotationVisitor)2 FieldVisitor (act.asm.FieldVisitor)2 ByteCodeVisitor (act.util.ByteCodeVisitor)1