Skip to content

Commit c3fe88e

Browse files
Merge pull request #362 from brandhuf/remove_string_overloads_from_most_fluent_methods
Marking soon to be removed methods in the fluent api as obsolete
2 parents 850064c + 55ec99f commit c3fe88e

File tree

64 files changed

+2516
-2523
lines changed

Some content is hidden

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

64 files changed

+2516
-2523
lines changed
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,59 @@
1+
using System;
12
using System.Linq;
23

34
namespace ArchUnitNET.Domain.Extensions
45
{
56
public static class AttributeExtensions
67
{
8+
[Obsolete(
9+
"Either HasAttribute() without the useRegularExpressions parameter or HasAttributeMatching() should be used"
10+
)]
711
public static bool HasAttribute(
812
this IHasAttributes a,
913
string pattern,
10-
bool useRegularExpressions = false
14+
bool useRegularExpressions
1115
)
1216
{
1317
return a.Attributes.Any(attribute =>
1418
attribute.FullNameMatches(pattern, useRegularExpressions)
1519
);
1620
}
1721

22+
public static bool HasAttribute(this IHasAttributes a, string fullName)
23+
{
24+
return a.Attributes.Any(attribute => attribute.FullNameEquals(fullName));
25+
}
26+
27+
[Obsolete(
28+
"Either OnlyHasAttributes() without the useRegularExpressions parameter or OnlyHasAttributesMatching() should be used"
29+
)]
1830
public static bool OnlyHasAttributes(
1931
this IHasAttributes a,
2032
string pattern,
21-
bool useRegularExpressions = false
33+
bool useRegularExpressions
2234
)
2335
{
2436
return a.Attributes.IsNullOrEmpty()
2537
|| a.Attributes.All(attribute =>
2638
attribute.FullNameMatches(pattern, useRegularExpressions)
2739
);
2840
}
41+
42+
public static bool HasAttributeMatching(this IHasAttributes a, string pattern)
43+
{
44+
return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern));
45+
}
46+
47+
public static bool OnlyHasAttributes(this IHasAttributes a, string name)
48+
{
49+
return a.Attributes.IsNullOrEmpty()
50+
|| a.Attributes.All(attribute => attribute.FullNameEquals(name));
51+
}
52+
53+
public static bool OnlyHasAttributesMatching(this IHasAttributes a, string pattern)
54+
{
55+
return a.Attributes.IsNullOrEmpty()
56+
|| a.Attributes.All(attribute => attribute.FullNameMatches(pattern));
57+
}
2958
}
3059
}

ArchUnitNET/Domain/Extensions/DependencyExtensions.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using ArchUnitNET.Domain.Dependencies;
@@ -6,16 +7,29 @@ namespace ArchUnitNET.Domain.Extensions
67
{
78
public static class DependencyExtensions
89
{
10+
[Obsolete(
11+
"Either CallsMethod() without the useRegularExpressions parameter or CallsMethodMatching() should be used"
12+
)]
913
public static bool CallsMethod(
1014
this IHasDependencies type,
1115
string pattern,
12-
bool useRegularExpressions = false
16+
bool useRegularExpressions
1317
)
1418
{
1519
return type.GetCalledMethods()
1620
.Any(member => member.FullNameMatches(pattern, useRegularExpressions));
1721
}
1822

23+
public static bool CallsMethod(this IHasDependencies type, string fullName)
24+
{
25+
return type.GetCalledMethods().Any(member => member.FullNameEquals(fullName));
26+
}
27+
28+
public static bool CallsMethodMatching(this IHasDependencies type, string pattern)
29+
{
30+
return type.GetCalledMethods().Any(member => member.FullNameMatches(pattern));
31+
}
32+
1933
public static IEnumerable<MethodMember> GetCalledMethods(this IHasDependencies type)
2034
{
2135
return type
@@ -30,6 +44,9 @@ public static IEnumerable<FieldMember> GetAccessedFieldMembers(this IHasDependen
3044
.Select(dependency => (FieldMember)dependency.TargetMember);
3145
}
3246

47+
[Obsolete(
48+
"Either DependsOnType() without the useRegularExpressions parameter or DependsOnTypeMatching() should be used"
49+
)]
3350
public static bool DependsOn(
3451
this IHasDependencies c,
3552
string pattern,
@@ -40,6 +57,19 @@ public static bool DependsOn(
4057
.Any(d => d.FullNameMatches(pattern, useRegularExpressions));
4158
}
4259

60+
public static bool DependsOnType(this IHasDependencies c, string fullName)
61+
{
62+
return c.GetTypeDependencies().Any(d => d.FullNameEquals(fullName));
63+
}
64+
65+
public static bool DependsOnTypeMatching(this IHasDependencies c, string pattern)
66+
{
67+
return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern));
68+
}
69+
70+
[Obsolete(
71+
"Either OnlyDependsOnType() without the useRegularExpressions parameter or OnlyDependsOnTypesMatching() should be used"
72+
)]
4373
public static bool OnlyDependsOn(
4474
this IHasDependencies c,
4575
string pattern,
@@ -50,6 +80,16 @@ public static bool OnlyDependsOn(
5080
.All(d => d.FullNameMatches(pattern, useRegularExpressions));
5181
}
5282

83+
public static bool OnlyDependsOnType(this IHasDependencies c, string fullName)
84+
{
85+
return c.GetTypeDependencies().All(d => d.FullNameEquals(fullName));
86+
}
87+
88+
public static bool OnlyDependsOnTypesMatching(this IHasDependencies c, string pattern)
89+
{
90+
return c.GetTypeDependencies().All(d => d.FullNameMatches(pattern));
91+
}
92+
5393
public static IEnumerable<IType> GetTypeDependencies(this IHasDependencies c)
5494
{
5595
return c.Dependencies.Select(dependency => dependency.Target);

ArchUnitNET/Domain/Extensions/MemberExtensions.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34
using ArchUnitNET.Domain.Dependencies;
@@ -6,15 +7,28 @@ namespace ArchUnitNET.Domain.Extensions
67
{
78
public static class MemberExtensions
89
{
10+
[Obsolete(
11+
"Either IsDeclaredIn() without the useRegularExpressions parameter or IsDeclaredInTypeMatching() should be used"
12+
)]
913
public static bool IsDeclaredIn(
1014
this IMember member,
1115
string pattern,
12-
bool useRegularExpressions = false
16+
bool useRegularExpressions
1317
)
1418
{
1519
return member.DeclaringType.FullNameMatches(pattern, useRegularExpressions);
1620
}
1721

22+
public static bool IsDeclaredIn(this IMember member, string fullName)
23+
{
24+
return member.DeclaringType.FullNameEquals(fullName);
25+
}
26+
27+
public static bool IsDeclaredInTypeMatching(this IMember member, string pattern)
28+
{
29+
return member.DeclaringType.FullNameMatches(pattern);
30+
}
31+
1832
public static bool IsDeclaredIn(this IMember member, IType type)
1933
{
2034
return member.DeclaringType.Equals(type);
@@ -56,6 +70,9 @@ public static bool HasMethodCallDependencies(
5670
return member.GetMethodCallDependencies(getBackwardsDependencies).Any();
5771
}
5872

73+
[Obsolete(
74+
"Either IsCalledByType() without the useRegularExpressions parameter or IsCalledByTypeMatching() should be used"
75+
)]
5976
public static bool IsCalledBy(
6077
this MethodMember member,
6178
string pattern,
@@ -69,6 +86,20 @@ public static bool IsCalledBy(
6986
);
7087
}
7188

89+
public static bool IsCalledByType(this MethodMember member, string fullName)
90+
{
91+
return member
92+
.GetMethodCallDependencies(true)
93+
.Any(dependency => dependency.Origin.FullNameEquals(fullName));
94+
}
95+
96+
public static bool IsCalledByTypeMatching(this MethodMember member, string pattern)
97+
{
98+
return member
99+
.GetMethodCallDependencies(true)
100+
.Any(dependency => dependency.Origin.FullNameMatches(pattern));
101+
}
102+
72103
public static IEnumerable<IType> GetCallingTypes(this MethodMember member)
73104
{
74105
return member
@@ -77,6 +108,9 @@ public static IEnumerable<IType> GetCallingTypes(this MethodMember member)
77108
.Distinct();
78109
}
79110

111+
[Obsolete(
112+
"Either HasDependencyInMethodBodyToType() without the useRegularExpressions parameter or HasDependencyInMethodBodyToTypeMatching() should be used"
113+
)]
80114
public static bool HasDependencyInMethodBodyTo(
81115
this MethodMember member,
82116
string pattern,
@@ -90,6 +124,26 @@ public static bool HasDependencyInMethodBodyTo(
90124
);
91125
}
92126

127+
public static bool HasDependencyInMethodBodyToType(
128+
this MethodMember member,
129+
string fullName
130+
)
131+
{
132+
return member
133+
.GetBodyTypeMemberDependencies()
134+
.Any(dependency => dependency.Target.FullNameEquals(fullName));
135+
}
136+
137+
public static bool HasDependencyInMethodBodyToTypeMatching(
138+
this MethodMember member,
139+
string pattern
140+
)
141+
{
142+
return member
143+
.GetBodyTypeMemberDependencies()
144+
.Any(dependency => dependency.Target.FullNameMatches(pattern));
145+
}
146+
93147
public static bool HasFieldTypeDependencies(
94148
this IMember member,
95149
bool getBackwardsDependencies = false

ArchUnitNET/Domain/Extensions/NamingExtensions.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ public static bool NameContains(
3636
return cls.Name.IndexOf(pattern, stringComparison) >= 0;
3737
}
3838

39+
[Obsolete(
40+
"Either NameEquals() or NameMatches() without the useRegularExpressions parameter should be used"
41+
)]
3942
public static bool NameMatches(
4043
this IHasName cls,
4144
string pattern,
42-
bool useRegularExpressions = false
45+
bool useRegularExpressions
4346
)
4447
{
4548
if (useRegularExpressions)
@@ -50,10 +53,23 @@ public static bool NameMatches(
5053
return string.Equals(cls.Name, pattern, StringComparison.OrdinalIgnoreCase);
5154
}
5255

56+
public static bool NameEquals(this IHasName cls, string name)
57+
{
58+
return string.Equals(cls.Name, name, StringComparison.OrdinalIgnoreCase);
59+
}
60+
61+
public static bool NameMatches(this IHasName cls, string pattern)
62+
{
63+
return pattern != null && Regex.IsMatch(cls.Name, pattern);
64+
}
65+
66+
[Obsolete(
67+
"Either FullNameEquals() or FullNameMatches() without the useRegularExpressions parameter should be used"
68+
)]
5369
public static bool FullNameMatches(
5470
this IHasName cls,
5571
string pattern,
56-
bool useRegularExpressions = false
72+
bool useRegularExpressions
5773
)
5874
{
5975
if (useRegularExpressions)
@@ -64,6 +80,16 @@ public static bool FullNameMatches(
6480
return string.Equals(cls.FullName, pattern, StringComparison.OrdinalIgnoreCase);
6581
}
6682

83+
public static bool FullNameEquals(this IHasName cls, string fullName)
84+
{
85+
return string.Equals(cls.FullName, fullName, StringComparison.OrdinalIgnoreCase);
86+
}
87+
88+
public static bool FullNameMatches(this IHasName cls, string pattern)
89+
{
90+
return pattern != null && Regex.IsMatch(cls.FullName, pattern);
91+
}
92+
6793
public static bool FullNameContains(this IHasName cls, string pattern)
6894
{
6995
return pattern != null && cls.FullName.ToLower().Contains(pattern.ToLower());

0 commit comments

Comments
 (0)