Search in sources :

Example 1 with AnnotationVisitor

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

the class ModelBaseEnhancer method addAnnotation.

private void addAnnotation() {
    AnnotationVisitor av = visitAnnotation(Type.getType(MappedSuperclass.class).getDescriptor(), true);
    av.visitEnd();
}
Also used : AnnotationVisitor(act.asm.AnnotationVisitor)

Example 2 with AnnotationVisitor

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

the class MetricContextScanner method byteCodeVisitor.

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

        private String className;

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            className = Type.getObjectType(name).getClassName();
        }

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

                    @Override
                    public void visit(String name, Object value) {
                        super.visit(name, value);
                        if ("value".equals(name)) {
                            repo.registerMetricContext(className, value.toString());
                        }
                    }
                };
            }
            return av;
        }
    };
}
Also used : ByteCodeVisitor(act.util.ByteCodeVisitor) AnnotationVisitor(act.asm.AnnotationVisitor)

Example 3 with AnnotationVisitor

use of act.asm.AnnotationVisitor 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 4 with AnnotationVisitor

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

the class CommanderEnhancer method visitMethod.

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    if (null == metaInfo || isConstructor(name)) {
        return mv;
    }
    final CommandMethodMetaInfo methodInfo = metaInfo.command(name);
    if (null == methodInfo) {
        return mv;
    }
    if (isPublic(access) && !isConstructor(name)) {
        return new MethodVisitor(ASM5, mv) {

            private Set<Integer> skipNaming = new HashSet<Integer>();

            @Override
            public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
                if ("Ljavax/inject/Named;".equals(desc)) {
                    skipNaming.add(parameter);
                }
                return super.visitParameterAnnotation(parameter, desc, visible);
            }

            @Override
            public void visitEnd() {
                int sz = methodInfo.paramCount();
                for (int i = 0; i < sz; ++i) {
                    if (!skipNaming.contains(i)) {
                        String name = methodInfo.param(i).name();
                        AnnotationVisitor av = mv.visitParameterAnnotation(i, "Ljavax/inject/Named;", true);
                        av.visit("value", name);
                    }
                }
                super.visitEnd();
            }
        };
    }
    return mv;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) CommandMethodMetaInfo(act.cli.meta.CommandMethodMetaInfo) AnnotationVisitor(act.asm.AnnotationVisitor) MethodVisitor(act.asm.MethodVisitor)

Example 5 with AnnotationVisitor

use of act.asm.AnnotationVisitor 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)8 ByteCodeVisitor (act.util.ByteCodeVisitor)3 FieldVisitor (act.asm.FieldVisitor)2 MethodVisitor (act.asm.MethodVisitor)2 Type (act.asm.Type)1 CommandMethodMetaInfo (act.cli.meta.CommandMethodMetaInfo)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 org.osgl.$ (org.osgl.$)1 C (org.osgl.util.C)1