Skip to content

Commit 5efbcc4

Browse files
author
Tomas Lukac
committed
fix for DeepSource analysis
1 parent 54180a4 commit 5efbcc4

File tree

3 files changed

+65
-61
lines changed

3 files changed

+65
-61
lines changed

src/NHibernate/Linq/ExpressionTransformers/EnumEqualsTransformer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ public class EnumEqualsTransformer : IExpressionTransformer<MethodCallExpression
1313
{
1414
public ExpressionType[] SupportedExpressionTypes => _supportedExpressionTypes;
1515

16-
private static readonly ExpressionType[] _supportedExpressionTypes = new[]
17-
{
18-
ExpressionType.Call
19-
};
16+
private static readonly ExpressionType[] _supportedExpressionTypes = { ExpressionType.Call };
2017

2118
public Expression Transform(MethodCallExpression expression)
2219
{
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Linq.Expressions;
6+
using System.Reflection;
7+
using NHibernate.Util;
8+
using Remotion.Linq.EagerFetching.Parsing;
9+
using Remotion.Linq.Parsing.Structure;
10+
using Remotion.Linq.Parsing.Structure.NodeTypeProviders;
11+
12+
namespace NHibernate.Linq
13+
{
14+
public class NHibernateNodeTypeProvider : INodeTypeProvider
15+
{
16+
private INodeTypeProvider defaultNodeTypeProvider;
17+
18+
public NHibernateNodeTypeProvider()
19+
{
20+
var methodInfoRegistry = new MethodInfoBasedNodeTypeRegistry();
21+
22+
methodInfoRegistry.Register(
23+
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.Fetch, default(IQueryable<object>), default(Expression<Func<object, object>>)) },
24+
typeof(FetchOneExpressionNode));
25+
methodInfoRegistry.Register(
26+
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.FetchLazyProperties, default(IQueryable<object>)) },
27+
typeof(FetchLazyPropertiesExpressionNode));
28+
methodInfoRegistry.Register(
29+
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.FetchMany, default(IQueryable<object>), default(Expression<Func<object, IEnumerable<object>>>)) },
30+
typeof(FetchManyExpressionNode));
31+
methodInfoRegistry.Register(
32+
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.ThenFetch, default(INhFetchRequest<object, object>), default(Expression<Func<object, object>>)) },
33+
typeof(ThenFetchOneExpressionNode));
34+
methodInfoRegistry.Register(
35+
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.ThenFetchMany, default(INhFetchRequest<object, object>), default(Expression<Func<object, IEnumerable<object>>>)) },
36+
typeof(ThenFetchManyExpressionNode));
37+
methodInfoRegistry.Register(
38+
new[]
39+
{
40+
ReflectHelper.FastGetMethodDefinition(LinqExtensionMethods.WithLock, default(IQueryable<object>), default(LockMode)),
41+
ReflectHelper.FastGetMethodDefinition(LinqExtensionMethods.WithLock, default(IEnumerable<object>), default(LockMode))
42+
},
43+
typeof(LockExpressionNode));
44+
45+
var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider();
46+
nodeTypeProvider.InnerProviders.Add(methodInfoRegistry);
47+
defaultNodeTypeProvider = nodeTypeProvider;
48+
}
49+
50+
public bool IsRegistered(MethodInfo method)
51+
{
52+
// Avoid Relinq turning IDictionary.Contains into ContainsResultOperator. We do our own processing for that method.
53+
if (method.DeclaringType == typeof(IDictionary) && method.Name == "Contains")
54+
return false;
55+
56+
return defaultNodeTypeProvider.IsRegistered(method);
57+
}
58+
59+
public System.Type GetNodeType(MethodInfo method)
60+
{
61+
return defaultNodeTypeProvider.GetNodeType(method);
62+
}
63+
}
64+
}

src/NHibernate/Linq/NhRelinqQueryParser.cs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
4-
using System.Linq;
53
using System.Linq.Expressions;
6-
using System.Reflection;
74
using NHibernate.Linq.ExpressionTransformers;
85
using NHibernate.Linq.Visitors;
9-
using NHibernate.Util;
106
using Remotion.Linq;
11-
using Remotion.Linq.EagerFetching.Parsing;
127
using Remotion.Linq.Parsing.ExpressionVisitors.Transformation;
138
using Remotion.Linq.Parsing.Structure;
149
using Remotion.Linq.Parsing.Structure.ExpressionTreeProcessors;
15-
using Remotion.Linq.Parsing.Structure.NodeTypeProviders;
1610

1711
namespace NHibernate.Linq
1812
{
@@ -91,55 +85,4 @@ internal static Func<Expression, Expression> CreatePreTransformer(IExpressionTra
9185
return new TransformingExpressionTreeProcessor(preTransformerRegistry).Process;
9286
}
9387
}
94-
95-
public class NHibernateNodeTypeProvider : INodeTypeProvider
96-
{
97-
private INodeTypeProvider defaultNodeTypeProvider;
98-
99-
public NHibernateNodeTypeProvider()
100-
{
101-
var methodInfoRegistry = new MethodInfoBasedNodeTypeRegistry();
102-
103-
methodInfoRegistry.Register(
104-
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.Fetch, default(IQueryable<object>), default(Expression<Func<object, object>>)) },
105-
typeof(FetchOneExpressionNode));
106-
methodInfoRegistry.Register(
107-
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.FetchLazyProperties, default(IQueryable<object>)) },
108-
typeof(FetchLazyPropertiesExpressionNode));
109-
methodInfoRegistry.Register(
110-
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.FetchMany, default(IQueryable<object>), default(Expression<Func<object, IEnumerable<object>>>)) },
111-
typeof(FetchManyExpressionNode));
112-
methodInfoRegistry.Register(
113-
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.ThenFetch, default(INhFetchRequest<object, object>), default(Expression<Func<object, object>>)) },
114-
typeof(ThenFetchOneExpressionNode));
115-
methodInfoRegistry.Register(
116-
new[] { ReflectHelper.FastGetMethodDefinition(EagerFetchingExtensionMethods.ThenFetchMany, default(INhFetchRequest<object, object>), default(Expression<Func<object, IEnumerable<object>>>)) },
117-
typeof(ThenFetchManyExpressionNode));
118-
methodInfoRegistry.Register(
119-
new[]
120-
{
121-
ReflectHelper.FastGetMethodDefinition(LinqExtensionMethods.WithLock, default(IQueryable<object>), default(LockMode)),
122-
ReflectHelper.FastGetMethodDefinition(LinqExtensionMethods.WithLock, default(IEnumerable<object>), default(LockMode))
123-
},
124-
typeof(LockExpressionNode));
125-
126-
var nodeTypeProvider = ExpressionTreeParser.CreateDefaultNodeTypeProvider();
127-
nodeTypeProvider.InnerProviders.Add(methodInfoRegistry);
128-
defaultNodeTypeProvider = nodeTypeProvider;
129-
}
130-
131-
public bool IsRegistered(MethodInfo method)
132-
{
133-
// Avoid Relinq turning IDictionary.Contains into ContainsResultOperator. We do our own processing for that method.
134-
if (method.DeclaringType == typeof(IDictionary) && method.Name == "Contains")
135-
return false;
136-
137-
return defaultNodeTypeProvider.IsRegistered(method);
138-
}
139-
140-
public System.Type GetNodeType(MethodInfo method)
141-
{
142-
return defaultNodeTypeProvider.GetNodeType(method);
143-
}
144-
}
14588
}

0 commit comments

Comments
 (0)