Skip to content

Commit c24302b

Browse files
committed
C#: Replace all uses of the deprecated hasQualifiedName/1 predicate.
1 parent 315a3a5 commit c24302b

File tree

140 files changed

+372
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+372
-313
lines changed

csharp/ql/examples/snippets/catch_exception.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
import csharp
1111

1212
from CatchClause catch
13-
where catch.getCaughtExceptionType().hasQualifiedName("System.IO.IOException")
13+
where catch.getCaughtExceptionType().hasQualifiedName("System.IO", "IOException")
1414
select catch

csharp/ql/examples/snippets/constructor_call.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
import csharp
1111

1212
from ObjectCreation new
13-
where new.getObjectType().hasQualifiedName("System.Exception")
13+
where new.getObjectType().hasQualifiedName("System", "Exception")
1414
select new

csharp/ql/examples/snippets/extend_class.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
import csharp
1414

1515
from RefType type
16-
where type.getABaseType+().hasQualifiedName("System.Collections.IEnumerator")
16+
where type.getABaseType+().hasQualifiedName("System.Collections", "IEnumerator")
1717
select type

csharp/ql/examples/snippets/field_read.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import csharp
1111
from Field f, FieldRead read
1212
where
1313
f.hasName("VirtualAddress") and
14-
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE.Section") and
14+
f.getDeclaringType().hasQualifiedName("Mono.Cecil.PE", "Section") and
1515
f = read.getTarget()
1616
select read

csharp/ql/examples/snippets/method_call.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ from MethodCall call, Method method
1212
where
1313
call.getTarget() = method and
1414
method.hasName("MethodName") and
15-
method.getDeclaringType().hasQualifiedName("Company.Class")
15+
method.getDeclaringType().hasQualifiedName("Company", "Class")
1616
select call

csharp/ql/examples/snippets/null_argument.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ where
1717
add.hasName("Add") and
1818
add.getDeclaringType()
1919
.getUnboundDeclaration()
20-
.hasQualifiedName("System.Collections.Generic.ICollection<>") and
20+
.hasQualifiedName("System.Collections.Generic", "ICollection<>") and
2121
call.getAnArgument() instanceof NullLiteral
2222
select call

csharp/ql/examples/snippets/override_method.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ import csharp
1111
from Method override, Method base
1212
where
1313
base.hasName("ToString") and
14-
base.getDeclaringType().hasQualifiedName("System.Object") and
14+
base.getDeclaringType().hasQualifiedName("System", "Object") and
1515
base.getAnOverrider() = override
1616
select override

csharp/ql/examples/snippets/throw_exception.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
import csharp
1010

1111
from ThrowStmt throw
12-
where throw.getThrownExceptionType().getBaseClass*().hasQualifiedName("System.IO.IOException")
12+
where throw.getThrownExceptionType().getBaseClass*().hasQualifiedName("System.IO", "IOException")
1313
select throw

csharp/ql/lib/Linq/Helpers.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private int numStmts(ForeachStmt fes) {
1919
}
2020

2121
/** Holds if the type's qualified name is "System.Linq.Enumerable" */
22-
predicate isEnumerableType(ValueOrRefType t) { t.hasQualifiedName("System.Linq.Enumerable") }
22+
predicate isEnumerableType(ValueOrRefType t) { t.hasQualifiedName("System.Linq", "Enumerable") }
2323

2424
/** Holds if the type's qualified name starts with "System.Collections.Generic.IEnumerable" */
2525
predicate isIEnumerableType(ValueOrRefType t) {

csharp/ql/lib/semmle/code/csharp/Stmt.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class BlockStmt extends Stmt, @block_stmt {
7575

7676
/** Holds if this block is the container of the global statements. */
7777
predicate isGlobalStatementContainer() {
78-
this.getEnclosingCallable().hasQualifiedName("Program.<Main>$")
78+
this.getEnclosingCallable().hasQualifiedName("Program", "<Main>$")
7979
}
8080

8181
override Stmt stripSingletonBlocks() {

csharp/ql/lib/semmle/code/csharp/Type.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ class AnonymousClass extends Class {
825825
* The `object` type, `System.Object`.
826826
*/
827827
class ObjectType extends Class {
828-
ObjectType() { this.hasQualifiedName("System.Object") }
828+
ObjectType() { this.hasQualifiedName("System", "Object") }
829829

830830
override string toStringWithTypes() { result = "object" }
831831

@@ -836,7 +836,7 @@ class ObjectType extends Class {
836836
* The `string` type, `System.String`.
837837
*/
838838
class StringType extends Class {
839-
StringType() { this.hasQualifiedName("System.String") }
839+
StringType() { this.hasQualifiedName("System", "String") }
840840

841841
override string toStringWithTypes() { result = "string" }
842842

csharp/ql/lib/semmle/code/csharp/commons/Util.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MainMethod extends Method {
88
(
99
this.hasName("Main")
1010
or
11-
this.hasQualifiedName("Program.<Main>$")
11+
this.hasQualifiedName("Program", "<Main>$")
1212
) and
1313
this.isStatic() and
1414
(this.getReturnType() instanceof VoidType or this.getReturnType() instanceof IntType) and

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ module Expressions {
768768
nc.getOuterCompletion()
769769
.(ThrowCompletion)
770770
.getExceptionClass()
771-
.hasQualifiedName("System.InvalidOperationException")
771+
.hasQualifiedName("System", "InvalidOperationException")
772772
)
773773
)
774774
}

csharp/ql/lib/semmle/code/csharp/controlflow/internal/NonReturning.qll

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private class ThrowingCall extends NonReturningCall {
5151
this =
5252
any(MethodCall mc |
5353
mc.getTarget()
54-
.hasQualifiedName("System.Runtime.ExceptionServices.ExceptionDispatchInfo", "Throw") and
54+
.hasQualifiedName("System.Runtime.ExceptionServices", "ExceptionDispatchInfo", "Throw") and
5555
(
5656
mc.hasNoArguments() and
5757
c.getExceptionClass() instanceof SystemExceptionClass
@@ -85,8 +85,8 @@ private class DirectlyExitingCallable extends ExitingCallable {
8585
DirectlyExitingCallable() {
8686
this =
8787
any(Method m |
88-
m.hasQualifiedName("System.Environment", "Exit") or
89-
m.hasQualifiedName("System.Windows.Forms.Application", "Exit")
88+
m.hasQualifiedName("System", "Environment", "Exit") or
89+
m.hasQualifiedName("System.Windows.Forms", "Application", "Exit")
9090
)
9191
}
9292
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/ConstantUtils.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private class ExprNode = ControlFlow::Nodes::ExprNode;
1313
* Holds if `pa` is an access to the `Length` property of an array.
1414
*/
1515
predicate systemArrayLengthAccess(PropertyAccess pa) {
16-
propertyOverrides(pa.getTarget(), "System.Array", "Length")
16+
propertyOverrides(pa.getTarget(), "System", "Array", "Length")
1717
}
1818

1919
/**

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/RangeUtils.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ private module Impl {
150150
/**
151151
* Holds if property `p` matches `property` in `baseClass` or any overrides.
152152
*/
153-
predicate propertyOverrides(Property p, string baseClass, string property) {
153+
predicate propertyOverrides(Property p, string namespace, string baseClass, string property) {
154154
exists(Property p2 |
155-
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(baseClass) and
155+
p2.getUnboundDeclaration().getDeclaringType().hasQualifiedName(namespace, baseClass) and
156156
p2.hasName(property)
157157
|
158158
p.overridesOrImplementsOrEquals(p2)

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ private module Impl {
8383
*/
8484
predicate containerSizeAccess(ExprNode e) {
8585
exists(Property p | p = e.getExpr().(PropertyAccess).getTarget() |
86-
propertyOverrides(p, "System.Collections.Generic.IEnumerable<>", "Count") or
87-
propertyOverrides(p, "System.Collections.ICollection", "Count") or
88-
propertyOverrides(p, "System.String", "Length") or
89-
propertyOverrides(p, "System.Array", "Length")
86+
propertyOverrides(p, "System.Collections.Generic", "IEnumerable<>", "Count") or
87+
propertyOverrides(p, "System.Collections", "ICollection", "Count") or
88+
propertyOverrides(p, "System", "String", "Length") or
89+
propertyOverrides(p, "System", "Array", "Length")
9090
)
9191
or
9292
e.getExpr() instanceof CountCall

csharp/ql/lib/semmle/code/csharp/frameworks/Dapper.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private import semmle.code.csharp.frameworks.system.Data
99
module Dapper {
1010
/** The namespace `Dapper`. */
1111
class DapperNamespace extends Namespace {
12-
DapperNamespace() { this.hasQualifiedName("Dapper") }
12+
DapperNamespace() { this.hasQualifiedName("", "Dapper") }
1313
}
1414

1515
/** A class in `Dapper`. */

csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module DataAnnotations {
2020
class NotMappedAttribute extends Attribute {
2121
NotMappedAttribute() {
2222
this.getType()
23-
.hasQualifiedName("System.ComponentModel.DataAnnotations.Schema.NotMappedAttribute")
23+
.hasQualifiedName("System.ComponentModel.DataAnnotations.Schema", "NotMappedAttribute")
2424
}
2525
}
2626
}

csharp/ql/lib/semmle/code/csharp/frameworks/Format.qll

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@ class FormatMethod extends Method {
2727
or
2828
(this.hasName("Write") or this.hasName("WriteLine")) and
2929
(
30-
declType.hasQualifiedName("System.Console")
30+
declType.hasQualifiedName("System", "Console")
3131
or
32-
declType.hasQualifiedName("System.IO.TextWriter")
32+
declType.hasQualifiedName("System.IO", "TextWriter")
3333
or
34-
declType.hasQualifiedName("System.Diagnostics.Debug") and
34+
declType.hasQualifiedName("System.Diagnostics", "Debug") and
3535
this.getParameter(1).getType() instanceof ArrayType
3636
)
3737
or
38-
declType.hasQualifiedName("System.Diagnostics.Trace") and
38+
declType.hasQualifiedName("System.Diagnostics", "Trace") and
3939
(
4040
this.hasName("TraceError") or
4141
this.hasName("TraceInformation") or
4242
this.hasName("TraceWarning")
4343
)
4444
or
4545
this.hasName("TraceInformation") and
46-
declType.hasQualifiedName("System.Diagnostics.TraceSource")
46+
declType.hasQualifiedName("System.Diagnostics", "TraceSource")
4747
or
4848
this.hasName("Print") and
49-
declType.hasQualifiedName("System.Diagnostics.Debug")
49+
declType.hasQualifiedName("System.Diagnostics", "Debug")
5050
)
5151
or
5252
this.hasName("Assert") and
53-
declType.hasQualifiedName("System.Diagnostics.Debug") and
53+
declType.hasQualifiedName("System.Diagnostics", "Debug") and
5454
this.getNumberOfParameters() = 4
5555
)
5656
}
@@ -65,7 +65,7 @@ class FormatMethod extends Method {
6565
else
6666
if
6767
this.hasName("Assert") and
68-
this.getDeclaringType().hasQualifiedName("System.Diagnostics.Debug")
68+
this.getDeclaringType().hasQualifiedName("System.Diagnostics", "Debug")
6969
then result = 2
7070
else result = 0
7171
}

csharp/ql/lib/semmle/code/csharp/frameworks/JsonNET.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import csharp
88
module JsonNET {
99
/** The namespace `Newtonsoft.Json`. */
1010
class JsonNETNamespace extends Namespace {
11-
JsonNETNamespace() { this.hasQualifiedName("Newtonsoft.Json") }
11+
JsonNETNamespace() { this.hasQualifiedName("Newtonsoft", "Json") }
1212
}
1313

1414
/** A class in `Newtonsoft.Json`. */

csharp/ql/lib/semmle/code/csharp/frameworks/Moq.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import csharp
44

55
/** The `Moq.Language` Namespace. */
66
class MoqLanguageNamespace extends Namespace {
7-
MoqLanguageNamespace() { this.hasQualifiedName("Moq.Language") }
7+
MoqLanguageNamespace() { this.hasQualifiedName("Moq", "Language") }
88
}
99

1010
/**

csharp/ql/lib/semmle/code/csharp/frameworks/NHibernate.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module NHibernate {
1414

1515
/** The interface `NHibernamte.ISession`. */
1616
class ISessionInterface extends Interface {
17-
ISessionInterface() { this.hasQualifiedName("NHibernate.ISession") }
17+
ISessionInterface() { this.hasQualifiedName("NHibernate", "ISession") }
1818

1919
/** Gets a parameter that uses a mapped object. */
2020
Parameter getAMappedObjectParameter() {

csharp/ql/lib/semmle/code/csharp/frameworks/Sql.qll

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ class IDbCommandConstructionSqlExpr extends SqlExpr, ObjectCreation {
3434
exists(InstanceConstructor ic | ic = this.getTarget() |
3535
ic.getDeclaringType().getABaseType*() instanceof SystemDataIDbCommandInterface and
3636
ic.getParameter(0).getType() instanceof StringType and
37-
not ic.getDeclaringType()
38-
.hasQualifiedName([
39-
// Known sealed classes:
40-
"System.Data.SqlClient.SqlCommand", "System.Data.Odbc.OdbcCommand",
41-
"System.Data.OleDb.OleDbCommand", "System.Data.EntityClient.EntityCommand",
42-
"System.Data.SQLite.SQLiteCommand"
43-
])
37+
not exists(Type t | t = ic.getDeclaringType() |
38+
// Known sealed classes:
39+
t.hasQualifiedName("System.Data.SqlClient", "SqlCommand") or
40+
t.hasQualifiedName("System.Data.Odbc", "OdbcCommand") or
41+
t.hasQualifiedName("System.Data.OleDb", "OleDbCommand") or
42+
t.hasQualifiedName("System.Data.EntityClient", "EntityCommand") or
43+
t.hasQualifiedName("System.Data.SQLite", "SQLiteCommand")
44+
)
4445
)
4546
}
4647

csharp/ql/lib/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class MicrosoftAspNetCoreMvcController extends Class {
217217
.getType()
218218
.getABaseType*()
219219
// ApiControllerAttribute is derived from ControllerAttribute
220-
.hasQualifiedName("Microsoft.AspNetCore.Mvc.ControllerAttribute")
220+
.hasQualifiedName("Microsoft.AspNetCore.Mvc", "ControllerAttribute")
221221
) and
222222
not this.getABaseType*().getAnAttribute() instanceof
223223
MicrosoftAspNetCoreMvcNonControllerAttribute
@@ -288,7 +288,7 @@ class MicrosoftAspNetCoreHttpHttpResponse extends Class {
288288
/** An interface that is a wrapper around the collection of cookies in the response. */
289289
class MicrosoftAspNetCoreHttpResponseCookies extends Interface {
290290
MicrosoftAspNetCoreHttpResponseCookies() {
291-
this.hasQualifiedName("Microsoft.AspNetCore.Http.IResponseCookies")
291+
this.hasQualifiedName("Microsoft.AspNetCore.Http", "IResponseCookies")
292292
}
293293

294294
/** Gets the `Append` method. */

0 commit comments

Comments
 (0)