typetools / typetools/checker-framework

More options to @DefaultQualifier: member type, modifiers

Open
#205 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the @DefaultQualifier and @DefaultQualifiers API as used in package-info.java, and trace how annotation targets are currently interpreted. Compare that behavior with the requested field-only and combined modifier locations; done means the shown Nullable and NonNull defaults can express the requested outcomes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.