@@ -8,13 +8,13 @@ private import semmle.code.csharp.frameworks.system.collections.Generic as Gener
88private import semmle.code.csharp.frameworks.system.Collections as Collections
99
1010//#################### PREDICATES ####################
11- private Stmt firstStmt ( ForeachStmt fes ) {
11+ private Stmt firstStmt ( ForEachStmt fes ) {
1212 if fes .getBody ( ) instanceof BlockStmt
1313 then result = fes .getBody ( ) .( BlockStmt ) .getStmt ( 0 )
1414 else result = fes .getBody ( )
1515}
1616
17- private int numStmts ( ForeachStmt fes ) {
17+ private int numStmts ( ForEachStmt fes ) {
1818 if fes .getBody ( ) instanceof BlockStmt
1919 then result = count ( fes .getBody ( ) .( BlockStmt ) .getAStmt ( ) )
2020 else result = 1
@@ -53,12 +53,15 @@ predicate isIEnumerableType(ValueOrRefType t) {
5353 )
5454}
5555
56+ /** DEPRECATED: Use `ForEachStmtGenericEnumerable` instead. */
57+ deprecated class ForeachStmtGenericEnumerable = ForEachStmtGenericEnumerable ;
58+
5659/**
5760 * A class of foreach statements where the iterable expression
5861 * supports the use of the LINQ extension methods on `IEnumerable<T>`.
5962 */
60- class ForeachStmtGenericEnumerable extends ForeachStmt {
61- ForeachStmtGenericEnumerable ( ) {
63+ class ForEachStmtGenericEnumerable extends ForEachStmt {
64+ ForEachStmtGenericEnumerable ( ) {
6265 exists ( ValueOrRefType t | t = this .getIterableExpr ( ) .getType ( ) |
6366 t .getABaseType * ( ) .getUnboundDeclaration ( ) instanceof
6467 GenericCollections:: SystemCollectionsGenericIEnumerableTInterface or
@@ -67,12 +70,15 @@ class ForeachStmtGenericEnumerable extends ForeachStmt {
6770 }
6871}
6972
73+ /** DEPRECATED: Use `ForEachStmtEnumerable` instead. */
74+ deprecated class ForeachStmtEnumerable = ForEachStmtEnumerable ;
75+
7076/**
7177 * A class of foreach statements where the iterable expression
7278 * supports the use of the LINQ extension methods on `IEnumerable`.
7379 */
74- class ForeachStmtEnumerable extends ForeachStmt {
75- ForeachStmtEnumerable ( ) {
80+ class ForEachStmtEnumerable extends ForEachStmt {
81+ ForEachStmtEnumerable ( ) {
7682 exists ( ValueOrRefType t | t = this .getIterableExpr ( ) .getType ( ) |
7783 t .getABaseType * ( ) instanceof Collections:: SystemCollectionsIEnumerableInterface or
7884 t .( ArrayType ) .getRank ( ) = 1
@@ -82,11 +88,11 @@ class ForeachStmtEnumerable extends ForeachStmt {
8288
8389/**
8490 * Holds if `foreach` statement `fes` could be converted to a `.All()` call.
85- * That is, the `ForeachStmt ` contains a single `if` with a condition that
91+ * That is, the `ForEachStmt ` contains a single `if` with a condition that
8692 * accesses the loop variable and with a body that assigns `false` to a variable
8793 * and `break`s out of the `foreach`.
8894 */
89- predicate missedAllOpportunity ( ForeachStmtGenericEnumerable fes ) {
95+ predicate missedAllOpportunity ( ForEachStmtGenericEnumerable fes ) {
9096 exists ( IfStmt is |
9197 // The loop contains an if statement with no else case, and nothing else.
9298 is = firstStmt ( fes ) and
@@ -110,7 +116,7 @@ predicate missedAllOpportunity(ForeachStmtGenericEnumerable fes) {
110116 * block, the access is a cast, and the first statement is a
111117 * local variable declaration statement `s`.
112118 */
113- predicate missedCastOpportunity ( ForeachStmtEnumerable fes , LocalVariableDeclStmt s ) {
119+ predicate missedCastOpportunity ( ForEachStmtEnumerable fes , LocalVariableDeclStmt s ) {
114120 s = firstStmt ( fes ) and
115121 forex ( VariableAccess va | va = fes .getVariable ( ) .getAnAccess ( ) |
116122 va = s .getAVariableDeclExpr ( ) .getAChildExpr * ( )
@@ -127,7 +133,7 @@ predicate missedCastOpportunity(ForeachStmtEnumerable fes, LocalVariableDeclStmt
127133 * block, the access is a cast with the `as` operator, and the first statement
128134 * is a local variable declaration statement `s`.
129135 */
130- predicate missedOfTypeOpportunity ( ForeachStmtEnumerable fes , LocalVariableDeclStmt s ) {
136+ predicate missedOfTypeOpportunity ( ForEachStmtEnumerable fes , LocalVariableDeclStmt s ) {
131137 s = firstStmt ( fes ) and
132138 forex ( VariableAccess va | va = fes .getVariable ( ) .getAnAccess ( ) |
133139 va = s .getAVariableDeclExpr ( ) .getAChildExpr * ( )
@@ -145,7 +151,7 @@ predicate missedOfTypeOpportunity(ForeachStmtEnumerable fes, LocalVariableDeclSt
145151 * local variable declaration statement `s`, and the initializer does not
146152 * contain an `await` expression (since `Select` does not support async lambdas).
147153 */
148- predicate missedSelectOpportunity ( ForeachStmtGenericEnumerable fes , LocalVariableDeclStmt s ) {
154+ predicate missedSelectOpportunity ( ForEachStmtGenericEnumerable fes , LocalVariableDeclStmt s ) {
149155 s = firstStmt ( fes ) and
150156 forex ( VariableAccess va | va = fes .getVariable ( ) .getAnAccess ( ) |
151157 va = s .getAVariableDeclExpr ( ) .getAChildExpr * ( )
@@ -160,7 +166,7 @@ predicate missedSelectOpportunity(ForeachStmtGenericEnumerable fes, LocalVariabl
160166 * variable, and the body of the `if` is either a `continue` or there's nothing
161167 * else in the loop than the `if`.
162168 */
163- predicate missedWhereOpportunity ( ForeachStmtGenericEnumerable fes , IfStmt is ) {
169+ predicate missedWhereOpportunity ( ForEachStmtGenericEnumerable fes , IfStmt is ) {
164170 // The very first thing the foreach loop does is test its iteration variable.
165171 is = firstStmt ( fes ) and
166172 exists ( VariableAccess va |
0 commit comments