Skip to content

Commit cf18a9a

Browse files
committed
Fix bad join order in Shadowing::shadows
Fixes the bad join order in `Shadowing::shadows`: Tuple counts for Shadowing::shadows#f4fb89a3#ffff@c4b8a90j: 182915 ~0% {2} r1 = Variable::LocalVariableDecl::getCallable#dispred#f0820431#ff AND NOT Shadowing::shadows#f4fb89a3#ffff#antijoin_rhs(Lhs.0, Lhs.1) 182915 ~0% {3} r2 = JOIN r1 WITH localvars ON FIRST 1 OUTPUT Lhs.1, Lhs.0, Rhs.2 182915 ~3% {4} r3 = JOIN r2 WITH Member::Member::getDeclaringType#dispred#f0820431#bf ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0, Lhs.2 182833 ~0% {4} r4 = JOIN r3 WITH classes ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.0 182833 ~3% {5} r5 = JOIN r4 WITH Element::Element::getName#dispred#f0820431#ff ON FIRST 1 OUTPUT Lhs.2, Lhs.0, Lhs.1, Lhs.3, Rhs.1 183352620 ~5% {5} r6 = JOIN r5 WITH Member::Field::getType#dispred#f0820431#bf_10#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.3, Lhs.1, Lhs.2, Lhs.4 40529 ~0% {5} r7 = JOIN r6 WITH Member::Field::getDeclaringType#dispred#f0820431#fb ON FIRST 2 OUTPUT Lhs.0, Lhs.4, Lhs.2, Lhs.3, Lhs.1 678 ~4% {4} r8 = JOIN r7 WITH Element::Element::getName#dispred#f0820431#ff ON FIRST 2 OUTPUT Lhs.2, Lhs.3, Lhs.4, Lhs.0 670 ~4% {4} r9 = r8 AND NOT Member::Field::isStatic#dispred#f0820431#b(Lhs.3) 670 ~3% {4} r10 = SCAN r9 OUTPUT In.0, In.2, In.3, In.1 return r10 After the fix: Tuple counts for Shadowing::shadows#f4fb89a3#ffff@95ca976v: 182915 ~0% {2} r1 = Variable::LocalVariableDecl::getCallable#dispred#f0820431#ff AND NOT Shadowing::shadows#f4fb89a3#ffff#antijoin_rhs(Lhs.0, Lhs.1) 182915 ~0% {3} r2 = JOIN r1 WITH localvars ON FIRST 1 OUTPUT Lhs.1, Lhs.0, Rhs.2 182915 ~0% {4} r3 = JOIN r2 WITH Member::Member::getDeclaringType#dispred#f0820431#bf ON FIRST 1 OUTPUT Lhs.1, Lhs.0, Lhs.2, Rhs.1 182915 ~7% {5} r4 = JOIN r3 WITH Element::Element::getName#dispred#f0820431#ff ON FIRST 1 OUTPUT Lhs.3, Rhs.1, Lhs.2, Lhs.0, Lhs.1 678 ~4% {4} r5 = JOIN r4 WITH Shadowing::getField#f4fb89a3#ffff ON FIRST 3 OUTPUT Lhs.3, Lhs.4, Lhs.0, Rhs.3 670 ~4% {4} r6 = r5 AND NOT Member::Field::isStatic#dispred#f0820431#b(Lhs.3) 670 ~3% {4} r7 = SCAN r6 OUTPUT In.0, In.2, In.3, In.1 return r7
1 parent e65a046 commit cf18a9a

File tree

1 file changed

+12
-4
lines changed
  • java/ql/src/Violations of Best Practice/Naming Conventions

1 file changed

+12
-4
lines changed

java/ql/src/Violations of Best Practice/Naming Conventions/Shadowing.qll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ predicate setterFor(Method m, Field f) {
2020
predicate shadows(LocalVariableDecl d, Class c, Field f, Callable method) {
2121
d.getCallable() = method and
2222
method.getDeclaringType() = c and
23-
c.getAField() = f and
24-
f.getName() = d.getName() and
25-
f.getType() = d.getType() and
26-
not d.getCallable().isStatic() and
23+
f = getField(c, d.getName(), d.getType()) and
24+
not method.isStatic() and
2725
not f.isStatic()
2826
}
2927

28+
/**
29+
* Gets the field with the given name and type from the given class, if any.
30+
*/
31+
pragma[nomagic]
32+
private Field getField(Class c, string name, Type t) {
33+
result.getDeclaringType() = c and
34+
result.getName() = name and
35+
result.getType() = t
36+
}
37+
3038
predicate thisAccess(LocalVariableDecl d, Field f) {
3139
shadows(d, _, f, _) and
3240
exists(VarAccess va | va.getVariable().(Field).getSourceDeclaration() = f |

0 commit comments

Comments
 (0)