1 19 package gcc.util; 20 21 import java.lang.reflect.*; 22 import java.util.*; 23 24 public class ExceptionList extends ArrayList 25 { 26 public ExceptionList() 27 { 28 } 29 30 public ExceptionList(Constructor template) 31 { 32 Class[] types = template.getExceptionTypes(); 33 add(types); 34 } 35 36 public ExceptionList(Method template) 37 { 38 Class[] types = template.getExceptionTypes(); 39 add(types); 40 } 41 42 public ExceptionList(Class[] types) 43 { 44 add(types); 45 } 46 47 public void add(Class[] types) 48 { 49 int n = types.length; 50 for (int i = 0; i < n; i++) 51 { 52 Class type = types[i]; 53 if (ExceptionUtil.isUserException(type)) 54 { 55 add(type); 56 } 57 } 58 } 59 60 public ExceptionList add(String type) 61 { 62 super.add(type); 63 return this; 64 } 65 66 public ExceptionList add(Class type) 67 { 68 return add(JavaType.getName(type)); 69 } 70 71 public String toString() 72 { 73 if (size() == 0) 74 { 75 return ""; 76 } 77 StringBuffer sb = new StringBuffer(" throws "); 78 int comma = 0; 79 for (Iterator i = iterator(); i.hasNext(); comma++) 80 { 81 String type = (String)i.next(); 82 if (comma > 0) 83 { 84 sb.append(", "); 85 } 86 sb.append(type); 87 } 88 return sb.toString(); 89 } 90 } 91 | Popular Tags |