1 19 20 package edu.umd.cs.findbugs.ba.type; 21 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 25 import org.apache.bcel.classfile.ClassFormatException; 26 import org.apache.bcel.generic.ReferenceType; 27 import org.apache.bcel.generic.Type; 28 29 import edu.umd.cs.findbugs.ba.AnalysisContext; 30 import edu.umd.cs.findbugs.ba.Hierarchy; 31 32 40 public class FieldStoreType { 41 private HashSet <String > typeSignatureSet; 42 private ReferenceType loadType; 43 44 public FieldStoreType() { 45 this.typeSignatureSet = new HashSet <String >(); 46 } 47 48 public void addTypeSignature(String signature) { 50 loadType = null; 51 typeSignatureSet.add(signature); 52 } 53 54 public Iterator <String > signatureIterator() { 55 return typeSignatureSet.iterator(); 56 } 57 58 public ReferenceType getLoadType(ReferenceType fieldType) { 59 if (loadType == null) { 60 computeLoadType(fieldType); 61 } 62 return loadType; 63 } 64 65 private void computeLoadType(ReferenceType fieldType) { 66 ReferenceType leastSupertype = null; 67 68 for (Iterator <String > i = signatureIterator(); i.hasNext();) { 69 try { 70 String signature = i.next(); 71 Type type = Type.getType(signature); 72 if (!(type instanceof ReferenceType)) 73 continue; 74 75 leastSupertype = (leastSupertype == null) 78 ? (ReferenceType) type 79 : leastSupertype.getFirstCommonSuperclass((ReferenceType) type); 80 81 } catch (ClassFormatException e) { 82 } catch (ClassNotFoundException e) { 84 AnalysisContext.reportMissingClass(e); 85 } 86 } 87 88 try { 89 if (leastSupertype != null && Hierarchy.isSubtype(leastSupertype, fieldType)) 90 loadType = leastSupertype; 91 } catch (ClassNotFoundException e) { 92 AnalysisContext.reportMissingClass(e); 93 } 94 95 if (loadType == null) 96 loadType = fieldType; 97 } 98 } 99 | Popular Tags |