All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.evosuite.instrumentation.ExplicitExceptionHandler Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3.0 of the License, or
 * (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with EvoSuite. If not, see .
 */
/**
 * 
 */
package org.evosuite.instrumentation;

import org.evosuite.PackageInfo;
import org.evosuite.runtime.instrumentation.AnnotatedLabel;
import org.evosuite.testcase.execution.ExecutionTrace;
import org.evosuite.testcase.execution.ExecutionTracer;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * 

* ExplicitExceptionHandler class. *

* * @author gordon */ public class ExplicitExceptionHandler extends MethodVisitor { private final String fullMethodName; private final String className; private boolean inErrorBranch = false; int currentLine = 0; /** *

* Constructor for ExplicitExceptionHandler. *

* * @param mv * a {@link org.objectweb.asm.MethodVisitor} object. * @param className * a {@link java.lang.String} object. * @param methodName * a {@link java.lang.String} object. * @param desc * a {@link java.lang.String} object. */ public ExplicitExceptionHandler(MethodVisitor mv, String className, String methodName, String desc) { super(Opcodes.ASM5, mv); fullMethodName = methodName + desc; this.className = className; } /* (non-Javadoc) * @see org.objectweb.asm.MethodVisitor#visitLabel(org.objectweb.asm.Label) */ /** {@inheritDoc} */ @Override public void visitLabel(Label label) { if (label instanceof AnnotatedLabel) { AnnotatedLabel l = (AnnotatedLabel) label; if (Boolean.TRUE.equals(l.info)) { inErrorBranch = true; } else { inErrorBranch = false; } } super.visitLabel(label); } /* (non-Javadoc) * @see org.objectweb.asm.MethodVisitor#visitInsn(int) */ /** {@inheritDoc} */ @Override public void visitInsn(int opcode) { if (opcode == Opcodes.ATHROW && !inErrorBranch) { super.visitInsn(Opcodes.DUP); this.visitLdcInsn(className); this.visitLdcInsn(fullMethodName); mv.visitMethodInsn(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "exceptionThrown", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V", false); } super.visitInsn(opcode); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy