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 */
023package com.jcoverage.util;
024
025
026import org.apache.bcel.generic.ArrayType;
027import org.apache.bcel.generic.BasicType;
028import org.apache.bcel.generic.ObjectType;
029import org.apache.bcel.generic.Type;
030
031public class TypeHelper {
032  public static Type getType(Class cl) {
033    if(cl.equals(boolean.class)) {
034      return Type.BOOLEAN;
035    } else if(cl.equals(char.class)) {
036      return Type.CHAR;
037    } else if(cl.equals(byte.class)) {
038      return Type.BYTE;
039    } else if(cl.equals(short.class)) {
040      return Type.SHORT;
041    } else if(cl.equals(int.class)) {
042      return Type.INT;
043    } else if(cl.equals(long.class)) {
044      return Type.LONG;
045    } else if(cl.equals(float.class)) {
046      return Type.FLOAT;
047    } else if(cl.equals(double.class)) {
048      return Type.DOUBLE;
049    } else if(cl.isArray()) {
050      return new ArrayType(getType(cl.getComponentType()),1);
051    } else if(cl.equals(void.class)) {
052      return Type.VOID;
053    } else {
054      return new ObjectType(cl.getName());
055    }
056  }
057
058  public static Type[] getTypes(Class[] cls) {
059    Type[] types=new Type[cls.length];
060    for(int i=0;i<cls.length;i++) {
061      types[i]=getType(cls[i]);
062    }
063    return types;
064  }
065}