Search in sources :

Example 21 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.

the class RegexSearch method search.

@Override
public void search(final ClassNode node, final SearchResultNotifier srn, boolean exact) {
    final Iterator<MethodNode> methods = node.methods.iterator();
    final String srchText = searchText.getText();
    if (srchText.isEmpty())
        return;
    while (methods.hasNext()) {
        final MethodNode method = methods.next();
        if (regexFinder == null) {
            regexFinder = new RegexInsnFinder(node, method);
        } else {
            regexFinder.setMethod(node, method);
        }
        if (regexFinder.find(srchText).length > 0) {
            String desc2 = method.desc;
            try {
                desc2 = Type.getType(method.desc).toString();
                if (desc2 == null || desc2.equals("null"))
                    desc2 = method.desc;
            } catch (java.lang.ArrayIndexOutOfBoundsException e) {
            }
            srn.notifyOfResult(node.name + "." + method.name + desc2);
        }
    }
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode)

Example 22 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project bytecode-viewer by Konloch.

the class CheckClassAdapter method verify.

/**
     * Checks a given class.
     * 
     * @param cr
     *            a <code>ClassReader</code> that contains bytecode for the
     *            analysis.
     * @param loader
     *            a <code>ClassLoader</code> which will be used to load
     *            referenced classes. This is useful if you are verifiying
     *            multiple interdependent classes.
     * @param dump
     *            true if bytecode should be printed out not only when errors
     *            are found.
     * @param pw
     *            write where results going to be printed
     */
public static void verify(final ClassReader cr, final ClassLoader loader, final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
    Type syperType = cn.superName == null ? null : Type.getObjectType(cn.superName);
    List<MethodNode> methods = cn.methods;
    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext(); ) {
        interfaces.add(Type.getObjectType(i.next()));
    }
    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name), syperType, interfaces, (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) SimpleVerifier(org.objectweb.asm.tree.analysis.SimpleVerifier) Analyzer(org.objectweb.asm.tree.analysis.Analyzer) BasicValue(org.objectweb.asm.tree.analysis.BasicValue) MethodNode(org.objectweb.asm.tree.MethodNode)

Example 23 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project jacoco by jacoco.

the class GroovyGeneratedFilterTest method testGroovyGeneratedAnnotation.

@Test
public void testGroovyGeneratedAnnotation() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Lgroovy/transform/Generated;", true);
    m.visitInsn(Opcodes.ICONST_0);
    m.visitInsn(Opcodes.IRETURN);
    filter.filter("Foo", "java/lang/Object", m, this);
    assertEquals(m.instructions.getFirst(), fromInclusive);
    assertEquals(m.instructions.getLast(), toInclusive);
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) Test(org.junit.Test)

Example 24 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project jacoco by jacoco.

the class GroovyGeneratedFilterTest method testOtherAnnotation.

@Test
public void testOtherAnnotation() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Lother/Annotation;", true);
    m.visitInsn(Opcodes.ICONST_0);
    m.visitInsn(Opcodes.IRETURN);
    filter.filter("Foo", "java/lang/Object", m, this);
    assertNull(fromInclusive);
    assertNull(toInclusive);
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) Test(org.junit.Test)

Example 25 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project jacoco by jacoco.

the class LombokGeneratedFilterTest method testLombokGeneratedAnnotation.

@Test
public void testLombokGeneratedAnnotation() {
    final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, "hashCode", "()I", null, null);
    m.visitAnnotation("Llombok/Generated;", false);
    m.visitInsn(Opcodes.ICONST_0);
    m.visitInsn(Opcodes.IRETURN);
    filter.filter("Foo", "java/lang/Object", m, this);
    assertEquals(m.instructions.getFirst(), fromInclusive);
    assertEquals(m.instructions.getLast(), toInclusive);
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) Test(org.junit.Test)

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