C#: Share qualified name module for model editor queries

This commit is contained in:
Koen Vlaswinkel
2023-12-13 13:48:44 +01:00
parent ea504cddd1
commit e177f8783a
2 changed files with 17 additions and 15 deletions

View File

@@ -269,7 +269,7 @@ private predicate elementSpec(
UnboundValueOrRefType t
) {
elementSpec(namespace, type, subtypes, name, signature, ext) and
QN::hasQualifiedName(t, namespace, type)
hasQualifiedTypeName(t, namespace, type)
}
private class UnboundValueOrRefType extends ValueOrRefType {
@@ -337,7 +337,7 @@ Declaration interpretBaseDeclaration(string namespace, string type, string name,
exists(UnboundValueOrRefType t | elementSpec(namespace, type, _, name, signature, _, t) |
result =
any(Declaration d |
QN::hasQualifiedName(d, namespace, type, name) and
hasQualifiedMethodName(d, namespace, type, name) and
(
signature = ""
or
@@ -439,6 +439,19 @@ private module QualifiedNameInput implements QualifiedNameInputSig {
private module QN = QualifiedName<QualifiedNameInput>;
/** Holds if declaration `d` has the qualified name `qualifier`.`name`. */
predicate hasQualifiedTypeName(Type t, string namespace, string type) {
QN::hasQualifiedName(t, namespace, type)
}
/**
* Holds if declaration `d` has name `name` and is defined in type `type`
* with namespace `namespace`.
*/
predicate hasQualifiedMethodName(Declaration d, string namespace, string type, string name) {
QN::hasQualifiedName(d, namespace, type, name)
}
pragma[nomagic]
private string parameterQualifiedType(Parameter p) {
exists(string qualifier, string name |

View File

@@ -1,7 +1,6 @@
/** Provides classes and predicates related to handling APIs for the VS Code extension. */
private import csharp
private import semmle.code.csharp.commons.QualifiedName
private import semmle.code.csharp.dataflow.FlowSummary
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
private import semmle.code.csharp.dataflow.internal.ExternalFlow
@@ -121,22 +120,12 @@ string methodClassification(Call method) {
* Gets the fully qualified name of the type `t`.
*/
private string qualifiedTypeName(string namespace, Type t) {
exists(string type | QN::hasQualifiedName(t, namespace, type) | result = type)
exists(string type | hasQualifiedTypeName(t, namespace, type) | result = type)
}
/**
* Gets the fully qualified name of the callable `c`.
*/
private string qualifiedCallableName(string namespace, string type, Callable c) {
exists(string name | QN::hasQualifiedName(c, namespace, type, name) | result = name)
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
}
private module QualifiedNameInput implements QualifiedNameInputSig {
string getUnboundGenericSuffix(UnboundGeneric ug) {
result =
"<" + strictconcat(int i, string s | s = ug.getTypeParameter(i).getName() | s, "," order by i)
+ ">"
}
}
private module QN = QualifiedName<QualifiedNameInput>;