001    /**
002     * www.jcoverage.com
003     * Copyright (C)2003 jcoverage ltd.
004     *
005     * This file is part of jcoverage.
006     *
007     * jcoverage is free software; you can redistribute it and/or modify
008     * it under the terms of the GNU General Public License as published
009     * by the Free Software Foundation; either version 2 of the License,
010     * or (at your option) any later version.
011     *
012     * jcoverage is distributed in the hope that it will be useful, but
013     * WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     * General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with jcoverage; if not, write to the Free Software
019     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020     * USA
021     *
022     */
023    package com.jcoverage.util;
024    
025    import org.apache.bcel.generic.InstructionHandle;
026    import org.apache.bcel.generic.LineNumberGen;
027    import org.apache.bcel.generic.MethodGen;
028    import org.apache.bcel.generic.Type;
029    
030    public class MethodGenHelper {
031      final MethodGen mg;
032    
033      public MethodGenHelper(MethodGen mg) {
034        this.mg=mg;
035      }
036    
037      public MethodGen getMethodGen() {
038        return mg;
039      }
040    
041      public boolean hasLineNumber(InstructionHandle handle) {
042        LineNumberGen[] lineNumberGen=mg.getLineNumbers();
043        for(int i=0;i<lineNumberGen.length;i++) {
044          if(lineNumberGen[i].containsTarget(handle)) {
045            return true;
046          }
047        }
048        return false;
049      }
050    
051      public int getLineNumber(InstructionHandle handle) {
052        LineNumberGen[] lineNumberGen=mg.getLineNumbers();
053        for(int i=0;i<lineNumberGen.length;i++) {
054          if(lineNumberGen[i].containsTarget(handle)) {
055            return lineNumberGen[i].getSourceLine();
056          }
057        }
058        return 0;
059      }
060    
061      public boolean isVoidReturningMethod() {
062        return mg.getReturnType().equals(Type.VOID);
063      }
064    }