Search in sources :

Example 6 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project flink by apache.

the class NestedMethodAnalyzer method invokeNestedMethod.

@SuppressWarnings("unchecked")
private TaggedValue invokeNestedMethod(List<? extends BasicValue> values, final MethodInsnNode methodInsn) throws AnalyzerException {
    final Object[] mn = findMethodNode(methodInsn.owner, methodInsn.name, methodInsn.desc);
    MethodNode methodNode = (MethodNode) mn[0];
    // recursion
    if (methodNode.name.equals(this.methodNode.name) && methodNode.desc.equals(this.methodNode.desc)) {
        // return the values that are present so far
        return mergeReturnValues(returnValues);
    }
    final NestedMethodAnalyzer nma = new NestedMethodAnalyzer(analyzer, (String) mn[1], (MethodNode) mn[0], (List<BasicValue>) values, remainingNesting - 1, topLevelMethod && isBridgeMethod());
    return nma.analyze();
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) UdfAnalyzerUtils.findMethodNode(org.apache.flink.api.java.sca.UdfAnalyzerUtils.findMethodNode) BasicValue(org.objectweb.asm.tree.analysis.BasicValue)

Example 7 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project felix by apache.

the class DefaultBindingModule method configure.

/**
 * Configure all the iPOJO's default annotation's bindings.
 */
public void configure() {
    // Class level annotations
    // --------------------------------
    bind(Component.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new ComponentVisitor(context.getWorkbench(), context.getReporter());
        }
    });
    bind(Handler.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new HandlerVisitor(context.getWorkbench(), context.getReporter());
        }
    });
    bind(Provides.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new ProvidesVisitor(context.getWorkbench());
        }
    });
    bind(HandlerDeclaration.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            Reporter reporter = context.getReporter();
            return new HandlerDeclarationVisitor(context.getWorkbench(), getFreshDocumentBuilder(reporter), reporter);
        }
    });
    bind(Instantiate.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new InstantiateVisitor(context.getWorkbench());
        }
    });
    // Field level annotations
    // --------------------------------
    bind(Requires.class).when(on(ElementType.FIELD)).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new RequiresVisitor(context.getWorkbench(), context.getFieldNode().name);
        }
    }).when(on(ElementType.PARAMETER)).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new ParameterBindVisitor(context.getWorkbench(), Action.BIND, context.getParameterIndex());
        }
    });
    bind(Controller.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            return new ControllerVisitor(context.getWorkbench(), context.getFieldNode().name);
        }
    });
    bind(ServiceProperty.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            String name = context.getFieldNode().name;
            ComponentWorkbench workbench = context.getWorkbench();
            if (!workbench.getIds().containsKey("provides")) {
                // The provides annotation is already computed.
                context.getReporter().warn("The component does not provide services, skip ServiceProperty for {}", name);
                return null;
            } else {
                // Get the provides element
                Element provides = workbench.getIds().get("provides");
                return new FieldPropertyVisitor(name, provides);
            }
        }
    });
    bind(ServiceController.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            String name = context.getFieldNode().name;
            ComponentWorkbench workbench = context.getWorkbench();
            if (!workbench.getIds().containsKey("provides")) {
                // The provides annotation is already computed.
                context.getReporter().warn("The component does not provide services, skip @ServiceController for {}", name);
                return null;
            } else {
                // Get the provides element
                Element provides = workbench.getIds().get("provides");
                return new ServiceControllerVisitor(name, provides);
            }
        }
    });
    bind(Property.class).when(on(ElementType.FIELD)).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            ComponentWorkbench workbench = context.getWorkbench();
            Element properties = Elements.getPropertiesElement(workbench);
            String name = context.getFieldNode().name;
            return new FieldPropertyVisitor(name, properties);
        }
    }).when(on(ElementType.METHOD)).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            ComponentWorkbench workbench = context.getWorkbench();
            // @Property on method parameter
            Element properties = Elements.getPropertiesElement(workbench);
            String name = context.getMethodNode().name;
            return new MethodPropertyVisitor(properties, name);
        }
    }).when(on(ElementType.PARAMETER)).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            ComponentWorkbench workbench = context.getWorkbench();
            // @Property on method parameter
            Element properties = Elements.getPropertiesElement(workbench);
            MethodNode method = context.getMethodNode();
            return new ParameterPropertyVisitor(properties, method, context.getParameterIndex());
        }
    });
    bind(Validate.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new LifecycleVisitor(context.getWorkbench(), Names.computeEffectiveMethodName(node.name), LifecycleVisitor.Transition.VALIDATE);
        }
    });
    bind(Invalidate.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new LifecycleVisitor(context.getWorkbench(), Names.computeEffectiveMethodName(node.name), LifecycleVisitor.Transition.INVALIDATE);
        }
    });
    bind(Updated.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new UpdatedVisitor(context.getWorkbench(), Names.computeEffectiveMethodName(node.name));
        }
    });
    bind(Bind.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new MethodBindVisitor(context.getWorkbench(), Action.BIND, node, context.getReporter());
        }
    });
    bind(Unbind.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new MethodBindVisitor(context.getWorkbench(), Action.UNBIND, node, context.getReporter());
        }
    });
    bind(Modified.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new MethodBindVisitor(context.getWorkbench(), Action.MODIFIED, node, context.getReporter());
        }
    });
    bind(PostRegistration.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new PostRegistrationVisitor(context.getWorkbench(), node.name);
        }
    });
    bind(PostUnregistration.class).to(new AnnotationVisitorFactory() {

        public AnnotationVisitor newAnnotationVisitor(BindingContext context) {
            MethodNode node = context.getMethodNode();
            return new PostUnregistrationVisitor(context.getWorkbench(), node.name);
        }
    });
    bind(Context.class).to(new GenericVisitorFactory("context", ""));
}
Also used : GenericVisitorFactory(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.generic.GenericVisitorFactory) ParameterBindVisitor(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.bind.ParameterBindVisitor) Element(org.apache.felix.ipojo.metadata.Element) AnnotationVisitorFactory(org.apache.felix.ipojo.manipulator.spi.AnnotationVisitorFactory) MethodNode(org.objectweb.asm.tree.MethodNode) BindingContext(org.apache.felix.ipojo.manipulator.spi.BindingContext) Reporter(org.apache.felix.ipojo.manipulator.Reporter) BindingContext(org.apache.felix.ipojo.manipulator.spi.BindingContext) MethodBindVisitor(org.apache.felix.ipojo.manipulator.metadata.annotation.visitor.bind.MethodBindVisitor) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) ComponentWorkbench(org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench)

Example 8 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project felix by apache.

the class MethodBindVisitorTestCase method testIdentifierProvided.

public void testIdentifierProvided() throws Exception {
    Reporter reporter = mock(Reporter.class);
    ComponentWorkbench workbench = new ComponentWorkbench(null, type());
    MethodNode node = new MethodNode();
    node.name = "myMethod";
    MethodBindVisitor visitor = new MethodBindVisitor(workbench, Action.BIND, node, reporter);
    visitor.visit("id", "my-identifier");
    visitor.visitEnd();
    assertNotNull(workbench.getIds().get("my-identifier"));
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) Reporter(org.apache.felix.ipojo.manipulator.Reporter) ComponentWorkbench(org.apache.felix.ipojo.manipulator.metadata.annotation.ComponentWorkbench)

Example 9 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project felix by apache.

the class NamesTestCase method testSpecificationRecognized.

public void testSpecificationRecognized() throws Exception {
    MethodNode node = new MethodNode();
    node.name = "handle";
    node.desc = "(Lmy/Service;)V";
    assertEquals("my.Service", getMethodIdentifier(node));
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode)

Example 10 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project felix by apache.

the class NamesTestCase method testNoPatternRecognized.

public void testNoPatternRecognized() throws Exception {
    MethodNode node = new MethodNode();
    node.name = "notify";
    node.desc = "()V";
    assertNull(getMethodIdentifier(node));
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode)

Aggregations

MethodNode (org.objectweb.asm.tree.MethodNode)322 ClassNode (org.objectweb.asm.tree.ClassNode)123 Test (org.junit.Test)94 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)59 ClassReader (org.objectweb.asm.ClassReader)57 InsnList (org.objectweb.asm.tree.InsnList)49 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)47 Label (org.objectweb.asm.Label)44 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)41 InsnNode (org.objectweb.asm.tree.InsnNode)34 ClassWriter (org.objectweb.asm.ClassWriter)26 FieldNode (org.objectweb.asm.tree.FieldNode)26 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 ArrayList (java.util.ArrayList)24 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)24 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)21 LabelNode (org.objectweb.asm.tree.LabelNode)19 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)19 List (java.util.List)17 Type (org.objectweb.asm.Type)17