1 19 20 package edu.umd.cs.findbugs.ba.type; 21 22 import org.apache.bcel.Constants; 23 import org.apache.bcel.generic.ObjectType; 24 import org.apache.bcel.generic.Type; 25 26 27 32 public class ExceptionObjectType extends ObjectType implements Constants, ExtendedTypes { 33 36 private static final long serialVersionUID = 1L; 37 private ExceptionSet exceptionSet; 38 39 45 private ExceptionObjectType(String className, ExceptionSet exceptionSet) { 46 super(className); 47 this.exceptionSet = exceptionSet; 48 } 49 50 57 public static Type fromExceptionSet(ExceptionSet exceptionSet) throws ClassNotFoundException { 58 Type commonSupertype = exceptionSet.getCommonSupertype(); 59 if (commonSupertype.getType() != T_OBJECT) 60 return commonSupertype; 61 62 ObjectType exceptionSupertype = (ObjectType) commonSupertype; 63 return new ExceptionObjectType(exceptionSupertype.getClassName(), exceptionSet); 64 } 65 66 @Override 67 public byte getType() { 68 return T_EXCEPTION; 69 } 70 71 @Override 72 public int hashCode() { 73 return getSignature().hashCode(); 74 } 75 76 @Override 77 public boolean equals(Object o) { 78 if (o == null) return false; 79 if (o.getClass() != this.getClass()) return false; 80 81 ExceptionObjectType other = (ExceptionObjectType) o; 82 return getSignature().equals(other.getSignature()) 83 && exceptionSet.equals(other.exceptionSet); 84 } 85 86 91 public ExceptionSet getExceptionSet() { 92 return exceptionSet; 93 } 94 95 @Override 96 public String toString() { 97 StringBuffer buf = new StringBuffer (); 98 buf.append("<exception:"); 99 boolean first = true; 100 for (ExceptionSet.ThrownExceptionIterator i = exceptionSet.iterator(); i.hasNext();) { 101 if (first) 102 first = false; 103 else 104 buf.append(','); 105 buf.append(i.next().toString()); 106 } 107 buf.append(">"); 108 return buf.toString(); 109 } 110 } 111 112 | Popular Tags |