@@ -52,6 +52,27 @@ query predicate multipleParents(Element child, string childClass, Element parent
52
52
parentClass = parent .getPrimaryQlClasses ( )
53
53
}
54
54
55
+ /** Holds if `parent` has multiple children at the same index. */
56
+ query predicate multipleChildren ( Element parent , int index , Element child1 , Element child2 ) {
57
+ child1 = getChildAndAccessor ( parent , index , _) and
58
+ child2 = getChildAndAccessor ( parent , index , _) and
59
+ child1 != child2
60
+ }
61
+
62
+ /**
63
+ * Holds if `child` has multiple positions amongst the `accessor` children
64
+ * of `parent`.
65
+ *
66
+ * Children are allowed to have multiple positions for _different_ accessors,
67
+ * for example in an array repeat expression `[1; 10]`, `1` has positions for
68
+ * both `getRepeatOperand()` and `getExpr()`.
69
+ */
70
+ query predicate multiplePositions ( Element parent , int pos1 , int pos2 , string accessor , Element child ) {
71
+ child = getChildAndAccessor ( parent , pos1 , accessor ) and
72
+ child = getChildAndAccessor ( parent , pos2 , accessor ) and
73
+ pos1 != pos2
74
+ }
75
+
55
76
/**
56
77
* Gets counts of abstract syntax tree inconsistencies of each type.
57
78
*/
@@ -71,4 +92,10 @@ int getAstInconsistencyCounts(string type) {
71
92
or
72
93
type = "Multiple parents" and
73
94
result = count ( Element e | multipleParents ( e ) | e )
95
+ or
96
+ type = "Multiple children" and
97
+ result = count ( Element e | multipleChildren ( _, _, e , _) | e )
98
+ or
99
+ type = "Multiple positions" and
100
+ result = count ( Element e | multiplePositions ( _, _, _, _, e ) | e )
74
101
}
0 commit comments