Skip to content

Commit c27fdaf

Browse files
authored
Merge pull request #44 from NN---/annotations
Add code annotations.
2 parents 33d2c59 + 130fab0 commit c27fdaf

File tree

68 files changed

+359
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+359
-178
lines changed

CodeJam.Blocks/Mapping/CodeJamConvertException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public CodeJamConvertException(string message)
5050
/// the current exception.</param>
5151
/// <seealso cref="Exception.Message"/>
5252
/// <seealso cref="Exception.InnerException"/>
53-
public CodeJamConvertException(string message, Exception innerException)
53+
public CodeJamConvertException(string message, Exception innerException)
5454
: base(message, innerException)
5555
{
5656
}
@@ -62,7 +62,7 @@ public CodeJamConvertException(string message, Exception innerException)
6262
/// <param name="innerException">The InnerException, if any, that threw
6363
/// the current exception.</param>
6464
/// <seealso cref="Exception.InnerException"/>
65-
public CodeJamConvertException(Exception innerException)
65+
public CodeJamConvertException([NotNull] Exception innerException)
6666
: base(innerException.Message, innerException)
6767
{
6868
}
@@ -76,7 +76,7 @@ public CodeJamConvertException(Exception innerException)
7676
/// destination.</param>
7777
/// <remarks>This constructor is called during deserialization to
7878
/// reconstitute the exception object transmitted over a stream.</remarks>
79-
protected CodeJamConvertException(SerializationInfo info, StreamingContext context)
79+
protected CodeJamConvertException([NotNull] SerializationInfo info, StreamingContext context)
8080
: base(info, context)
8181
{
8282
}

CodeJam.Blocks/Mapping/CodeJamMappingException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if !LESSTHAN_NET40
1+
#if !LESSTHAN_NET40
22
using System;
33
using System.Runtime.Serialization;
44

@@ -60,7 +60,7 @@ public CodeJamMappingException(string message, Exception innerException)
6060
/// <param name="innerException">The InnerException, if any, that threw
6161
/// the current exception.</param>
6262
/// <seealso cref="Exception.InnerException"/>
63-
public CodeJamMappingException(Exception innerException)
63+
public CodeJamMappingException([NotNull] Exception innerException)
6464
: base(innerException.Message, innerException)
6565
{
6666
}
@@ -75,7 +75,7 @@ public CodeJamMappingException(Exception innerException)
7575
/// destination.</param>
7676
/// <remarks>This constructor is called during deserialization to
7777
/// reconstitute the exception object transmitted over a stream.</remarks>
78-
protected CodeJamMappingException(SerializationInfo info, StreamingContext context)
78+
protected CodeJamMappingException([NotNull] SerializationInfo info, StreamingContext context)
7979
: base(info, context)
8080
{
8181
}

CodeJam.Blocks/Mapping/ConvertBuilder.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111
using CodeJam.Collections;
1212
using CodeJam.Expressions;
1313

14+
using JetBrains.Annotations;
15+
1416
namespace CodeJam.Mapping
1517
{
1618
using Reflection;
1719

1820
internal static class ConvertBuilder
1921
{
22+
[NotNull]
2023
private static readonly MethodInfo _defaultConverter = InfoOf.Method(() => ConvertDefault(null, typeof(int)));
2124

22-
private static object ConvertDefault(object value, Type conversionType)
25+
private static object ConvertDefault(object value, [NotNull] Type conversionType)
2326
{
2427
try
2528
{
@@ -31,7 +34,8 @@ private static object ConvertDefault(object value, Type conversionType)
3134
}
3235
}
3336

34-
private static Expression GetCtor(Type from, Type to, Expression p)
37+
[CanBeNull]
38+
private static Expression GetCtor([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
3539
{
3640
var ctor = to.GetConstructor(new[] { from });
3741

@@ -46,7 +50,8 @@ private static Expression GetCtor(Type from, Type to, Expression p)
4650
return Expression.New(ctor, p);
4751
}
4852

49-
private static Expression GetValue(Type from, Type to, Expression p)
53+
[CanBeNull]
54+
private static Expression GetValue([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
5055
{
5156
var pi = from.GetProperty("Value");
5257

@@ -66,7 +71,7 @@ private static Expression GetValue(Type from, Type to, Expression p)
6671
private const BindingFlags _methodLookup =
6772
BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
6873

69-
private static Expression GetOperator(Type from, Type to, Expression p)
74+
private static Expression GetOperator([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
7075
{
7176
var op =
7277
to.GetMethod("op_Implicit", _methodLookup, null, new[] { from }, null) ??
@@ -75,7 +80,7 @@ private static Expression GetOperator(Type from, Type to, Expression p)
7580
return op != null ? Expression.Convert(p, to, op) : null;
7681
}
7782

78-
private static bool IsConvertible(Type type)
83+
private static bool IsConvertible([NotNull] Type type)
7984
{
8085
if (type.IsEnum)
8186
return false;
@@ -99,7 +104,7 @@ private static bool IsConvertible(Type type)
99104
}
100105
}
101106

102-
private static Expression GetConvertion(Type from, Type to, Expression p)
107+
private static Expression GetConvertion([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
103108
{
104109
if (IsConvertible(from) && IsConvertible(to) && to != typeof(bool) ||
105110
from.IsAssignableFrom(to) && to.IsAssignableFrom(from))
@@ -108,7 +113,7 @@ private static Expression GetConvertion(Type from, Type to, Expression p)
108113
return null;
109114
}
110115

111-
private static Expression GetParse(Type from, Type to, Expression p)
116+
private static Expression GetParse([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
112117
{
113118
if (from == typeof(string))
114119
{
@@ -133,7 +138,7 @@ private static Expression GetParse(Type from, Type to, Expression p)
133138
return null;
134139
}
135140

136-
private static Expression GetToString(Type from, Type to, Expression p)
141+
private static Expression GetToString([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
137142
{
138143
if (to == typeof(string) && !from.IsNullable())
139144
{
@@ -150,7 +155,7 @@ private static Expression GetToString(Type from, Type to, Expression p)
150155
return null;
151156
}
152157

153-
private static Expression GetParseEnum(Type from, Type to, Expression p)
158+
private static Expression GetParseEnum([NotNull] Type from, [NotNull] Type to, [NotNull] Expression p)
154159
{
155160
if (from == typeof(string) && to.IsEnum)
156161
{
@@ -210,7 +215,11 @@ into g
210215

211216
private static readonly MethodInfo _throwLinqToDBConvertException = InfoOf.Method(() => ThrowLinqToDBException(null));
212217

213-
private static Expression GetToEnum(Type from, Type to, Expression expression, MappingSchema mappingSchema)
218+
private static Expression GetToEnum(
219+
[NotNull] Type from,
220+
[NotNull] Type to,
221+
[NotNull] Expression expression,
222+
[NotNull] MappingSchema mappingSchema)
214223
{
215224
if (to.IsEnum)
216225
{

CodeJam.Blocks/Mapping/ConvertInfo.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
using System.Collections.Generic;
55
using System.Linq.Expressions;
66

7+
using JetBrains.Annotations;
8+
79
namespace CodeJam.Mapping
810
{
911
internal class ConvertInfo
1012
{
13+
[NotNull]
1114
public static readonly ConvertInfo Default = new ConvertInfo();
1215

1316
public class LambdaInfo
@@ -30,27 +33,28 @@ public LambdaInfo(
3033
public readonly bool IsSchemaSpecific;
3134
}
3235

36+
[NotNull]
3337
private readonly ConcurrentDictionary<Type, ConcurrentDictionary<Type, LambdaInfo>> _expressions =
3438
new ConcurrentDictionary<Type, ConcurrentDictionary<Type, LambdaInfo>>();
3539

36-
public void Set(Type from, Type to, LambdaInfo expr) => Set(_expressions, from, to, expr);
40+
public void Set([NotNull] Type from, [NotNull] Type to, [NotNull] LambdaInfo expr) => Set(_expressions, from, to, expr);
3741

3842
private static void Set(
39-
IDictionary<Type, ConcurrentDictionary<Type, LambdaInfo>> expressions,
40-
Type from,
41-
Type to,
42-
LambdaInfo expr)
43+
[NotNull] IDictionary<Type, ConcurrentDictionary<Type, LambdaInfo>> expressions,
44+
[NotNull] Type from,
45+
[NotNull] Type to,
46+
[NotNull] LambdaInfo expr)
4347
{
4448
if (!expressions.TryGetValue(from, out var dic))
4549
expressions[from] = dic = new ConcurrentDictionary<Type, LambdaInfo>();
4650

4751
dic[to] = expr;
4852
}
4953

50-
public LambdaInfo Get(Type from, Type to) =>
54+
public LambdaInfo Get([NotNull] Type from, [NotNull] Type to) =>
5155
_expressions.TryGetValue(from, out var dic) && dic.TryGetValue(to, out var li) ? li : null;
5256

53-
public LambdaInfo Create(MappingSchema mappingSchema, Type from, Type to)
57+
public LambdaInfo Create([NotNull] MappingSchema mappingSchema, [NotNull] Type from, [NotNull] Type to)
5458
{
5559
var ex = ConvertBuilder.GetConverter(mappingSchema, from, to);
5660
var lm = ex.Item1.Compile();

CodeJam.Blocks/Mapping/ConvertT.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static Expression<Func<TFrom,TTo>> Expression
6262
}
6363
}
6464

65-
private static Func<TFrom,TTo> _lambda;
65+
[NotNull] private static Func<TFrom,TTo> _lambda;
6666

6767
/// <summary>
6868
/// Represents a function that converts a value of <i>TFrom</i> type to <i>TTo</i> type.
@@ -102,6 +102,7 @@ public static Func<TFrom,TTo> Lambda
102102
/// <summary>
103103
/// Returns a function that converts a value of <i>TFrom</i> type to <i>TTo</i> type.
104104
/// </summary>
105+
[NotNull]
105106
public static Func<TFrom,TTo> From => _lambda;
106107
}
107108
}

CodeJam.Blocks/Mapping/DefaultValue.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace CodeJam.Mapping
1616
[PublicAPI]
1717
public static class DefaultValue
1818
{
19+
[NotNull]
1920
private static readonly ConcurrentDictionary<Type,object> _defaultValues = new ConcurrentDictionary<Type,object>
2021
{
2122
[typeof(int)] = default(int),

CodeJam.Blocks/Mapping/DefaultValueExpression.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System;
33
using System.Linq.Expressions;
44

5+
using JetBrains.Annotations;
6+
57
namespace CodeJam.Mapping
68
{
79
internal class DefaultValueExpression : Expression
810
{
9-
public DefaultValueExpression(MappingSchema mappingSchema, Type type)
11+
public DefaultValueExpression([CanBeNull] MappingSchema mappingSchema, [NotNull] Type type)
1012
{
1113
_mappingSchema = mappingSchema;
1214
Type = type;

CodeJam.Blocks/Mapping/ExpressionBuilder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
using CodeJam.Collections;
1010

11+
using JetBrains.Annotations;
12+
1113
using static System.Linq.Expressions.Expression;
1214

1315
// ReSharper disable TailRecursiveCall
@@ -37,11 +39,11 @@ private class BuilderData
3739
public bool IsRestart => RestartCounter > 10;
3840
}
3941

40-
public ExpressionBuilder(IMapperBuilder mapperBuilder, ValueTuple<MemberInfo[],LambdaExpression>[] memberMappers)
42+
public ExpressionBuilder([NotNull] IMapperBuilder mapperBuilder, ValueTuple<MemberInfo[],LambdaExpression>[] memberMappers)
4143
: this(mapperBuilder, new BuilderData(memberMappers)) =>
4244
_processCrossReferences = mapperBuilder.ProcessCrossReferences == true;
4345

44-
private ExpressionBuilder(IMapperBuilder mapperBuilder, BuilderData data)
46+
private ExpressionBuilder([NotNull] IMapperBuilder mapperBuilder, BuilderData data)
4547
{
4648
_mapperBuilder = mapperBuilder;
4749
_data = data;
@@ -50,9 +52,13 @@ private ExpressionBuilder(IMapperBuilder mapperBuilder, BuilderData data)
5052
_processCrossReferences = true;
5153
}
5254

55+
[NotNull]
5356
private readonly IMapperBuilder _mapperBuilder;
57+
[NotNull]
5458
private readonly Type _fromType;
59+
[NotNull]
5560
private readonly Type _toType;
61+
[NotNull]
5662
private readonly BuilderData _data;
5763
private readonly bool _processCrossReferences;
5864

@@ -296,6 +302,7 @@ private MemberAssignment BuildAssignment(
296302

297303
#region GetExpression
298304

305+
[NotNull]
299306
public LambdaExpression GetExpression()
300307
{
301308
var pFrom = Parameter(_fromType, "from");

CodeJam.Blocks/Mapping/IMapperBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public interface IMapperBuilder
7373
/// <summary>
7474
/// Type to map from.
7575
/// </summary>
76-
Type FromType { get; }
76+
[NotNull] Type FromType { get; }
7777

7878
/// <summary>
7979
/// Type to map to.
8080
/// </summary>
81-
Type ToType { get; }
81+
[NotNull] Type ToType { get; }
8282
}
8383
}
8484
#endif

CodeJam.Blocks/Mapping/MapperBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace CodeJam.Mapping
1818
[PublicAPI]
1919
public class MapperBuilder<TFrom, TTo> : IMapperBuilder
2020
{
21+
[NotNull]
2122
private MappingSchema _mappingSchema = MappingSchema.Default;
2223

2324
/// <summary>
@@ -115,6 +116,7 @@ public MapperBuilder<TFrom, TTo> SetMemberFilter([NotNull] Func<MemberAccessor,
115116
/// <param name="memberName">Type member name.</param>
116117
/// <param name="mapName">Mapping name.</param>
117118
/// <returns>Returns this mapper.</returns>
119+
[NotNull]
118120
public MapperBuilder<TFrom, TTo> FromMapping([NotNull] Type type, [NotNull] string memberName, [NotNull] string mapName)
119121
{
120122
Code.NotNull(type, nameof(type));
@@ -270,6 +272,7 @@ public MapperBuilder<TFrom, TTo> ToMapping(IReadOnlyDictionary<string, string> m
270272
/// <param name="memberName">Type member name.</param>
271273
/// <param name="mapName">Mapping name.</param>
272274
/// <returns>Returns this mapper.</returns>
275+
[NotNull]
273276
public MapperBuilder<TFrom, TTo> Mapping(Type type, string memberName, string mapName)
274277
=> FromMapping(type, memberName, mapName).ToMapping(type, memberName, mapName);
275278

@@ -280,6 +283,7 @@ public MapperBuilder<TFrom, TTo> Mapping(Type type, string memberName, string ma
280283
/// <param name="memberName">Type member name.</param>
281284
/// <param name="mapName">Mapping name.</param>
282285
/// <returns>Returns this mapper.</returns>
286+
[NotNull]
283287
public MapperBuilder<TFrom, TTo> Mapping<T>(string memberName, string mapName)
284288
=> Mapping(typeof(T), memberName, mapName);
285289

@@ -289,6 +293,7 @@ public MapperBuilder<TFrom, TTo> Mapping<T>(string memberName, string mapName)
289293
/// <param name="memberName">Type member name.</param>
290294
/// <param name="mapName">Mapping name.</param>
291295
/// <returns>Returns this mapper.</returns>
296+
[NotNull]
292297
public MapperBuilder<TFrom, TTo> Mapping(string memberName, string mapName)
293298
=> Mapping(typeof(TFrom), memberName, mapName).Mapping(typeof(TTo), memberName, mapName);
294299

@@ -298,6 +303,7 @@ public MapperBuilder<TFrom, TTo> Mapping(string memberName, string mapName)
298303
/// <param name="type">Type to map.</param>
299304
/// <param name="mapping">Mapping parameters.</param>
300305
/// <returns>Returns this mapper.</returns>
306+
[NotNull]
301307
public MapperBuilder<TFrom, TTo> Mapping([NotNull] Type type, [NotNull] IReadOnlyDictionary<string, string> mapping)
302308
{
303309
Code.NotNull(type, nameof(type));
@@ -402,6 +408,7 @@ public MapperBuilder<TFrom, TTo> SetDeepCopy(bool? deepCopy)
402408
/// Gets an instance of <see cref="ExpressionBuilder"/> class.
403409
/// </summary>
404410
/// <returns><see cref="ExpressionBuilder"/>.</returns>
411+
[NotNull]
405412
internal ExpressionBuilder GetExpressionMapper()
406413
=> new ExpressionBuilder(this, MemberMappers?.Select(mm => ValueTuple.Create(mm.Item1.GetMembersInfo(), mm.Item2)).ToArray());
407414
}

0 commit comments

Comments
 (0)