@Documented @Retention(value=RUNTIME) @Target(value={FIELD,CONSTRUCTOR,METHOD,PARAMETER}) public @interface ReadOnly
immutable reference in that @ReadOnly does not
exclude the existence of references used for mutation. A read-only parameter,
unlike a borrowed parameter for which mutation is not permitted, may be
compromised/aliased. Thus we normally do not recommend variables be annotated
@ReadOnly unless the callee wishes to retain a reference.
A Borrowed field may be annotated @ReadOnly to indicate that the field
cannot be used for mutation.
It is a modeling error to annotate a primitive type. For example
@ReadOnly("return") public int getValue() { … }
and
public void setValue(@ReadOnly int value) { … }
would generate modeling errors.
This annotation is not currently checked by analysis and is still experimental. It may be used for documentation purposes.
Return Value:
Field:
@annotate tag. One complication is that the parameter being
annotated must be explicitly specified because the annotation can no longer
appear in the context of the parameter declaration.
/**
* @annotate ReadOnly("a, b, c")
*/
public void m1(Object a, Object b, Object c) { ... }
This annotation states that the three parameters are readonly. Alternatively,
you can use several annotations as shown below.
/**
* @annotate ReadOnly("a")
* @annotate ReadOnly("b")
* @annotate ReadOnly("c")
*/
public void m1(Object a, Object b, Object c) { ... }
public abstract String value
""
"this"
"return"
"this, return"
"return, this"
The values are interpreted thusly
"this", it indicates the
receiver is readonly. This value is only allowed on methods.
"return", it indicates the
return value is readonly. This value is allowed on methods and
constructors.
"this" and "return", it
indicates that both the receiver and the return value are readonly. This
value is only allowed on methods.
This attribute is not used when annotating a parameter or a field: the attribute value must be the empty string in these cases.
The value of this attribute must conform to the following grammar (in Augmented Backus–Naur Form):
value = [("this" ["," "return"]) / ("return" ["," "this"])] ; See above comments
Copyright © 2012 Surelogic, Inc.. All Rights Reserved.