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 public class ClassHelper { 026 public static String getPackageName(Class cl) { 027 return getPackageName(cl.getName()); 028 } 029 030 public static String getPackageName(String cl) { 031 int lastDot=cl.lastIndexOf('.'); 032 if(lastDot==-1) { 033 return ""; 034 } 035 return cl.substring(0,lastDot); 036 } 037 038 public static String getBaseName(String cl) { 039 int lastDot=cl.lastIndexOf('.'); 040 if(lastDot==-1) { 041 return cl; 042 } else { 043 return cl.substring(lastDot+1); 044 } 045 } 046 047 public static String getBaseName(Class cl) { 048 return getBaseName(cl.getName()); 049 } 050 051 public static Class getPrimitiveWrapper(Class cl) { 052 if(cl.isPrimitive()) { 053 if(cl.equals(boolean.class)) { 054 return Boolean.class; 055 } else if(cl.equals(char.class)) { 056 return Character.class; 057 } else if(cl.equals(byte.class)) { 058 return Byte.class; 059 } else if(cl.equals(short.class)) { 060 return Short.class; 061 } else if(cl.equals(int.class)) { 062 return Integer.class; 063 } else if(cl.equals(long.class)) { 064 return Long.class; 065 } else if(cl.equals(float.class)) { 066 return Float.class; 067 } else if(cl.equals(double.class)) { 068 return Double.class; 069 } 070 } 071 072 throw new IllegalArgumentException(cl.getName()); 073 } 074 }