mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
java: add qldoc
These interfaces were previously in a .ql file. Also, use the XXAccess variants.
This commit is contained in:
@@ -4,39 +4,49 @@ module;
|
|||||||
import java
|
import java
|
||||||
import semmle.code.java.frameworks.Mockito
|
import semmle.code.java.frameworks.Mockito
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Java type representing a lock.
|
||||||
|
* We identify a lock type as one that has both `lock` and `unlock` methods.
|
||||||
|
*/
|
||||||
class LockType extends RefType {
|
class LockType extends RefType {
|
||||||
LockType() {
|
LockType() {
|
||||||
this.getAMethod().hasName("lock") and
|
this.getAMethod().hasName("lock") and
|
||||||
this.getAMethod().hasName("unlock")
|
this.getAMethod().hasName("unlock")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets a method that is locking this lock type. */
|
||||||
Method getLockMethod() {
|
Method getLockMethod() {
|
||||||
result.getDeclaringType() = this and
|
result.getDeclaringType() = this and
|
||||||
result.hasName(["lock", "lockInterruptibly", "tryLock"])
|
result.hasName(["lock", "lockInterruptibly", "tryLock"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets a method that is unlocking this lock type. */
|
||||||
Method getUnlockMethod() {
|
Method getUnlockMethod() {
|
||||||
result.getDeclaringType() = this and
|
result.getDeclaringType() = this and
|
||||||
result.hasName("unlock")
|
result.hasName("unlock")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets an `isHeldByCurrentThread` method of this lock type. */
|
||||||
Method getIsHeldByCurrentThreadMethod() {
|
Method getIsHeldByCurrentThreadMethod() {
|
||||||
result.getDeclaringType() = this and
|
result.getDeclaringType() = this and
|
||||||
result.hasName("isHeldByCurrentThread")
|
result.hasName("isHeldByCurrentThread")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets a call to a method that is locking this lock type. */
|
||||||
MethodCall getLockAccess() {
|
MethodCall getLockAccess() {
|
||||||
result.getMethod() = this.getLockMethod() and
|
result.getMethod() = this.getLockMethod() and
|
||||||
// Not part of a Mockito verification call
|
// Not part of a Mockito verification call
|
||||||
not result instanceof MockitoVerifiedMethodCall
|
not result instanceof MockitoVerifiedMethodCall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets a call to a method that is unlocking this lock type. */
|
||||||
MethodCall getUnlockAccess() {
|
MethodCall getUnlockAccess() {
|
||||||
result.getMethod() = this.getUnlockMethod() and
|
result.getMethod() = this.getUnlockMethod() and
|
||||||
// Not part of a Mockito verification call
|
// Not part of a Mockito verification call
|
||||||
not result instanceof MockitoVerifiedMethodCall
|
not result instanceof MockitoVerifiedMethodCall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets a call to a method that checks if the lock is held by the current thread. */
|
||||||
MethodCall getIsHeldByCurrentThreadAccess() {
|
MethodCall getIsHeldByCurrentThreadAccess() {
|
||||||
result.getMethod() = this.getIsHeldByCurrentThreadMethod() and
|
result.getMethod() = this.getIsHeldByCurrentThreadMethod() and
|
||||||
// Not part of a Mockito verification call
|
// Not part of a Mockito verification call
|
||||||
@@ -200,9 +210,9 @@ module Monitors {
|
|||||||
exists(Variable localLock, MethodCall lockCall, MethodCall unlockCall |
|
exists(Variable localLock, MethodCall lockCall, MethodCall unlockCall |
|
||||||
represents(lock, localLock) and
|
represents(lock, localLock) and
|
||||||
lockCall.getQualifier() = localLock.getAnAccess() and
|
lockCall.getQualifier() = localLock.getAnAccess() and
|
||||||
lockCall.getMethod() = lock.getType().(LockType).getLockMethod() and
|
lockCall = lock.getType().(LockType).getLockAccess() and
|
||||||
unlockCall.getQualifier() = localLock.getAnAccess() and
|
unlockCall.getQualifier() = localLock.getAnAccess() and
|
||||||
unlockCall.getMethod() = lock.getType().(LockType).getUnlockMethod()
|
unlockCall = lock.getType().(LockType).getUnlockAccess()
|
||||||
|
|
|
|
||||||
dominates(lockCall.getControlFlowNode(), unlockCall.getControlFlowNode()) and
|
dominates(lockCall.getControlFlowNode(), unlockCall.getControlFlowNode()) and
|
||||||
dominates(lockCall.getControlFlowNode(), getNodeToBeDominated(e)) and
|
dominates(lockCall.getControlFlowNode(), getNodeToBeDominated(e)) and
|
||||||
|
|||||||
Reference in New Issue
Block a user