user8488823
user8488823

Reputation: 75

Checkerframework replace annotation

I'm new to Checker Framework and I have defined 2 subtyping annotations like this:

@Target(value={TYPE_USE,TYPE_PARAMETER})
@DefaultQualifierInHierarchy
@SubtypeOf(value={})
public @interface Base{}

and

@Target(value={TYPE_USE,TYPE_PARAMETER})
@SubtypeOf(value=Base.class)
@DefaultFor(value=LOWER_BOUND)
public @interface Sub{}

When I use a subtyping checker with these annotations on the following code, it produces an error, because sink() expects a string marked as @Sub, but receives @Base (the default for String s0), which is the expected behaviour.

public static void main(String args[]) {
    String s0 = "a";
    sink(s0);
}

public static void sink(@Sub String s) {}

Now I want to add a third annotation, called for example @ToSub and use it like this:

public static void main(String args[]) {
    String s0 = "a";
    @ToSub String s1 = s0;
    sink(s1);
}

public static void sink(@Sub String s) {}

This third annotation is supposed to turn the current type of s0 (@Base) into its subtype @Sub for the new string s1, so that this code example would not throw an error.

Is this at all possible with Checker Framework? I could not find a way to accomplish this simply by defining a new annotation, did I miss something? Can this maybe only be accomplished by writing a completely new checker?

Upvotes: 0

Views: 167

Answers (1)

mernst
mernst

Reputation: 8127

You seem to be looking for Java's existing @SuppressWarnings annotation.

More generally, if you want to suppress a warning, see the "Suppressing warnings" chapter of the Checker Framework manual.

Upvotes: 1

Related Questions