@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public @interface ReturnsLock
Methods that override a method annotated with
@ReturnsLock("l") must also be
explicitly annotated @ReturnsLock("l").
It is a modeling error if they are not.
null
and reference the lock object declared in the RegionLock or PolicyLock declaration
for the named lock.
Thing, returns a lock used to protected subclass
state.
@Region("protected ThingState")
@RegionLock("ThingLock is thingLock protects ThingState")
class Thing {
private final Object thingLock = new Object();
@ReturnsLock("ThingLock")
protected Object getThingLock() {
return thingLock;
}
...
}
The lock getter method can then be used in subclasses such as the
Player below.
class Player extends Thing {
@InRegion("ThingState")
private long x, y;
public void setPosition(long x, long y) {
synchronized (getThingLock()) {
this.x = x;
this.y = y;
}
}
...
}
A lock getter method may return a policy lock:
@PolicyLock("InitLock is initLock")
public class System {
private final Object initLock = new Object();
...
@ReturnsLock("InitLock")
protected Object getInitLock() {
return initLock;
}
}
@annotate tag.
/**
* @annotate Region("protected ThingState")
* @annotate RegionLock("ThingLock is thingLock protects ThingState")
*/
class Thing {
private final Object thingLock = new Object();
/**
* @annotate ReturnsLock("ThingLock")
*/
protected Object getThingLock() {
return thingLock;
}
...
}
RegionLockpublic abstract String value
value = lockSpecification
lockSpecification = qualifiedLockSpecification / simpleLockSpecification
simpleLockSpecification = simpleLockName ["." ("readLock" / "writeLock")]
qualifiedLockSpecification = qualifiedLockName ["." ("readLock" / "writeLock")]
simpleLockName = IDENTIFIER ; Lock from the receiver (same as "this:IDENTIFIER")
qualifiedLockName = parameterLockName / typeQualifiedLockName / innerClassLockName
parameterLockName = simpleExpression ":" IDENTIFIER ; Lock from a method/constructor parameter
simpleExpression = "this" / IDENTIFER ; Receiver or parameter name
typeQualifiedLockName = typeExpression ":" IDENTIFIER ; Static lock qualified by a class name
typeExpression = IDENTIFIER *("." IDENTIFIER)
innerClassLockName = namedType "." "this" ":" IDENTIFIER ; Lock from an enclosing instance
namedType = IDENTIFIER *("." IDENTIFIER)
IDENTIFIER = Legal Java Identifier
Copyright © 2012 Surelogic, Inc.. All Rights Reserved.