typetools / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
1.02k stars 355 forks source link

More options to @DefaultQualifier: member type, modifiers #205

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please add more options for finer-grained control over which annotations are 
applied to which program elements by default. 

Here are two requested features:
 * target annotations at fields without targeting methods or the enclosing class
 * target based on a combination of modifiers (visibility, static or not, final or not) 
This would be especially useful for classes that hold untrusted data parsed 
from JSON or XML.

This is what the extended @DefaultQualifier API could look like when used in a 
package-info.java file:

@DefaultQualifiers({
  @DefaultQualifier(value = Nullable.class, targets = {
    @Location({ PUBLIC, NON_FINAL, FIELDS }), 
    @Location({ VOLATILE, FIELDS })
  }),
  @DefaultQualifier(value=NonNull.class, targets = {
    @Location({ PUBLIC, STATIC, FINAL, FIELDS })
  })
})
package some.component;

import static checkers.quals.DefaultLocation.*;
import checkers.nullness.quals.NonNull;
import checkers.nullness.quals.Nullable;
import checkers.quals.DefaultQualifier;
import checkers.quals.DefaultQualifiers;
import checkers.quals.Location;

That package-info.java file would override the default annotations to be set 
like this:

class ContrivedExamplePerson {
  public static final String JOB_1 = "koodari"; // @NonNull
  static volatile Boolean isValidationComplete; // @Nullable

  public final String recordType = "minimum";   // not overridden
  public String name;                           // @Nullable
  public String occupation;                     // @Nullable
}

Original issue reported on code.google.com by timo.kin...@gmail.com on 9 Feb 2013 at 1:42

GoogleCodeExporter commented 9 years ago
This would be a useful enhancement.

Original comment by michael.ernst@gmail.com on 28 Mar 2013 at 6:11