Skip to content

Commit 81c8cac

Browse files
committed
C#: Add partial model printer for TargetApi class.
1 parent 9c6ed0a commit 81c8cac

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

csharp/ql/src/utils/model-generator/ModelGeneratorUtilsSpecific.qll

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,42 @@ class TargetAPI extends Callable {
1010
isRelevantForModels(this)
1111
}
1212
}
13+
14+
private string parameterQualifiedTypeNamesToString(TargetAPI api) {
15+
result =
16+
concat(Parameter p, int i |
17+
p = api.getParameter(i)
18+
|
19+
p.getType().getQualifiedName(), "," order by i
20+
)
21+
}
22+
23+
/** Holds if the summary should apply for all overrides of this. */
24+
private predicate isBaseCallableOrPrototype(TargetAPI api) {
25+
api.getDeclaringType() instanceof Interface
26+
or
27+
exists(Modifiable m | m = [api.(Modifiable), api.(Accessor).getDeclaration()] |
28+
m.isAbstract()
29+
or
30+
api.getDeclaringType().(Modifiable).isAbstract() and m.(Virtualizable).isVirtual()
31+
)
32+
}
33+
34+
/** Gets a string representing, whether the summary should apply for all overrides of this. */
35+
private string getCallableOverride(TargetAPI api) {
36+
if isBaseCallableOrPrototype(api) then result = "true" else result = "false"
37+
}
38+
39+
/** Computes the first 6 columns for CSV rows. */
40+
string asPartialModel(TargetAPI api) {
41+
exists(string namespace, string type |
42+
api.getDeclaringType().hasQualifiedName(namespace, type) and
43+
result =
44+
namespace + ";" //
45+
+ type + ";" //
46+
+ getCallableOverride(api) + ";" //
47+
+ api.getName() + ";" //
48+
+ "(" + parameterQualifiedTypeNamesToString(api) + ")" //
49+
+ /* ext + */ ";" //
50+
)
51+
}

0 commit comments

Comments
 (0)