Skip to content

Commit f1a596e

Browse files
committed
Fix code review findings
1 parent 62f5af9 commit f1a596e

File tree

6 files changed

+24
-43
lines changed

6 files changed

+24
-43
lines changed

csharp/extractor/Semmle.Extraction.CSharp/SymbolExtensions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,6 @@ private static void BuildNamedTypeDisplayName(this INamedTypeSymbol namedType, C
482482
{
483483
trapFile.Write(TrapExtensions.EncodeString(namedType.Name));
484484
}
485-
486-
if (namedType.IsGenericType && namedType.TypeKind != TypeKind.Error && namedType.TypeArguments.Any())
487-
{
488-
var args = string.Join(',', namedType.TypeArguments.Select(ta => ta.MetadataName));
489-
490-
cx.Extractor.Logger.Log(Util.Logging.Severity.Debug, $"Found generic type '{namedType.MetadataName}' with type arguments '{args}', skipping type arguments in type name.");
491-
}
492485
}
493486

494487
public static bool IsReallyUnbound(this INamedTypeSymbol type) =>

csharp/ql/src/definitions.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ private class TypeMentionUse extends Use, TypeMention {
158158
Use.super.hasLocationInfo(filepath, startline, startcolumn, endline, _) and
159159
endcolumn =
160160
startcolumn +
161-
this.getType().(ConstructedType).getUnboundGeneric().getNameWithoutBrackets().length() - 1
161+
this.getType().(ConstructedType).getUnboundGeneric().getUndecoratedName().length() - 1
162162
or
163163
Use.super.hasLocationInfo(filepath, startline, startcolumn, endline, _) and
164-
endcolumn =
165-
startcolumn + this.getType().(UnboundGenericType).getNameWithoutBrackets().length() - 1
164+
endcolumn = startcolumn + this.getType().(UnboundGenericType).getUndecoratedName().length() - 1
166165
or
167166
not this.getType() instanceof ConstructedType and
168167
not this.getType() instanceof UnboundGenericType and

csharp/ql/src/semmle/code/csharp/AnnotatedType.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class AnnotatedConstructedType extends AnnotatedType {
407407

408408
override string toString() {
409409
result =
410-
annotations.getTypePrefix() + type.getUnboundGeneric().getNameWithoutBrackets() + "<" +
410+
annotations.getTypePrefix() + type.getUnboundGeneric().getUndecoratedName() + "<" +
411411
this.getTypeArgumentsString() + ">" + annotations.getTypeSuffix()
412412
}
413413

csharp/ql/src/semmle/code/csharp/Generics.qll

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,23 @@ class UnboundGenericType extends ValueOrRefType, UnboundGeneric {
116116
}
117117

118118
override string toStringWithTypes() {
119-
result = this.getNameWithoutBrackets() + "<" + this.typeParametersToString() + ">"
119+
result = this.getUndecoratedName() + "<" + this.typeParametersToString() + ">"
120120
}
121121

122122
final override string getName() {
123-
result = this.getNameWithoutBrackets() + "<" + this.getTypeParameterCommas() + ">"
123+
result = this.getUndecoratedName() + "<" + this.getTypeParameterCommas() + ">"
124124
}
125125

126126
final override predicate hasQualifiedName(string qualifier, string name) {
127127
exists(string name0 | name = name0 + "<" + this.getTypeParameterCommas() + ">" |
128128
exists(string enclosing |
129129
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
130-
name0 = enclosing + "+" + this.getNameWithoutBrackets()
130+
name0 = enclosing + "+" + this.getUndecoratedName()
131131
)
132132
or
133133
not exists(this.getDeclaringType()) and
134134
qualifier = this.getNamespace().getQualifiedName() and
135-
name0 = this.getNameWithoutBrackets()
135+
name0 = this.getUndecoratedName()
136136
)
137137
}
138138
}
@@ -348,8 +348,8 @@ class UnboundGenericDelegateType extends DelegateType, UnboundGenericType {
348348

349349
override string toStringWithTypes() {
350350
result =
351-
getNameWithoutBrackets() + "<" + this.typeParametersToString() + ">(" +
352-
parameterTypesToString() + ")"
351+
getUndecoratedName() + "<" + this.typeParametersToString() + ">(" + parameterTypesToString() +
352+
")"
353353
}
354354
}
355355

@@ -400,29 +400,23 @@ class ConstructedType extends ValueOrRefType, ConstructedGeneric {
400400
}
401401

402402
final override string toStringWithTypes() {
403-
exists(string undecorated |
404-
types(this, _, undecorated) and
405-
result = undecorated + "<" + this.getTypeArgumentsString() + ">"
406-
)
403+
result = this.getUndecoratedName() + "<" + this.getTypeArgumentsString() + ">"
407404
}
408405

409406
final override string getName() {
410-
exists(string undecorated |
411-
types(this, _, undecorated) and
412-
result = undecorated + "<" + this.getTypeArgumentsNames() + ">"
413-
)
407+
result = this.getUndecoratedName() + "<" + this.getTypeArgumentsNames() + ">"
414408
}
415409

416410
final override predicate hasQualifiedName(string qualifier, string name) {
417411
exists(string name0 | name = name0 + "<" + this.getTypeArgumentsQualifiedNames() + ">" |
418412
exists(string enclosing |
419413
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
420-
name0 = enclosing + "+" + this.getNameWithoutBrackets()
414+
name0 = enclosing + "+" + this.getUndecoratedName()
421415
)
422416
or
423417
not exists(this.getDeclaringType()) and
424418
qualifier = this.getNamespace().getQualifiedName() and
425-
name0 = this.getNameWithoutBrackets()
419+
name0 = this.getUndecoratedName()
426420
)
427421
}
428422
}

csharp/ql/src/semmle/code/csharp/Type.qll

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ private predicate isObjectClass(Class c) { c instanceof ObjectType }
5555
* Either a value type (`ValueType`) or a reference type (`RefType`).
5656
*/
5757
class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_or_ref_type {
58-
/** Gets the name of this type without `<...>` brackets, in case it is a generic type. */
59-
string getNameWithoutBrackets() { types(this, _, result) }
58+
/**
59+
* DEPRECATED: use `getUndecoratedName()` instead
60+
*
61+
* Gets the name of this type without `<...>` brackets, in case it is a generic type.
62+
*/
63+
deprecated string getNameWithoutBrackets() { types(this, _, result) }
6064

6165
/**
6266
* Holds if this type has the qualified name `qualifier`.`name`.
@@ -67,12 +71,12 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
6771
override predicate hasQualifiedName(string qualifier, string name) {
6872
exists(string enclosing |
6973
this.getDeclaringType().hasQualifiedName(qualifier, enclosing) and
70-
name = enclosing + "+" + this.getNameWithoutBrackets()
74+
name = enclosing + "+" + this.getUndecoratedName()
7175
)
7276
or
7377
not exists(this.getDeclaringType()) and
7478
qualifier = this.getNamespace().getQualifiedName() and
75-
name = this.getNameWithoutBrackets()
79+
name = this.getUndecoratedName()
7680
}
7781

7882
/** Gets the namespace containing this type. */
@@ -86,16 +90,7 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
8690

8791
override ValueOrRefType getDeclaringType() { none() }
8892

89-
override string getUndecoratedName() {
90-
if this.getName().indexOf("<") > 0
91-
then
92-
exists(string name, int p |
93-
name = this.getName() and p = min(int p2 | p2 = name.indexOf("<") and p2 > 0)
94-
|
95-
result = name.substring(0, p)
96-
)
97-
else result = this.getName()
98-
}
93+
override string getUndecoratedName() { types(this, _, result) }
9994

10095
/** Gets a nested child type, if any. */
10196
NestedType getAChildType() { nested_types(result, this, _) }

csharp/ql/src/semmle/code/csharp/frameworks/system/data/Entity.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module SystemDataEntity {
3939
/** The `System.Data.Entity.DbSet` class. */
4040
class DbSet extends Class {
4141
DbSet() {
42-
this.getUnboundDeclaration().(csharp::UnboundGenericClass).getNameWithoutBrackets() = "DbSet"
42+
this.getUnboundDeclaration().(csharp::UnboundGenericClass).getUndecoratedName() = "DbSet"
4343
}
4444

4545
/** Gets the `SqlQuery` method. */
@@ -100,7 +100,7 @@ module SystemDataEntityInfrastructure {
100100
this.getABaseType*()
101101
.getUnboundDeclaration()
102102
.(csharp::UnboundGenericClass)
103-
.getNameWithoutBrackets() = "DbRawSqlQuery"
103+
.getUndecoratedName() = "DbRawSqlQuery"
104104
}
105105
}
106106
}

0 commit comments

Comments
 (0)