Search in sources :

Example 6 with AnnotationVisitor

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

the class SingletonEnhancer method addAnnotationIfNeeded.

private void addAnnotationIfNeeded() {
    if (shouldAddAnnotation) {
        AnnotationVisitor av = super.visitAnnotation(Type.getType(Singleton.class).getDescriptor(), true);
        av.visitEnd();
    }
}
Also used : AnnotationVisitor(act.asm.AnnotationVisitor)

Example 7 with AnnotationVisitor

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

the class GenieFactoryFinder method byteCodeVisitor.

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

        private boolean isPublic;

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            isPublic = AsmTypes.isPublic(access);
            isModule = Module.class.getName().equals(Type.getObjectType(superName).getClassName());
        }

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            return !isPublic || isModule || isFactory ? mv : new MethodVisitor(ASM5, mv) {

                @Override
                public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
                    Type annoType = Type.getType(desc);
                    if (AsmTypes.PROVIDES.asmType().equals(annoType)) {
                        isFactory = true;
                    }
                    return super.visitAnnotation(desc, visible);
                }
            };
        }
    };
}
Also used : Type(act.asm.Type) ByteCodeVisitor(act.util.ByteCodeVisitor) AnnotationVisitor(act.asm.AnnotationVisitor) MethodVisitor(act.asm.MethodVisitor)

Example 8 with AnnotationVisitor

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

the class ClassDetector method of.

public static ClassDetector of(final ClassFilter... filters) {
    E.illegalArgumentIf(filters.length == 0);
    if (filters.length == 1) {
        return new FilteredClassDetector(filters[0]);
    }
    return new ClassDetector() {

        C.List<ClassDetector> detectors = C.listOf(filters).map(new $.F1<ClassFilter, ClassDetector>() {

            @Override
            public ClassDetector apply(ClassFilter classFilter) throws NotAppliedException, $.Break {
                return new FilteredClassDetector(classFilter);
            }
        });

        private List<ClassDetector> matches = new ArrayList<>();

        @Override
        public int hashCode() {
            return $.hc(detectors);
        }

        @Override
        public boolean equals(Object obj) {
            return obj == this;
        }

        @Override
        public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
            super.visit(version, access, name, signature, superName, interfaces);
            for (ClassDetector detector : detectors) {
                detector.visit(version, access, name, signature, superName, interfaces);
                if (detector.found()) {
                    matches.add(detector);
                }
            }
        }

        @Override
        public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
            AnnotationVisitor av = super.visitAnnotation(desc, visible);
            if (matches.size() == detectors.size() || !isExtendsAnnotation(desc)) {
                return av;
            }
            final C.List<ClassDetector> unmatched = detectors.without(matches);
            return new AnnotationVisitor(ASM5, av) {

                @Override
                public void visit(String name, Object value) {
                    for (ClassDetector detector : unmatched) {
                        AnnotationVisitor av0 = detector.visitAnnotation(desc, visible);
                        av0.visit(name, value);
                        if (detector.found()) {
                            matches.add(detector);
                        }
                    }
                    super.visit(name, value);
                }
            };
        }

        @Override
        public boolean found() {
            return !matches.isEmpty();
        }
    };
}
Also used : C(org.osgl.util.C) org.osgl.$(org.osgl.$) AnnotationVisitor(act.asm.AnnotationVisitor) ArrayList(java.util.ArrayList) List(java.util.List)

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