@Documented @Retention(value=RUNTIME) @Target(value={METHOD,CONSTRUCTOR}) @InheritedAnnotation public @interface EnsuresLTLengthOf
Consider the following example, from the Index Checker's regression tests:
@EnsuresLTLengthOf(value = "end", targetValue = "array", offset = "#1 - 1")
public void shiftIndex(@NonNegative int x) {
int newEnd = end - x;
if (newEnd < 0) throw new RuntimeException();
end = newEnd;
}
where end
is annotated as @NonNegative @LTEqLengthOf("array") int end;
This method guarantees that end
has type @LTLengthOf(value="array", offset="x -
1")
after the method returns. This is useful in cases like this one:
public void useShiftIndex(@NonNegative int x) {
// :: error: (argument.type.incompatible)
Arrays.fill(array, end, end + x, null);
shiftIndex(x);
Arrays.fill(array, end, end + x, null);
}
The first call to Arrays.fill
is rejected (hence the comment about an error). But, after
calling shiftIndex(x)
, end
has an annotation that allows the end + x
to
be accepted as @LTLengthOf("array")
.LTLengthOf
Modifier and Type | Required Element and Description |
---|---|
String[] |
targetValue
Sequences, each of which is longer than the each of the expressions' value on successful
method termination.
|
String[] |
value
The Java expressions that are less than the length of the given sequences on successful
method termination.
|
public abstract String[] value
public abstract String[] targetValue
public abstract String[] offset
offset
element must ether be empty or the same
length as targetValue
.