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() . 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
Source File: ClassGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: ClassGenerator.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: ClassGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: ClassGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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 File: ClassGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 6
Source File: MethodNode.java    From hottub with 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 7
Source File: ClassGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: MethodNode.java    From jdk8u-jdk with 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 9
Source File: ClassGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ClassGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: MethodNode.java    From openjdk-jdk8u-backup with 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 12
Source File: ClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: MethodNode.java    From TencentKona-8 with 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 14
Source File: ClassGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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
Source File: ClassGenerator.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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 16
Source File: ClassGenerator.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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 17
Source File: ClassGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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 18
Source File: ClassGenerator.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
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 19
Source File: GeneratorAdapter.java    From nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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
Source File: GeneratorAdapter.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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)));
}