C#: Autoformat QL queries

This commit is contained in:
Tom Hvitved
2019-01-02 12:59:07 +01:00
parent 4348de3120
commit daa45322b1
277 changed files with 2462 additions and 2301 deletions

View File

@@ -8,22 +8,20 @@
* @tags efficiency
* maintainability
*/
import csharp
// any use of + that has string type
class StringCat extends AddExpr {
StringCat() {
this.getType() instanceof StringType
}
}
class StringCat extends AddExpr { StringCat() { this.getType() instanceof StringType } }
/*
* an assignment of the form
* v = ... + ... v ...
* where v is a simple variable (and not, for example, a property)
*/
/* an assignment of the form
v = ... + ... v ...
where v is a simple variable (and not, for example, a property)
*/
predicate isSelfConcatAssignExpr(AssignExpr e, Variable v) {
not e = any(AssignAddExpr a).getExpandedAssignment()
and
not e = any(AssignAddExpr a).getExpandedAssignment() and
exists(VariableAccess use |
stringCatContains(e.getRValue(), use) and
use.getTarget() = e.getTargetVariable() and
@@ -36,20 +34,22 @@ predicate stringCatContains(StringCat expr, Expr child) {
stringCatContains(expr, child.getParent())
}
/* an assignment of the form
v += ...
where v is a simple variable (and not, for example, a property)
*/
/*
* an assignment of the form
* v += ...
* where v is a simple variable (and not, for example, a property)
*/
predicate isConcatExpr(AssignAddExpr e, Variable v) {
e.getLValue().getType() instanceof StringType and
v = e.getTargetVariable()
}
from Expr e
where exists(LoopStmt loop, Variable v |
e.getEnclosingStmt().getParent*() = loop and
(isSelfConcatAssignExpr(e, v) or isConcatExpr(e, v)) and
forall(LocalVariableDeclExpr l | l.getVariable() = v | not l.getParent*() = loop)
)
where
exists(LoopStmt loop, Variable v |
e.getEnclosingStmt().getParent*() = loop and
(isSelfConcatAssignExpr(e, v) or isConcatExpr(e, v)) and
forall(LocalVariableDeclExpr l | l.getVariable() = v | not l.getParent*() = loop)
)
select e, "String concatenation in loop: use 'StringBuilder'."