001/*
002 * Cobertura - http://cobertura.sourceforge.net/
003 *
004 * Copyright (C) 2011 Piotr Tabor
005 *
006 * Note: This file is dual licensed under the GPL and the Apache
007 * Source License (so that it can be used from both the main
008 * Cobertura classes and the ant tasks).
009 *
010 * Cobertura is free software; you can redistribute it and/or modify
011 * it under the terms of the GNU General Public License as published
012 * by the Free Software Foundation; either version 2 of the License,
013 * or (at your option) any later version.
014 *
015 * Cobertura is distributed in the hope that it will be useful, but
016 * WITHOUT ANY WARRANTY; without even the implied warranty of
017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018 * General Public License for more details.
019 *
020 * You should have received a copy of the GNU General Public License
021 * along with Cobertura; if not, write to the Free Software
022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
023 * USA
024 */
025
026package net.sourceforge.cobertura.instrument.pass2;
027
028import net.sourceforge.cobertura.instrument.TouchPointListener;
029import net.sourceforge.cobertura.instrument.tp.ClassMap;
030
031import org.objectweb.asm.Label;
032import org.objectweb.asm.MethodVisitor;
033
034/**
035 * Analyzes given method and applies information about all found important places into {@link #classmap}.
036 * 
037 * @author piotr.tabor@gmail.com
038 */
039public class BuildClassMapTouchPointListener implements TouchPointListener{
040        private final ClassMap classmap;
041        
042        public BuildClassMapTouchPointListener(ClassMap classMap) {
043                this.classmap=classMap;
044        }
045        
046        public void beforeJump(int eventId,Label label, int currentLine,
047                        MethodVisitor nextMethodVisitor) {
048                classmap.registerNewJump(eventId,currentLine,label);            
049        }
050
051        public void beforeLabel(int eventId,Label label, int currentLine, MethodVisitor mv) {
052                classmap.registerNewLabel(eventId,currentLine, label);          
053        }       
054
055        public void afterLineNumber(int eventId,Label label, int currentLine,MethodVisitor nextMethodVisitor,String methodName, String methodSignature) {
056                classmap.registerLineNumber(eventId,currentLine,label,methodName,methodSignature);
057        }
058        
059        public void beforeSwitch(int eventId, Label def, Label[] labels, int currentLine, MethodVisitor mv, String conditionType) {
060                classmap.registerSwitch(eventId, currentLine, def, labels, conditionType);
061        }
062
063        public void ignoreLine(int eventId,int currentLine) {
064                classmap.unregisterLine(eventId,currentLine);           
065        }
066        
067// --------------- Not interesting events for analysis ---------------------------
068        public void afterJump(int eventId,Label label, int currentLine, MethodVisitor nextMethodVisitor) {}     
069        public void afterLabel(int eventId,Label label, int currentLine, MethodVisitor mv) {}   
070        public void afterMethodStart(MethodVisitor nextMethodVisitor) {};
071}