Skip to content

Commit 6812389

Browse files
committed
C#: Fix external API name for nested types
This fixes the name of reported external APIs for nested types. The `getDeclaringType().getUnboundDeclaration()`'s `toString()` method reports the name of the type, but not the name of the declaring type. This results in missing information in the `UnsupportedExternalAPIs.ql` query. For example, previously it would report: ``` GitHub.Nested#NestedClass.Test() ``` However, the `NestedClass` class does not exist in the namespace and is only a nested type within `MyFirstClass`. The correct name should be: ``` GitHub.Nested#MyFirstClass+NestedClass.Test() ``` This name also matches the format of MaD.
1 parent 085c85f commit 6812389

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ExternalApi extends DotNet::Callable {
5050
bindingset[this]
5151
private string getSignature() {
5252
result =
53-
this.getDeclaringType().getUnboundDeclaration() + "." + this.getName() + "(" +
53+
nestedName(this.getDeclaringType().getUnboundDeclaration()) + "." + this.getName() + "(" +
5454
parameterQualifiedTypeNamesToString(this) + ")"
5555
}
5656

@@ -118,6 +118,21 @@ class ExternalApi extends DotNet::Callable {
118118
}
119119
}
120120

121+
/**
122+
* Gets the nested name of the declaration.
123+
*
124+
* If the declaration is not a nested type, the result is the same as \`getName()\`.
125+
* Otherwise the name of the nested type is prefixed with a \`+\` and appended to
126+
* the name of the enclosing type, which might be a nested type as well.
127+
*/
128+
private string nestedName(Declaration declaration) {
129+
not exists(declaration.getDeclaringType().getUnboundDeclaration()) and
130+
result = declaration.getName()
131+
or
132+
nestedName(declaration.getDeclaringType().getUnboundDeclaration()) + "+" + declaration.getName() =
133+
result
134+
}
135+
121136
/**
122137
* Gets the limit for the number of results produced by a telemetry query.
123138
*/

0 commit comments

Comments
 (0)