@@ -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
@@ -33,12 +33,15 @@ predicate isIEnumerableType(ValueOrRefType t) {
3333 )
3434}
3535
36+ /** DEPRECATED: Use `ForEachStmtGenericEnumerable` instead. */
37+ deprecated class ForeachStmtGenericEnumerable = ForEachStmtGenericEnumerable ;
38+
3639/**
3740 * A class of foreach statements where the iterable expression
3841 * supports the use of the LINQ extension methods on `IEnumerable<T>`.
3942 */
40- class ForeachStmtGenericEnumerable extends ForeachStmt {
41- ForeachStmtGenericEnumerable ( ) {
43+ class ForEachStmtGenericEnumerable extends ForEachStmt {
44+ ForEachStmtGenericEnumerable ( ) {
4245 exists ( ValueOrRefType t | t = this .getIterableExpr ( ) .getType ( ) |
4346 t .getABaseType * ( ) .getUnboundDeclaration ( ) instanceof
4447 GenericCollections:: SystemCollectionsGenericIEnumerableTInterface or
@@ -47,12 +50,15 @@ class ForeachStmtGenericEnumerable extends ForeachStmt {
4750 }
4851}
4952
53+ /** DEPRECATED: Use `ForEachStmtEnumerable` instead. */
54+ deprecated class ForeachStmtEnumerable = ForEachStmtEnumerable ;
55+
5056/**
5157 * A class of foreach statements where the iterable expression
5258 * supports the use of the LINQ extension methods on `IEnumerable`.
5359 */
54- class ForeachStmtEnumerable extends ForeachStmt {
55- ForeachStmtEnumerable ( ) {
60+ class ForEachStmtEnumerable extends ForEachStmt {
61+ ForEachStmtEnumerable ( ) {
5662 exists ( ValueOrRefType t | t = this .getIterableExpr ( ) .getType ( ) |
5763 t .getABaseType * ( ) instanceof Collections:: SystemCollectionsIEnumerableInterface or
5864 t .( ArrayType ) .getRank ( ) = 1
@@ -62,11 +68,11 @@ class ForeachStmtEnumerable extends ForeachStmt {
6268
6369/**
6470 * Holds if `foreach` statement `fes` could be converted to a `.All()` call.
65- * That is, the `ForeachStmt ` contains a single `if` with a condition that
71+ * That is, the `ForEachStmt ` contains a single `if` with a condition that
6672 * accesses the loop variable and with a body that assigns `false` to a variable
6773 * and `break`s out of the `foreach`.
6874 */
69- predicate missedAllOpportunity ( ForeachStmtGenericEnumerable fes ) {
75+ predicate missedAllOpportunity ( ForEachStmtGenericEnumerable fes ) {
7076 exists ( IfStmt is |
7177 // The loop contains an if statement with no else case, and nothing else.
7278 is = firstStmt ( fes ) and
@@ -90,7 +96,7 @@ predicate missedAllOpportunity(ForeachStmtGenericEnumerable fes) {
9096 * block, the access is a cast, and the first statement is a
9197 * local variable declaration statement `s`.
9298 */
93- predicate missedCastOpportunity ( ForeachStmtEnumerable fes , LocalVariableDeclStmt s ) {
99+ predicate missedCastOpportunity ( ForEachStmtEnumerable fes , LocalVariableDeclStmt s ) {
94100 s = firstStmt ( fes ) and
95101 forex ( VariableAccess va | va = fes .getVariable ( ) .getAnAccess ( ) |
96102 va = s .getAVariableDeclExpr ( ) .getAChildExpr * ( )
@@ -107,7 +113,7 @@ predicate missedCastOpportunity(ForeachStmtEnumerable fes, LocalVariableDeclStmt
107113 * block, the access is a cast with the `as` operator, and the first statement
108114 * is a local variable declaration statement `s`.
109115 */
110- predicate missedOfTypeOpportunity ( ForeachStmtEnumerable fes , LocalVariableDeclStmt s ) {
116+ predicate missedOfTypeOpportunity ( ForEachStmtEnumerable fes , LocalVariableDeclStmt s ) {
111117 s = firstStmt ( fes ) and
112118 forex ( VariableAccess va | va = fes .getVariable ( ) .getAnAccess ( ) |
113119 va = s .getAVariableDeclExpr ( ) .getAChildExpr * ( )
@@ -125,7 +131,7 @@ predicate missedOfTypeOpportunity(ForeachStmtEnumerable fes, LocalVariableDeclSt
125131 * local variable declaration statement `s`, and the initializer does not
126132 * contain an `await` expression (since `Select` does not support async lambdas).
127133 */
128- predicate missedSelectOpportunity ( ForeachStmtGenericEnumerable fes , LocalVariableDeclStmt s ) {
134+ predicate missedSelectOpportunity ( ForEachStmtGenericEnumerable fes , LocalVariableDeclStmt s ) {
129135 s = firstStmt ( fes ) and
130136 forex ( VariableAccess va | va = fes .getVariable ( ) .getAnAccess ( ) |
131137 va = s .getAVariableDeclExpr ( ) .getAChildExpr * ( )
@@ -140,7 +146,7 @@ predicate missedSelectOpportunity(ForeachStmtGenericEnumerable fes, LocalVariabl
140146 * variable, and the body of the `if` is either a `continue` or there's nothing
141147 * else in the loop than the `if`.
142148 */
143- predicate missedWhereOpportunity ( ForeachStmtGenericEnumerable fes , IfStmt is ) {
149+ predicate missedWhereOpportunity ( ForEachStmtGenericEnumerable fes , IfStmt is ) {
144150 // The very first thing the foreach loop does is test its iteration variable.
145151 is = firstStmt ( fes ) and
146152 exists ( VariableAccess va |
0 commit comments