Skip to content

Commit 123fe5e

Browse files
Jami CogswellJami Cogswell
authored andcommitted
C#: add isParameterless predicate to Constructor class
1 parent cde93a3 commit 123fe5e

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ class Constructor extends DotNet::Constructor, Callable, Member, Attributable, @
358358
if this.isStatic() then result = this.getParameter(i) else result = this.getParameter(i - 1)
359359
}
360360

361+
/** Holds if this is a constructor without parameters. */
362+
predicate isParameterless() { this.getNumberOfParameters() = 0 }
363+
361364
override string getUndecoratedName() { result = ".ctor" }
362365
}
363366

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ class TestLibrary extends RefType {
2424
}
2525
}
2626

27-
/** Holds if the given callable is a constructor without parameters. */
28-
private predicate isParameterlessConstructor(DotNet::Callable c) {
29-
c instanceof Constructor and c.getNumberOfParameters() = 0
30-
}
31-
3227
/** Holds if the given callable is part of a common testing library or framework. */
3328
private predicate isTestLibrary(DotNet::Callable c) { c.getDeclaringType() instanceof TestLibrary }
3429

3530
/** Holds if the given callable is not worth supporting. */
3631
private predicate isUninteresting(DotNet::Callable c) {
37-
isTestLibrary(c) or isParameterlessConstructor(c)
32+
isTestLibrary(c) or
33+
c.(Constructor).isParameterless()
3834
}
3935

4036
/**

0 commit comments

Comments
 (0)