mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
C#: Replace more uses of getQualifiedName/0.
This commit is contained in:
@@ -1,26 +1,42 @@
|
||||
import cil
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
import semmle.code.cil.Type
|
||||
|
||||
private string elementType(Element e, string toString) {
|
||||
toString = e.(Method).getQualifiedName() and result = "method"
|
||||
or
|
||||
toString = e.(Property).getQualifiedName() and result = "property"
|
||||
exists(string namespace, string type, string name |
|
||||
toString = printQualifiedName(namespace, type, name)
|
||||
|
|
||||
e.(Method).hasQualifiedName(namespace, type, name) and result = "method"
|
||||
or
|
||||
e.(Property).hasQualifiedName(namespace, type, name) and result = "property"
|
||||
)
|
||||
or
|
||||
e =
|
||||
any(Parameter p |
|
||||
toString = "Parameter " + p.getIndex() + " of " + p.getDeclaringElement().getQualifiedName()
|
||||
exists(string namespace, string name |
|
||||
p.getDeclaringElement().hasQualifiedName(namespace, name)
|
||||
|
|
||||
toString = "Parameter " + p.getIndex() + " of " + printQualifiedName(namespace, name)
|
||||
)
|
||||
) and
|
||||
result = "parameter"
|
||||
or
|
||||
e =
|
||||
any(LocalVariable v |
|
||||
toString =
|
||||
"Local variable " + v.getIndex() + " of method " +
|
||||
v.getImplementation().getMethod().getQualifiedName()
|
||||
exists(string namespace, string type, string name |
|
||||
v.getImplementation().getMethod().hasQualifiedName(namespace, type, name)
|
||||
|
|
||||
toString =
|
||||
"Local variable " + v.getIndex() + " of method " +
|
||||
printQualifiedName(namespace, type, name)
|
||||
)
|
||||
) and
|
||||
result = "local"
|
||||
or
|
||||
toString = e.(FunctionPointerType).getQualifiedName() and result = "fnptr"
|
||||
exists(string namespace, string name | e.(FunctionPointerType).hasQualifiedName(namespace, name) |
|
||||
toString = printQualifiedName(namespace, name)
|
||||
) and
|
||||
result = "fnptr"
|
||||
or
|
||||
not e instanceof Method and
|
||||
not e instanceof Property and
|
||||
@@ -53,7 +69,9 @@ where
|
||||
(
|
||||
not e instanceof Parameter
|
||||
or
|
||||
e.(Parameter).getDeclaringElement().(Method).getDeclaringType().getQualifiedName() !=
|
||||
"System.Environment" // There are OS specific methods in this class
|
||||
not exists(Type t |
|
||||
t = e.(Parameter).getDeclaringElement().(Method).getDeclaringType() and
|
||||
t.hasQualifiedName("System", "Environment")
|
||||
) // There are OS specific methods in this class
|
||||
)
|
||||
select toString, type, i
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import cil
|
||||
import semmle.code.csharp.commons.Disposal
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from CIL::Field field
|
||||
from CIL::Field field, string namespace, string name
|
||||
where
|
||||
mayBeDisposed(field) and
|
||||
field.getDeclaringType().hasQualifiedName("DisposalTests", "Class1")
|
||||
select field.getQualifiedName()
|
||||
field.getDeclaringType().hasQualifiedName("DisposalTests", "Class1") and
|
||||
field.hasQualifiedName(namespace, name)
|
||||
select printQualifiedName(namespace, name)
|
||||
|
||||
@@ -5,5 +5,5 @@ from DotNet::Callable c, DotNet::Parameter param, int p
|
||||
where
|
||||
mayBeDisposed(param) and
|
||||
param = c.getParameter(p) and
|
||||
c.getDeclaringType().getQualifiedName() = "DisposalTests.Class1"
|
||||
c.getDeclaringType().hasQualifiedName("DisposalTests", "Class1")
|
||||
select c.toStringWithTypes(), p
|
||||
|
||||
@@ -6,5 +6,5 @@ from DotNet::Callable c, DotNet::Parameter param, int p
|
||||
where
|
||||
not mayBeDisposed(param) and
|
||||
param = c.getParameter(p) and
|
||||
c.getDeclaringType().getQualifiedName() = "DisposalTests.Class1"
|
||||
c.getDeclaringType().hasQualifiedName("DisposalTests", "Class1")
|
||||
select c.toStringWithTypes(), p
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from Destructor c
|
||||
from Destructor c, string namespace, string name
|
||||
where
|
||||
c.getDeclaringType().getName() = "Class" and
|
||||
c.getDeclaringType().getNamespace().getQualifiedName() = "Constructors"
|
||||
c.getDeclaringType().hasQualifiedName(namespace, name) and
|
||||
namespace = "Constructors" and
|
||||
name = "Class"
|
||||
select c, c.getDeclaringType().getQualifiedName()
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
from Method m, Method overrider
|
||||
from
|
||||
Method m, Method overrider, string mnamespace, string mtype, string mname, string onamespace,
|
||||
string otype, string oname
|
||||
where
|
||||
m.getAnOverrider() = overrider and
|
||||
m.getFile().getStem() = "CovariantReturn"
|
||||
select m.getQualifiedName(), m.getReturnType().toString(), overrider.getQualifiedName(),
|
||||
overrider.getReturnType().toString()
|
||||
m.getFile().getStem() = "CovariantReturn" and
|
||||
m.hasQualifiedName(mnamespace, mtype, mname) and
|
||||
overrider.hasQualifiedName(onamespace, otype, oname)
|
||||
select printQualifiedName(mnamespace, mtype, mname), m.getReturnType().toString(),
|
||||
printQualifiedName(onamespace, otype, oname), overrider.getReturnType().toString()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
private string getLocation(Member m) {
|
||||
if m.fromSource() then result = m.getALocation().(SourceLocation).toString() else result = "-"
|
||||
@@ -8,8 +9,13 @@ private string getIsAsync(ForeachStmt f) {
|
||||
if f.isAsync() then result = "async" else result = "sync"
|
||||
}
|
||||
|
||||
from ForeachStmt f
|
||||
select f, f.getElementType().toString(), getIsAsync(f),
|
||||
f.getGetEnumerator().getDeclaringType().getQualifiedName(), getLocation(f.getGetEnumerator()),
|
||||
f.getCurrent().getDeclaringType().getQualifiedName(), getLocation(f.getCurrent()),
|
||||
f.getMoveNext().getDeclaringType().getQualifiedName(), getLocation(f.getMoveNext())
|
||||
from
|
||||
ForeachStmt f, string namespace1, string type1, string namespace2, string type2,
|
||||
string namespace3, string type3
|
||||
where
|
||||
f.getGetEnumerator().getDeclaringType().hasQualifiedName(namespace1, type1) and
|
||||
f.getCurrent().getDeclaringType().hasQualifiedName(namespace2, type2) and
|
||||
f.getMoveNext().getDeclaringType().hasQualifiedName(namespace3, type3)
|
||||
select f, f.getElementType().toString(), getIsAsync(f), printQualifiedName(namespace1, type1),
|
||||
getLocation(f.getGetEnumerator()), printQualifiedName(namespace2, type2),
|
||||
getLocation(f.getCurrent()), printQualifiedName(namespace3, type3), getLocation(f.getMoveNext())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
query predicate records(RecordClass t, string i, RecordCloneMethod clone) {
|
||||
t.getABaseInterface().toStringWithTypes() = i and
|
||||
@@ -7,7 +8,9 @@ query predicate records(RecordClass t, string i, RecordCloneMethod clone) {
|
||||
}
|
||||
|
||||
private string getMemberName(Member m) {
|
||||
result = m.getDeclaringType().getQualifiedName() + "." + m.toStringWithTypes()
|
||||
exists(string namespace, string name | m.getDeclaringType().hasQualifiedName(namespace, name) |
|
||||
result = printQualifiedName(namespace, name) + "." + m.toStringWithTypes()
|
||||
)
|
||||
}
|
||||
|
||||
query predicate members(RecordClass t, string ms, string l) {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.QualifiedName
|
||||
|
||||
private string getSignature(Method m) {
|
||||
result = m.getDeclaringType().getQualifiedName() + "." + m.toStringWithTypes()
|
||||
exists(string namespace, string name | m.getDeclaringType().hasQualifiedName(namespace, name) |
|
||||
result = printQualifiedName(namespace, name) + "." + m.toStringWithTypes()
|
||||
)
|
||||
}
|
||||
|
||||
query predicate withExpr(WithExpr with, string type, Expr expr, ObjectInitializer init, string clone) {
|
||||
|
||||
Reference in New Issue
Block a user