Apply code review suggestion to increase precision in getValue

This commit is contained in:
Tony Torralba
2022-05-05 16:44:43 +02:00
committed by Ian Lynagh
parent bc84ff2031
commit 5498f41248

View File

@@ -25,12 +25,11 @@ class LiveLiteral extends MethodAccess {
* This predicate gets the constant value held by the private field.
*/
CompileTimeConstantExpr getValue() {
result =
any(ReturnStmt r | this.getMethod().calls(r.getEnclosingCallable()))
.getResult()
.(VarAccess)
.getVariable()
.getInitializer()
exists(MethodAccess getterCall, VarAccess va |
methodReturns(this.getMethod(), getterCall) and
methodReturns(getterCall.getMethod(), va) and
result = va.getVariable().getInitializer()
)
}
override string toString() { result = this.getValue().toString() }
@@ -40,3 +39,10 @@ class LiveLiteral extends MethodAccess {
class LiveLiteralMethod extends Method {
LiveLiteralMethod() { this.getDeclaringType().getName().matches("LiveLiterals$%") }
}
private predicate methodReturns(Method m, Expr res) {
exists(ReturnStmt r |
r.getResult() = res and
r.getEnclosingCallable() = m
)
}