Skip to content

Commit e4b96e9

Browse files
committed
C#: Minor improvements to the extractor changes.
1 parent 7f89a30 commit e4b96e9

File tree

7 files changed

+15
-16
lines changed

7 files changed

+15
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ public static bool TryGetExtensionMethod(this IMethodSymbol method, out IMethodS
692692
? extensionDeclaration.Construct(extensionMethodArguments.ToArray())
693693
: extensionDeclaration;
694694
}
695-
catch (Exception)
695+
catch
696696
{
697697
// If anything goes wrong, fall back to the unbound declaration.
698698
declaration = unboundDeclaration;

csharp/extractor/Semmle.Extraction.CSharp/Entities/Method.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal abstract class Method : CachedSymbol<IMethodSymbol>, IExpressionParentE
1414
protected Method(Context cx, IMethodSymbol init)
1515
: base(cx, init) { }
1616

17-
private IParameter? SyntheticParameter { get; set; }
17+
private SyntheticExtensionParameter? SyntheticParameter { get; set; }
1818

1919
private int SynthesizeExtensionParameter()
2020
{
@@ -24,7 +24,7 @@ private int SynthesizeExtensionParameter()
2424
!string.IsNullOrEmpty(parameter.Name) && !Symbol.IsStatic)
2525
{
2626
var originalSyntheticParam = OriginalDefinition.SyntheticParameter;
27-
SyntheticParameter = ImplicitExtensionParameter.Create(Context, this, parameter, originalSyntheticParam);
27+
SyntheticParameter = SyntheticExtensionParameter.Create(Context, this, parameter, originalSyntheticParam);
2828
return 1;
2929
}
3030

csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,22 +258,22 @@ private class VarargsTypeFactory : CachedEntityFactory<string?, VarargsType>
258258
}
259259

260260
/// <summary>
261-
/// Synthetic parameter for extension methods declared using the extensions syntax.
261+
/// Synthetic parameter for extension methods declared using the extension syntax.
262262
/// That is, we add a synthetic parameter s to IsValid in the following example:
263263
/// extension(string s) {
264264
/// public bool IsValid() { ... }
265265
/// }
266266
///
267-
/// Note, that we use the characteristics of the parameter of the associated (compiler generated) extension method
267+
/// Note, that we use the characteristics of the parameter of the extension type
268268
/// to populate the database.
269269
/// </summary>
270-
internal class ImplicitExtensionParameter : FreshEntity, IParameter
270+
internal class SyntheticExtensionParameter : FreshEntity, IParameter
271271
{
272272
private Method ExtensionMethod { get; }
273273
private IParameterSymbol ExtensionParameter { get; }
274-
private IParameter Original { get; }
274+
private SyntheticExtensionParameter Original { get; }
275275

276-
private ImplicitExtensionParameter(Context cx, Method method, IParameterSymbol parameter, IParameter? original) : base(cx)
276+
private SyntheticExtensionParameter(Context cx, Method method, IParameterSymbol parameter, SyntheticExtensionParameter? original) : base(cx)
277277
{
278278
ExtensionMethod = method;
279279
ExtensionParameter = parameter;
@@ -341,9 +341,6 @@ protected override void Populate(TextWriter trapFile)
341341
WriteLocationsToTrap(trapFile.param_location, this, locations);
342342
}
343343

344-
if (!IsSourceDeclaration || !ExtensionParameter.FromSource())
345-
return;
346-
347344
BindComments();
348345

349346
if (IsSourceDeclaration)
@@ -358,9 +355,9 @@ protected override void Populate(TextWriter trapFile)
358355
}
359356
}
360357

361-
public static ImplicitExtensionParameter Create(Context cx, Method method, IParameterSymbol parameter, IParameter? original)
358+
public static SyntheticExtensionParameter Create(Context cx, Method method, IParameterSymbol parameter, SyntheticExtensionParameter? original)
362359
{
363-
var p = new ImplicitExtensionParameter(cx, method, parameter, original);
360+
var p = new SyntheticExtensionParameter(cx, method, parameter, original);
364361
p.TryPopulate();
365362
return p;
366363
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Property.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public override void Populate(TextWriter trapFile)
103103
trapFile.expr_access(access, this);
104104
if (!Symbol.IsStatic)
105105
{
106-
// TODO: What about the containing type for extensions?
107106
This.CreateImplicit(Context, Symbol.ContainingType, Location, access, -1);
108107
}
109108
});

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override void Populate(TextWriter trapFile)
100100
if (!string.IsNullOrEmpty(parameter.Name))
101101
{
102102
var originalType = OriginalDefinition;
103-
// In case the this is constructed generic, we also need to create the unbound parameter.
103+
// In case this is a constructed generic, we also need to create the unbound parameter.
104104
var originalParameter = SymbolEqualityComparer.Default.Equals(Symbol, originalType.Symbol.ExtensionParameter) || originalType.Symbol.ExtensionParameter is null
105105
? null
106106
: Parameter.Create(Context, originalType.Symbol.ExtensionParameter, originalType);

csharp/extractor/Semmle.Extraction.CSharp/Entities/UserOperator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public override Type ContainingType
6868
/// <returns></returns>
6969
private bool IsImplicitOperator(out ITypeSymbol containingType)
7070
{
71-
// TODO: Do we need to handle extension operators here?
7271
containingType = Symbol.ContainingType;
7372
if (containingType is not null)
7473
{

csharp/extractor/Semmle.Util/IEnumerableExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ public static (IEnumerable<T>, IEnumerable<T>) SplitAt<T>(this IEnumerable<T> it
131131
foreach (var item in items)
132132
{
133133
if (i < index)
134+
{
134135
left.Add(item);
136+
}
135137
else
138+
{
136139
right.Add(item);
140+
}
137141
i++;
138142
}
139143
return (left, right);

0 commit comments

Comments
 (0)