-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathParameters.ql
More file actions
51 lines (44 loc) · 1.64 KB
/
Parameters.ql
File metadata and controls
51 lines (44 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import csharp
private predicate fromTestLocation(Element e) {
e.fromSource() and
e.getFile().getBaseName() = ["Parameters.cs", "LambdaParameters.cs"]
or
e.getFile().getStem() = "Parameters"
}
private predicate compilerGeneratedAttribute(Parameterizable container) {
container.getDeclaringType().getAnAttribute().getType().toStringWithTypes() =
"CompilerGeneratedAttribute"
}
query predicate noDefaultValue(Parameterizable container, Parameter p, int i) {
fromTestLocation(container) and
not p.hasDefaultValue() and
container.getParameter(i) = p and
not compilerGeneratedAttribute(container)
}
private predicate defaultValue(Parameterizable container, Parameter p, int i, Expr e) {
fromTestLocation(container) and
p.hasDefaultValue() and
container.getParameter(i) = p and
p.getDefaultValue() = e
}
query predicate withDefaultValue(Parameterizable container, Parameter p, int i, Expr e, string value) {
defaultValue(container, p, i, e) and
(if exists(e.getValue()) then value = e.getValue() else value = "-") and
not compilerGeneratedAttribute(container)
}
query predicate dateTimeDefaults(
Parameterizable container, Parameter p, ObjectCreation o, string constructor, string value
) {
defaultValue(container, p, _, o) and
o.getTarget().toStringWithTypes() = constructor and
o.getAnArgument().getValue() = value and
not compilerGeneratedAttribute(container)
}
query predicate implicitConversionDefaults(
Parameterizable container, Parameter p, OperatorCall o, Expr e, string type, string value
) {
defaultValue(container, p, _, o) and
o.getAnArgument() = e and
type = e.getType().toString() and
value = e.getValue()
}