1 19 20 package edu.umd.cs.findbugs.detect; 21 22 import org.apache.bcel.generic.ConstantPoolGen; 23 import org.apache.bcel.generic.Instruction; 24 import org.apache.bcel.generic.InvokeInstruction; 25 import org.apache.bcel.generic.ObjectType; 26 27 import edu.umd.cs.findbugs.ba.Hierarchy; 28 import edu.umd.cs.findbugs.ba.Location; 29 import edu.umd.cs.findbugs.ba.ObjectTypeFactory; 30 import edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback; 31 32 41 public class AnyMethodReturnValueStreamFactory implements StreamFactory { 42 private ObjectType baseClassType; 43 private String bugType; 44 45 public AnyMethodReturnValueStreamFactory(String streamBase) { 46 this.baseClassType = ObjectTypeFactory.getInstance(streamBase); 47 this.bugType = null; 48 } 49 50 public AnyMethodReturnValueStreamFactory setBugType(String bugType) { 51 this.bugType = bugType; 52 return this; 53 } 54 55 public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, 56 RepositoryLookupFailureCallback lookupFailureCallback) { 57 58 Instruction ins = location.getHandle().getInstruction(); 59 60 try { 61 if (ins instanceof InvokeInstruction) { 62 if (!Hierarchy.isSubtype(type, baseClassType)) 63 return null; 64 65 Stream stream = new Stream(location, type.getClassName(), baseClassType.getClassName()) 66 .setIsOpenOnCreation(true) 67 .setIgnoreImplicitExceptions(true); 68 if (bugType != null) 69 stream.setInteresting(bugType); 70 71 return stream; 72 } 73 } catch (ClassNotFoundException e) { 74 lookupFailureCallback.reportMissingClass(e); 75 } 76 77 return null; 78 } 79 } 80 81 | Popular Tags |