Java Code Examples for jdk.internal.org.objectweb.asm.ClassVisitor#visitMethod()

The following examples show how to use jdk.internal.org.objectweb.asm.ClassVisitor#visitMethod() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
static void addGetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = GETTER_PREFIX + memInfo.getJavaName();
    final String desc = getterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.getStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.getField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnValue();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example 2
static void addSetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = SETTER_PREFIX + memInfo.getJavaName();
    final String desc = setterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.loadLocal(1);
        mi.putStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.loadLocal(1);
        mi.putField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnVoid();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example 3
static void addGetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = GETTER_PREFIX + memInfo.getJavaName();
    final String desc = getterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.getStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.getField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnValue();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example 4
static void addSetter(final ClassVisitor cv, final String owner, final MemberInfo memInfo) {
    final int access = ACC_PUBLIC;
    final String name = SETTER_PREFIX + memInfo.getJavaName();
    final String desc = setterDesc(memInfo);
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    final MethodGenerator mi = new MethodGenerator(mv, access, name, desc);
    mi.visitCode();
    if (memInfo.isStatic() && memInfo.getKind() == Kind.PROPERTY) {
        mi.loadLocal(1);
        mi.putStatic(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    } else {
        mi.loadLocal(0);
        mi.loadLocal(1);
        mi.putField(owner, memInfo.getJavaName(), memInfo.getJavaDesc());
    }
    mi.returnVoid();
    mi.computeMaxs();
    mi.visitEnd();
}
 
Example 5
Source Project: hottub   File: MethodNode.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Makes the given class visitor visit this method.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (mv != null) {
        accept(mv);
    }
}
 
Example 6
/**
 * Makes the given class visitor visit this method.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (mv != null) {
        accept(mv);
    }
}
 
Example 7
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 8
/**
 * Makes the given class visitor visit this method.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (mv != null) {
        accept(mv);
    }
}
 
Example 9
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 10
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 11
/**
 * Makes the given class visitor visit this method.
 *
 * @param cv
 *            a class visitor.
 */
public void accept(final ClassVisitor cv) {
    String[] exceptions = new String[this.exceptions.size()];
    this.exceptions.toArray(exceptions);
    MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
            exceptions);
    if (mv != null) {
        accept(mv);
    }
}
 
Example 12
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 13
static MethodGenerator makeConstructor(final ClassVisitor cv) {
    final int access = 0;
    final String name = INIT;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 14
static MethodGenerator makeMethod(final ClassVisitor cv, final int access, final String name, final String desc) {
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 15
static MethodGenerator makeMethod(final ClassVisitor cv, final int access, final String name, final String desc) {
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 16
static MethodGenerator makeStaticInitializer(final ClassVisitor cv, final String name) {
    final int access =  ACC_PUBLIC | ACC_STATIC;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 17
static MethodGenerator makeMethod(final ClassVisitor cv, final int access, final String name, final String desc) {
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 18
static MethodGenerator makeStaticInitializer(final ClassVisitor cv, final String name) {
    final int access =  ACC_PUBLIC | ACC_STATIC;
    final String desc = DEFAULT_INIT_DESC;
    final MethodVisitor mv = cv.visitMethod(access, name, desc, null, null);
    return new MethodGenerator(mv, access, name, desc);
}
 
Example 19
/**
 * Creates a new {@link GeneratorAdapter}. <i>Subclasses must not use this
 * constructor</i>. Instead, they must use the
 * {@link #GeneratorAdapter(int, MethodVisitor, int, String, String)}
 * version.
 *
 * @param access
 *            access flags of the adapted method.
 * @param method
 *            the adapted method.
 * @param signature
 *            the signature of the adapted method (may be <tt>null</tt>).
 * @param exceptions
 *            the exceptions thrown by the adapted method (may be
 *            <tt>null</tt>).
 * @param cv
 *            the class visitor to which this adapter delegates calls.
 */
public GeneratorAdapter(final int access, final Method method,
        final String signature, final Type[] exceptions,
        final ClassVisitor cv) {
    this(access, method, cv
            .visitMethod(access, method.getName(), method.getDescriptor(),
                    signature, getInternalNames(exceptions)));
}
 
Example 20
/**
 * Creates a new {@link GeneratorAdapter}. <i>Subclasses must not use this
 * constructor</i>. Instead, they must use the
 * {@link #GeneratorAdapter(int, MethodVisitor, int, String, String)}
 * version.
 *
 * @param access access flags of the adapted method.
 * @param method the adapted method.
 * @param signature the signature of the adapted method (may be
 *        <tt>null</tt>).
 * @param exceptions the exceptions thrown by the adapted method (may be
 *        <tt>null</tt>).
 * @param cv the class visitor to which this adapter delegates calls.
 */
public GeneratorAdapter(
    final int access,
    final Method method,
    final String signature,
    final Type[] exceptions,
    final ClassVisitor cv)
{
    this(access, method, cv.visitMethod(access,
            method.getName(),
            method.getDescriptor(),
            signature,
            getInternalNames(exceptions)));
}