Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fbc128f

Browse files
committed
C#: Fix type parameter names
1 parent 2e350ca commit fbc128f

9 files changed

Lines changed: 61 additions & 58 deletions

File tree

csharp/extractor/Semmle.Extraction.CIL/CachedFunction.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ namespace Semmle.Extraction.CIL
77
/// A factory and a cache for mapping source entities to target entities.
88
/// Could be considered as a memoizer.
99
/// </summary>
10-
/// <typeparam name="SrcType">The type of the source.</typeparam>
11-
/// <typeparam name="TargetType">The type of the generated object.</typeparam>
12-
public class CachedFunction<SrcType, TargetType> where SrcType : notnull
10+
/// <typeparam name="TSrc">The type of the source.</typeparam>
11+
/// <typeparam name="TTarget">The type of the generated object.</typeparam>
12+
public class CachedFunction<TSrc, TTarget> where TSrc : notnull
1313
{
14-
private readonly Func<SrcType, TargetType> generator;
15-
private readonly Dictionary<SrcType, TargetType> cache;
14+
private readonly Func<TSrc, TTarget> generator;
15+
private readonly Dictionary<TSrc, TTarget> cache;
1616

1717
/// <summary>
1818
/// Initializes the factory with a given mapping.
1919
/// </summary>
2020
/// <param name="g">The mapping.</param>
21-
public CachedFunction(Func<SrcType, TargetType> g)
21+
public CachedFunction(Func<TSrc, TTarget> g)
2222
{
2323
generator = g;
24-
cache = new Dictionary<SrcType, TargetType>();
24+
cache = new Dictionary<TSrc, TTarget>();
2525
}
2626

2727
/// <summary>
@@ -30,7 +30,7 @@ public CachedFunction(Func<SrcType, TargetType> g)
3030
/// </summary>
3131
/// <param name="src">The source object.</param>
3232
/// <returns>The created object.</returns>
33-
public TargetType this[SrcType src]
33+
public TTarget this[TSrc src]
3434
{
3535
get
3636
{
@@ -47,22 +47,22 @@ public TargetType this[SrcType src]
4747
/// <summary>
4848
/// A factory for mapping a pair of source entities to a target entity.
4949
/// </summary>
50-
/// <typeparam name="Src1">Source entity type 1.</typeparam>
51-
/// <typeparam name="Src2">Source entity type 2.</typeparam>
52-
/// <typeparam name="Target">The target type.</typeparam>
53-
public class CachedFunction<Src1, Src2, Target>
50+
/// <typeparam name="TSrcEntity1">Source entity type 1.</typeparam>
51+
/// <typeparam name="TSrcEntity2">Source entity type 2.</typeparam>
52+
/// <typeparam name="TTarget">The target type.</typeparam>
53+
public class CachedFunction<TSrcEntity1, TSrcEntity2, TTarget>
5454
{
55-
private readonly CachedFunction<(Src1, Src2), Target> factory;
55+
private readonly CachedFunction<(TSrcEntity1, TSrcEntity2), TTarget> factory;
5656

5757
/// <summary>
5858
/// Initializes the factory with a given mapping.
5959
/// </summary>
6060
/// <param name="g">The mapping.</param>
61-
public CachedFunction(Func<Src1, Src2, Target> g)
61+
public CachedFunction(Func<TSrcEntity1, TSrcEntity2, TTarget> g)
6262
{
63-
factory = new CachedFunction<(Src1, Src2), Target>(p => g(p.Item1, p.Item2));
63+
factory = new CachedFunction<(TSrcEntity1, TSrcEntity2), TTarget>(p => g(p.Item1, p.Item2));
6464
}
6565

66-
public Target this[Src1 s1, Src2 s2] => factory[(s1, s2)];
66+
public TTarget this[TSrcEntity1 s1, TSrcEntity2 s2] => factory[(s1, s2)];
6767
}
6868
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ public static ExprKind AdjustKind(this Expression.CallType ct, ExprKind k)
291291
}
292292
}
293293

294-
internal abstract class Expression<SyntaxNode> : Expression
295-
where SyntaxNode : ExpressionSyntax
294+
internal abstract class Expression<TExpressionSyntax> : Expression
295+
where TExpressionSyntax : ExpressionSyntax
296296
{
297-
public readonly SyntaxNode Syntax;
297+
public readonly TExpressionSyntax Syntax;
298298

299299
protected Expression(ExpressionNodeInfo info)
300300
: base(info)
301301
{
302-
Syntax = (SyntaxNode)info.Node;
302+
Syntax = (TExpressionSyntax)info.Node;
303303
}
304304

305305
/// <summary>

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ArrayCreation.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace Semmle.Extraction.CSharp.Entities.Expressions
99
{
10-
internal abstract class ArrayCreation<SyntaxNode> : Expression<SyntaxNode> where SyntaxNode : ExpressionSyntax
10+
internal abstract class ArrayCreation<TSyntaxNode> : Expression<TSyntaxNode>
11+
where TSyntaxNode : ExpressionSyntax
1112
{
1213
protected ArrayCreation(ExpressionNodeInfo info) : base(info) { }
1314
}
1415

15-
internal abstract class ExplicitArrayCreation<SyntaxNode> : ArrayCreation<SyntaxNode> where SyntaxNode : ExpressionSyntax
16+
internal abstract class ExplicitArrayCreation<TSyntaxNode> : ArrayCreation<TSyntaxNode>
17+
where TSyntaxNode : ExpressionSyntax
1618
{
1719
protected ExplicitArrayCreation(ExpressionNodeInfo info) : base(info.SetKind(ExprKind.ARRAY_CREATION)) { }
1820

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ObjectCreation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
namespace Semmle.Extraction.CSharp.Entities.Expressions
1010
{
11-
internal abstract class ObjectCreation<SyntaxNode> : Expression<SyntaxNode> where SyntaxNode : ExpressionSyntax
11+
internal abstract class ObjectCreation<TExpressionSyntax> : Expression<TExpressionSyntax>
12+
where TExpressionSyntax : ExpressionSyntax
1213
{
1314
protected ObjectCreation(ExpressionNodeInfo info)
1415
: base(info) { }

csharp/extractor/Semmle.Extraction/Context.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ private void CheckEntityHasUniqueLabel(string id, ICachedEntity entity)
8888

8989
public Label GetNewLabel() => new Label(GetNewId());
9090

91-
public Entity CreateEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, object cacheKey, Type init)
92-
where Entity : ICachedEntity =>
91+
public TEntity CreateEntity<TInit, TEntity>(ICachedEntityFactory<TInit, TEntity> factory, object cacheKey, TInit init)
92+
where TEntity : ICachedEntity =>
9393
cacheKey is ISymbol s ? CreateEntity(factory, s, init, symbolEntityCache) : CreateEntity(factory, cacheKey, init, objectEntityCache);
9494

95-
public Entity CreateEntityFromSymbol<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init)
96-
where Type : ISymbol
97-
where Entity : ICachedEntity => CreateEntity(factory, init, init, symbolEntityCache);
95+
public TEntity CreateEntityFromSymbol<TSymbol, TEntity>(ICachedEntityFactory<TSymbol, TEntity> factory, TSymbol init)
96+
where TSymbol : ISymbol
97+
where TEntity : ICachedEntity => CreateEntity(factory, init, init, symbolEntityCache);
9898

9999
/// <summary>
100100
/// Creates and populates a new entity, or returns the existing one from the cache.
@@ -104,12 +104,12 @@ public Entity CreateEntityFromSymbol<Type, Entity>(ICachedEntityFactory<Type, En
104104
/// <param name="init">The initializer for the entity.</param>
105105
/// <param name="dictionary">The dictionary to use for caching.</param>
106106
/// <returns>The new/existing entity.</returns>
107-
private Entity CreateEntity<Type, CacheKeyType, Entity>(ICachedEntityFactory<Type, Entity> factory, CacheKeyType cacheKey, Type init, IDictionary<CacheKeyType, ICachedEntity> dictionary)
108-
where CacheKeyType : notnull
109-
where Entity : ICachedEntity
107+
private TEntity CreateEntity<TInit, TCacheKey, TEntity>(ICachedEntityFactory<TInit, TEntity> factory, TCacheKey cacheKey, TInit init, IDictionary<TCacheKey, ICachedEntity> dictionary)
108+
where TCacheKey : notnull
109+
where TEntity : ICachedEntity
110110
{
111111
if (dictionary.TryGetValue(cacheKey, out var cached))
112-
return (Entity)cached;
112+
return (TEntity)cached;
113113

114114
using (StackGuard)
115115
{

csharp/extractor/Semmle.Extraction/Entity.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public interface ICachedEntity : IEntity
9898
/// <summary>
9999
/// A factory for creating cached entities.
100100
/// </summary>
101-
/// <typeparam name="Initializer">The type of the initializer.</typeparam>
102-
public interface ICachedEntityFactory<in Initializer, out Entity> where Entity : ICachedEntity
101+
/// <typeparam name="TInit">The type of the initializer.</typeparam>
102+
public interface ICachedEntityFactory<in TInit, out TEntity> where TEntity : ICachedEntity
103103
{
104104
/// <summary>
105105
/// Initializes the entity, but does not generate any trap code.
106106
/// </summary>
107-
Entity Create(Context cx, Initializer init);
107+
TEntity Create(Context cx, TInit init);
108108
}
109109

110110
public static class ICachedEntityFactoryExtensions
@@ -113,29 +113,29 @@ public static class ICachedEntityFactoryExtensions
113113
/// Creates and populates a new entity, or returns the existing one from the cache,
114114
/// based on the supplied cache key.
115115
/// </summary>
116-
/// <typeparam name="Type">The type used to construct the entity.</typeparam>
117-
/// <typeparam name="Entity">The type of the entity to create.</typeparam>
116+
/// <typeparam name="TInit">The type used to construct the entity.</typeparam>
117+
/// <typeparam name="TEntity">The type of the entity to create.</typeparam>
118118
/// <param name="factory">The factory used to construct the entity.</param>
119119
/// <param name="cx">The extractor context.</param>
120120
/// <param name="cacheKey">The key used for caching.</param>
121121
/// <param name="init">The initializer for the entity.</param>
122122
/// <returns>The entity.</returns>
123-
public static Entity CreateEntity<Type, Entity>(this ICachedEntityFactory<Type, Entity> factory, Context cx, object cacheKey, Type init)
124-
where Entity : ICachedEntity => cx.CreateEntity(factory, cacheKey, init);
123+
public static TEntity CreateEntity<TInit, TEntity>(this ICachedEntityFactory<TInit, TEntity> factory, Context cx, object cacheKey, TInit init)
124+
where TEntity : ICachedEntity => cx.CreateEntity(factory, cacheKey, init);
125125

126126
/// <summary>
127127
/// Creates and populates a new entity from an `ISymbol`, or returns the existing one
128128
/// from the cache.
129129
/// </summary>
130-
/// <typeparam name="Type">The type used to construct the entity.</typeparam>
131-
/// <typeparam name="Entity">The type of the entity to create.</typeparam>
130+
/// <typeparam name="TSymbol">The type used to construct the entity.</typeparam>
131+
/// <typeparam name="TEntity">The type of the entity to create.</typeparam>
132132
/// <param name="factory">The factory used to construct the entity.</param>
133133
/// <param name="cx">The extractor context.</param>
134134
/// <param name="init">The initializer for the entity.</param>
135135
/// <returns>The entity.</returns>
136-
public static Entity CreateEntityFromSymbol<Type, Entity>(this ICachedEntityFactory<Type, Entity> factory, Context cx, Type init)
137-
where Type : ISymbol
138-
where Entity : ICachedEntity => cx.CreateEntityFromSymbol(factory, init);
136+
public static TEntity CreateEntityFromSymbol<TSymbol, TEntity>(this ICachedEntityFactory<TSymbol, TEntity> factory, Context cx, TSymbol init)
137+
where TSymbol : ISymbol
138+
where TEntity : ICachedEntity => cx.CreateEntityFromSymbol(factory, init);
139139

140140
public static void DefineLabel(this IEntity entity, TextWriter trapFile, IExtractor extractor)
141141
{

csharp/extractor/Semmle.Extraction/Symbol.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace Semmle.Extraction
66
/// <summary>
77
/// An abstract symbol, which encapsulates a data type (such as a C# symbol).
88
/// </summary>
9-
/// <typeparam name="Initializer">The type of the symbol.</typeparam>
10-
public abstract class CachedEntity<Initializer> : ICachedEntity
9+
/// <typeparam name="TSymbol">The type of the symbol.</typeparam>
10+
public abstract class CachedEntity<TSymbol> : ICachedEntity
1111
{
12-
protected CachedEntity(Context context, Initializer init)
12+
protected CachedEntity(Context context, TSymbol init)
1313
{
1414
Context = context;
1515
symbol = init;
@@ -41,14 +41,14 @@ public Context Context
4141
get;
4242
}
4343

44-
public Initializer symbol
44+
public TSymbol symbol
4545
{
4646
get;
4747
}
4848

4949
object? ICachedEntity.UnderlyingObject => symbol;
5050

51-
public Initializer UnderlyingObject => symbol;
51+
public TSymbol UnderlyingObject => symbol;
5252

5353
public abstract void WriteId(System.IO.TextWriter trapFile);
5454

@@ -68,7 +68,7 @@ public abstract bool NeedsPopulation
6868

6969
public override bool Equals(object? obj)
7070
{
71-
var other = obj as CachedEntity<Initializer>;
71+
var other = obj as CachedEntity<TSymbol>;
7272
return other?.GetType() == GetType() && Equals(other.symbol, symbol);
7373
}
7474

csharp/extractor/Semmle.Util/ActionMap.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ namespace Semmle.Util
77
/// A dictionary which performs an action when items are added to the dictionary.
88
/// The order in which keys and actions are added does not matter.
99
/// </summary>
10-
/// <typeparam name="Key"></typeparam>
11-
/// <typeparam name="Value"></typeparam>
12-
public class ActionMap<Key, Value> where Key : notnull
10+
/// <typeparam name="TKey"></typeparam>
11+
/// <typeparam name="TValue"></typeparam>
12+
public class ActionMap<TKey, TValue> where TKey : notnull
1313
{
14-
public void Add(Key key, Value value)
14+
public void Add(TKey key, TValue value)
1515
{
1616

1717
if (actions.TryGetValue(key, out var a))
1818
a(value);
1919
values[key] = value;
2020
}
2121

22-
public void OnAdd(Key key, Action<Value> action)
22+
public void OnAdd(TKey key, Action<TValue> action)
2323
{
2424
if (actions.TryGetValue(key, out var a))
2525
{
@@ -37,9 +37,9 @@ public void OnAdd(Key key, Action<Value> action)
3737
}
3838

3939
// Action associated with each key.
40-
private readonly Dictionary<Key, Action<Value>> actions = new Dictionary<Key, Action<Value>>();
40+
private readonly Dictionary<TKey, Action<TValue>> actions = new Dictionary<TKey, Action<TValue>>();
4141

4242
// Values associated with each key.
43-
private readonly Dictionary<Key, Value> values = new Dictionary<Key, Value>();
43+
private readonly Dictionary<TKey, TValue> values = new Dictionary<TKey, TValue>();
4444
}
4545
}

csharp/extractor/Semmle.Util/FuzzyDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Add(string k, T v)
6161
/// <param name="v1">Vector 1</param>
6262
/// <param name="v2">Vector 2</param>
6363
/// <returns>The Hamming Distance.</returns>
64-
private static int HammingDistance<U>(IEnumerable<U> v1, IEnumerable<U> v2) where U : notnull
64+
private static int HammingDistance<TElement>(IEnumerable<TElement> v1, IEnumerable<TElement> v2) where TElement : notnull
6565
{
6666
return v1.Zip(v2, (x, y) => x.Equals(y) ? 0 : 1).Sum();
6767
}

0 commit comments

Comments
 (0)