1 package edu.umd.cs.findbugs.ba.npe; 2 3 import edu.umd.cs.findbugs.SystemProperties; 4 import edu.umd.cs.findbugs.ba.JavaClassAndMethod; 5 import edu.umd.cs.findbugs.ba.JavaClassAndMethodChooser; 6 import edu.umd.cs.findbugs.ba.XMethod; 7 8 16 public class NonNullReturnValueAnnotationChecker implements JavaClassAndMethodChooser { 17 private static final boolean DEBUG = SystemProperties.getBoolean("fnd.debug.nullreturn"); 18 19 private MayReturnNullPropertyDatabase database; 20 private JavaClassAndMethod annotatedMethod; 21 private Boolean property; 22 23 24 public NonNullReturnValueAnnotationChecker(MayReturnNullPropertyDatabase database) { 25 this.database = database; 26 } 27 28 public Boolean getProperty() { 29 return property; 30 } 31 32 public JavaClassAndMethod getAnnotatedMethod() { 33 return annotatedMethod; 34 } 35 36 public boolean choose(JavaClassAndMethod javaClassAndMethod) { 37 XMethod xmethod = javaClassAndMethod.toXMethod(); 38 if (DEBUG) { 39 System.out.print("Checking " + xmethod + " for @NonNull or @CheckForNull..."); 40 } 41 Boolean prop = database.getProperty(xmethod); 42 if (prop != null) { 43 this.property = prop; 44 this.annotatedMethod = javaClassAndMethod; 45 if (DEBUG) { 46 System.out.println(prop.booleanValue() ? "@CheckForNull" : "@NonNull"); 47 } 48 return true; 49 } 50 if (DEBUG) { 51 System.out.println("not found"); 52 } 53 return false; 54 } 55 } 56 | Popular Tags |