1 19 20 package edu.umd.cs.findbugs.detect; 21 22 import org.apache.bcel.Constants; 23 import org.apache.bcel.generic.ConstantPoolGen; 24 import org.apache.bcel.generic.GETSTATIC; 25 import org.apache.bcel.generic.Instruction; 26 import org.apache.bcel.generic.ObjectType; 27 28 import edu.umd.cs.findbugs.ba.Location; 29 import edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback; 30 31 36 public class StaticFieldLoadStreamFactory implements StreamFactory { 37 public String streamBaseClass; 38 public String className; 39 public String fieldName; 40 public String fieldSig; 41 42 52 public StaticFieldLoadStreamFactory(String streamBaseClass, String className, 53 String fieldName, String fieldSig) { 54 this.streamBaseClass = streamBaseClass; 55 this.className = className; 56 this.fieldName = fieldName; 57 this.fieldSig = fieldSig; 58 } 59 60 public Stream createStream(Location location, ObjectType type, ConstantPoolGen cpg, 61 RepositoryLookupFailureCallback lookupFailureCallback) { 62 63 Instruction ins = location.getHandle().getInstruction(); 64 if (ins.getOpcode() != Constants.GETSTATIC) 65 return null; 66 67 GETSTATIC getstatic = (GETSTATIC) ins; 68 if (!className.equals(getstatic.getClassName(cpg)) 69 || !fieldName.equals(getstatic.getName(cpg)) 70 || !fieldSig.equals(getstatic.getSignature(cpg))) 71 return null; 72 73 return new Stream(location, type.getClassName(), streamBaseClass) 74 .setIgnoreImplicitExceptions(true) 75 .setIsOpenOnCreation(true); 76 } 77 } 78 79 | Popular Tags |