Search in sources :

Example 1 with TypeGenericVisitor

use of org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.TypeGenericVisitor in project felix by apache.

the class LegacyGenericBindingRegistry method createBindings.

@Override
protected List<Binding> createBindings(final Type type) {
    if (CUSTOM_HANDLER_PATTERN.matcher(type.getClassName()).matches()) {
        Binding binding = new Binding();
        binding.setAnnotationType(type);
        binding.setPredicate(alwaysTrue());
        binding.setFactory(new AnnotationVisitorFactory() {

            // Need to build a new Element instance for each created visitor
            public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
                if (context.getClassNode() != null) {
                    return new TypeGenericVisitor(context.getWorkbench(), Elements.buildElement(type));
                } else if (context.getFieldNode() != null) {
                    return new FieldGenericVisitor(context.getWorkbench(), Elements.buildElement(type), context.getFieldNode());
                } else if ((context.getMethodNode() != null) && (context.getParameterIndex() == BindingContext.NO_INDEX)) {
                    return new MethodGenericVisitor(context.getWorkbench(), Elements.buildElement(type), context.getMethodNode());
                } else {
                    // last case: method parameter annotation
                    return new ParameterGenericVisitor(context.getWorkbench(), Elements.buildElement(type), context.getMethodNode(), context.getParameterIndex());
                }
            }

            @Override
            public String toString() {
                return "LegacyGenericVisitorFactory";
            }
        });
        // Return the produced generic binding
        return singletonList(binding);
    }
    return emptyList();
}
Also used : TypeGenericVisitor(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.TypeGenericVisitor) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) FieldGenericVisitor(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.FieldGenericVisitor) MethodGenericVisitor(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.MethodGenericVisitor) ParameterGenericVisitor(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.ParameterGenericVisitor) BindingContext(org.apache.felix.ipojo.manipulator.spi.BindingContext) AnnotationVisitorFactory(org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory)

Aggregations

FieldGenericVisitor (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.FieldGenericVisitor)1 MethodGenericVisitor (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.MethodGenericVisitor)1 ParameterGenericVisitor (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.ParameterGenericVisitor)1 TypeGenericVisitor (org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.TypeGenericVisitor)1 AnnotationVisitorFactory (org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory)1 BindingContext (org.apache.felix.ipojo.manipulator.spi.BindingContext)1 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)1