bug_regression_jdk7.javassist.asm.BytecodeVerifyTestClassVisitor.java Source code

Java tutorial

Introduction

Here is the source code for bug_regression_jdk7.javassist.asm.BytecodeVerifyTestClassVisitor.java

Source

/*
 * Copyright 2016 Naver Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package bug_regression_jdk7.javassist.asm;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Woonduk Kang(emeroad)
 */
public class BytecodeVerifyTestClassVisitor extends ClassVisitor {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private String name;

    public BytecodeVerifyTestClassVisitor(final ClassVisitor cv) {
        super(Opcodes.ASM5, cv);
    }

    @Override
    public void visit(final int version, final int access, final String name, final String signature,
            final String superName, final String[] interfaces) {
        this.name = name;
        super.visit(version, access, name, signature, superName, interfaces);
    }

    @Override
    public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature,
            final String[] exceptions) {

        MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
        logger.debug("mv:{}", mv);
        logger.debug("name:{}", name);
        logger.debug("desc:{}", desc);
        logger.debug("signature:{}", signature);
        if (name.contains("bytecodeVerifyError")) {
            return new AddIntVariableMethodAdapter(mv, Opcodes.ACC_PUBLIC, name, "()V");
        }
        return mv;
    }
}