Skip to content

Commit 5109bab

Browse files
committed
java: add qldoc
These interfaces were previously in a .ql file. Also, use the XXAccess variants.
1 parent 1ad2394 commit 5109bab

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

java/ql/lib/semmle/code/java/Concurrency.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,49 @@ module;
44
import java
55
import semmle.code.java.frameworks.Mockito
66

7+
/**
8+
* A Java type representing a lock.
9+
* We identify a lock type as one that has both `lock` and `unlock` methods.
10+
*/
711
class LockType extends RefType {
812
LockType() {
913
this.getAMethod().hasName("lock") and
1014
this.getAMethod().hasName("unlock")
1115
}
1216

17+
/** Gets a method that is locking this lock type. */
1318
Method getLockMethod() {
1419
result.getDeclaringType() = this and
1520
result.hasName(["lock", "lockInterruptibly", "tryLock"])
1621
}
1722

23+
/** Gets a method that is unlocking this lock type. */
1824
Method getUnlockMethod() {
1925
result.getDeclaringType() = this and
2026
result.hasName("unlock")
2127
}
2228

29+
/** Gets an `isHeldByCurrentThread` method of this lock type. */
2330
Method getIsHeldByCurrentThreadMethod() {
2431
result.getDeclaringType() = this and
2532
result.hasName("isHeldByCurrentThread")
2633
}
2734

35+
/** Gets a call to a method that is locking this lock type. */
2836
MethodCall getLockAccess() {
2937
result.getMethod() = this.getLockMethod() and
3038
// Not part of a Mockito verification call
3139
not result instanceof MockitoVerifiedMethodCall
3240
}
3341

42+
/** Gets a call to a method that is unlocking this lock type. */
3443
MethodCall getUnlockAccess() {
3544
result.getMethod() = this.getUnlockMethod() and
3645
// Not part of a Mockito verification call
3746
not result instanceof MockitoVerifiedMethodCall
3847
}
3948

49+
/** Gets a call to a method that checks if the lock is held by the current thread. */
4050
MethodCall getIsHeldByCurrentThreadAccess() {
4151
result.getMethod() = this.getIsHeldByCurrentThreadMethod() and
4252
// Not part of a Mockito verification call
@@ -200,9 +210,9 @@ module Monitors {
200210
exists(Variable localLock, MethodCall lockCall, MethodCall unlockCall |
201211
represents(lock, localLock) and
202212
lockCall.getQualifier() = localLock.getAnAccess() and
203-
lockCall.getMethod() = lock.getType().(LockType).getLockMethod() and
213+
lockCall = lock.getType().(LockType).getLockAccess() and
204214
unlockCall.getQualifier() = localLock.getAnAccess() and
205-
unlockCall.getMethod() = lock.getType().(LockType).getUnlockMethod()
215+
unlockCall = lock.getType().(LockType).getUnlockAccess()
206216
|
207217
dominates(lockCall.getControlFlowNode(), unlockCall.getControlFlowNode()) and
208218
dominates(lockCall.getControlFlowNode(), getNodeToBeDominated(e)) and

0 commit comments

Comments
 (0)