Search in sources :

Example 1 with CommandMethodMetaInfo

use of act.cli.meta.CommandMethodMetaInfo 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)

Aggregations

AnnotationVisitor (act.asm.AnnotationVisitor)1 MethodVisitor (act.asm.MethodVisitor)1 CommandMethodMetaInfo (act.cli.meta.CommandMethodMetaInfo)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1