001 /* 002 * Cobertura - http://cobertura.sourceforge.net/ 003 * 004 * Copyright (C) 2003 jcoverage ltd. 005 * Copyright (C) 2005 Mark Doliner <thekingant@users.sourceforge.net> 006 * 007 * Cobertura 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 * Cobertura 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 Cobertura; 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 net.sourceforge.cobertura.util; 024 025 public abstract class ClassHelper 026 { 027 028 public static String getBaseName(Class cl) 029 { 030 return getBaseName(cl.getName()); 031 } 032 033 public static String getBaseName(String cl) 034 { 035 int lastDot = cl.lastIndexOf('.'); 036 if (lastDot == -1) 037 { 038 return cl; 039 } 040 return cl.substring(lastDot + 1); 041 } 042 043 public static String getPackageName(Class cl) 044 { 045 return getPackageName(cl.getName()); 046 } 047 048 public static String getPackageName(String cl) 049 { 050 int lastDot = cl.lastIndexOf('.'); 051 if (lastDot == -1) 052 { 053 return ""; 054 } 055 return cl.substring(0, lastDot); 056 } 057 058 public static Class getPrimitiveWrapper(Class cl) 059 { 060 if (cl.isPrimitive()) 061 { 062 if (cl.equals(boolean.class)) 063 { 064 return Boolean.class; 065 } 066 else if (cl.equals(char.class)) 067 { 068 return Character.class; 069 } 070 else if (cl.equals(byte.class)) 071 { 072 return Byte.class; 073 } 074 else if (cl.equals(short.class)) 075 { 076 return Short.class; 077 } 078 else if (cl.equals(int.class)) 079 { 080 return Integer.class; 081 } 082 else if (cl.equals(long.class)) 083 { 084 return Long.class; 085 } 086 else if (cl.equals(float.class)) 087 { 088 return Float.class; 089 } 090 else if (cl.equals(double.class)) 091 { 092 return Double.class; 093 } 094 } 095 096 throw new IllegalArgumentException(cl.getName()); 097 } 098 }