Skip to content

Commit 41b7180

Browse files
Merge pull request #380 from TNG/revert-377-feat/remove-obsolete-fluent-syntax-methods
Revert "Remove Obsolete Fluent Syntax Methods"
2 parents 776ebdb + 3f1d279 commit 41b7180

34 files changed

+7467
-24
lines changed

ArchUnitNET/Domain/Extensions/AttributeExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,40 @@ namespace ArchUnitNET.Domain.Extensions
55
{
66
public static class AttributeExtensions
77
{
8+
[Obsolete(
9+
"Either HasAttribute() without the useRegularExpressions parameter or HasAttributeMatching() should be used"
10+
)]
11+
public static bool HasAttribute(
12+
this IHasAttributes a,
13+
string pattern,
14+
bool useRegularExpressions
15+
)
16+
{
17+
return a.Attributes.Any(attribute =>
18+
attribute.FullNameMatches(pattern, useRegularExpressions)
19+
);
20+
}
21+
822
public static bool HasAttribute(this IHasAttributes a, string fullName)
923
{
1024
return a.Attributes.Any(attribute => attribute.FullNameEquals(fullName));
1125
}
1226

27+
[Obsolete(
28+
"Either OnlyHasAttributes() without the useRegularExpressions parameter or OnlyHasAttributesMatching() should be used"
29+
)]
30+
public static bool OnlyHasAttributes(
31+
this IHasAttributes a,
32+
string pattern,
33+
bool useRegularExpressions
34+
)
35+
{
36+
return a.Attributes.IsNullOrEmpty()
37+
|| a.Attributes.All(attribute =>
38+
attribute.FullNameMatches(pattern, useRegularExpressions)
39+
);
40+
}
41+
1342
public static bool HasAttributeMatching(this IHasAttributes a, string pattern)
1443
{
1544
return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern));

ArchUnitNET/Domain/Extensions/DependencyExtensions.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ namespace ArchUnitNET.Domain.Extensions
77
{
88
public static class DependencyExtensions
99
{
10+
[Obsolete(
11+
"Either CallsMethod() without the useRegularExpressions parameter or CallsMethodMatching() should be used"
12+
)]
13+
public static bool CallsMethod(
14+
this IHasDependencies type,
15+
string pattern,
16+
bool useRegularExpressions
17+
)
18+
{
19+
return type.GetCalledMethods()
20+
.Any(member => member.FullNameMatches(pattern, useRegularExpressions));
21+
}
22+
1023
public static bool CallsMethod(this IHasDependencies type, string fullName)
1124
{
1225
return type.GetCalledMethods().Any(member => member.FullNameEquals(fullName));
@@ -31,6 +44,19 @@ public static IEnumerable<FieldMember> GetAccessedFieldMembers(this IHasDependen
3144
.Select(dependency => (FieldMember)dependency.TargetMember);
3245
}
3346

47+
[Obsolete(
48+
"Either DependsOnType() without the useRegularExpressions parameter or DependsOnTypeMatching() should be used"
49+
)]
50+
public static bool DependsOn(
51+
this IHasDependencies c,
52+
string pattern,
53+
bool useRegularExpressions = false
54+
)
55+
{
56+
return c.GetTypeDependencies()
57+
.Any(d => d.FullNameMatches(pattern, useRegularExpressions));
58+
}
59+
3460
public static bool DependsOnType(this IHasDependencies c, string fullName)
3561
{
3662
return c.GetTypeDependencies().Any(d => d.FullNameEquals(fullName));
@@ -41,6 +67,19 @@ public static bool DependsOnTypeMatching(this IHasDependencies c, string pattern
4167
return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern));
4268
}
4369

70+
[Obsolete(
71+
"Either OnlyDependsOnType() without the useRegularExpressions parameter or OnlyDependsOnTypesMatching() should be used"
72+
)]
73+
public static bool OnlyDependsOn(
74+
this IHasDependencies c,
75+
string pattern,
76+
bool useRegularExpressions = false
77+
)
78+
{
79+
return c.GetTypeDependencies()
80+
.All(d => d.FullNameMatches(pattern, useRegularExpressions));
81+
}
82+
4483
public static bool OnlyDependsOnType(this IHasDependencies c, string fullName)
4584
{
4685
return c.GetTypeDependencies().All(d => d.FullNameEquals(fullName));

ArchUnitNET/Domain/Extensions/MemberExtensions.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ namespace ArchUnitNET.Domain.Extensions
77
{
88
public static class MemberExtensions
99
{
10+
[Obsolete(
11+
"Either IsDeclaredIn() without the useRegularExpressions parameter or IsDeclaredInTypeMatching() should be used"
12+
)]
13+
public static bool IsDeclaredIn(
14+
this IMember member,
15+
string pattern,
16+
bool useRegularExpressions
17+
)
18+
{
19+
return member.DeclaringType.FullNameMatches(pattern, useRegularExpressions);
20+
}
21+
1022
public static bool IsDeclaredIn(this IMember member, string fullName)
1123
{
1224
return member.DeclaringType.FullNameEquals(fullName);
@@ -58,6 +70,22 @@ public static bool HasMethodCallDependencies(
5870
return member.GetMethodCallDependencies(getBackwardsDependencies).Any();
5971
}
6072

73+
[Obsolete(
74+
"Either IsCalledByType() without the useRegularExpressions parameter or IsCalledByTypeMatching() should be used"
75+
)]
76+
public static bool IsCalledBy(
77+
this MethodMember member,
78+
string pattern,
79+
bool useRegularExpressions = false
80+
)
81+
{
82+
return member
83+
.GetMethodCallDependencies(true)
84+
.Any(dependency =>
85+
dependency.Origin.FullNameMatches(pattern, useRegularExpressions)
86+
);
87+
}
88+
6189
public static bool IsCalledByType(this MethodMember member, string fullName)
6290
{
6391
return member
@@ -80,6 +108,22 @@ public static IEnumerable<IType> GetCallingTypes(this MethodMember member)
80108
.Distinct();
81109
}
82110

111+
[Obsolete(
112+
"Either HasDependencyInMethodBodyToType() without the useRegularExpressions parameter or HasDependencyInMethodBodyToTypeMatching() should be used"
113+
)]
114+
public static bool HasDependencyInMethodBodyTo(
115+
this MethodMember member,
116+
string pattern,
117+
bool useRegularExpressions = false
118+
)
119+
{
120+
return member
121+
.GetBodyTypeMemberDependencies()
122+
.Any(dependency =>
123+
dependency.Target.FullNameMatches(pattern, useRegularExpressions)
124+
);
125+
}
126+
83127
public static bool HasDependencyInMethodBodyToType(
84128
this MethodMember member,
85129
string fullName

ArchUnitNET/Domain/Extensions/NamingExtensions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ 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+
)]
42+
public static bool NameMatches(
43+
this IHasName cls,
44+
string pattern,
45+
bool useRegularExpressions
46+
)
47+
{
48+
if (useRegularExpressions)
49+
{
50+
return pattern != null && Regex.IsMatch(cls.Name, pattern);
51+
}
52+
53+
return string.Equals(cls.Name, pattern, StringComparison.OrdinalIgnoreCase);
54+
}
55+
3956
public static bool NameEquals(this IHasName cls, string name)
4057
{
4158
return string.Equals(cls.Name, name, StringComparison.OrdinalIgnoreCase);
@@ -46,6 +63,23 @@ public static bool NameMatches(this IHasName cls, string pattern)
4663
return pattern != null && Regex.IsMatch(cls.Name, pattern);
4764
}
4865

66+
[Obsolete(
67+
"Either FullNameEquals() or FullNameMatches() without the useRegularExpressions parameter should be used"
68+
)]
69+
public static bool FullNameMatches(
70+
this IHasName cls,
71+
string pattern,
72+
bool useRegularExpressions
73+
)
74+
{
75+
if (useRegularExpressions)
76+
{
77+
return pattern != null && Regex.IsMatch(cls.FullName, pattern);
78+
}
79+
80+
return string.Equals(cls.FullName, pattern, StringComparison.OrdinalIgnoreCase);
81+
}
82+
4983
public static bool FullNameEquals(this IHasName cls, string fullName)
5084
{
5185
return string.Equals(cls.FullName, fullName, StringComparison.OrdinalIgnoreCase);

ArchUnitNET/Domain/Extensions/TypeExtensions.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ public static bool ImplementsInterface(this IType type, Interface intf)
1919
);
2020
}
2121

22+
[Obsolete(
23+
"Either ImplementsInterface() without the useRegularExpressions parameter or ImplementsInterfaceMatching() should be used"
24+
)]
25+
public static bool ImplementsInterface(
26+
this IType type,
27+
string pattern,
28+
bool useRegularExpressions
29+
)
30+
{
31+
if (type is GenericParameter)
32+
{
33+
return false;
34+
}
35+
36+
return type.ImplementedInterfaces.Any(implementedInterface =>
37+
implementedInterface.FullNameMatches(pattern, useRegularExpressions)
38+
);
39+
}
40+
2241
public static bool ImplementsInterface(this IType type, string fullName)
2342
{
2443
if (type is GenericParameter)
@@ -55,6 +74,26 @@ public static bool IsAssignableTo(this IType type, IType assignableToType)
5574
return type.GetAssignableTypes().Contains(assignableToType);
5675
}
5776

77+
[Obsolete(
78+
"Either IsAssignableTo() without the useRegularExpressions parameter or IsAssignableToTypeMatching() should be used"
79+
)]
80+
public static bool IsAssignableTo(
81+
this IType type,
82+
string pattern,
83+
bool useRegularExpressions
84+
)
85+
{
86+
if (type is GenericParameter genericParameter)
87+
{
88+
return genericParameter.TypeConstraints.All(t =>
89+
t.IsAssignableTo(pattern, useRegularExpressions)
90+
);
91+
}
92+
93+
return type.GetAssignableTypes()
94+
.Any(t => t.FullNameMatches(pattern, useRegularExpressions));
95+
}
96+
5897
public static bool IsAssignableTo(this IType type, string fullName)
5998
{
6099
if (type is GenericParameter genericParameter)
@@ -239,6 +278,18 @@ public static Attribute GetAttributeOfType(this IType type, Class attributeClass
239278
);
240279
}
241280

281+
[Obsolete(
282+
"Either ResidesInNamespace() without the useRegularExpressions parameter or ResidesInNamespaceMatching() should be used"
283+
)]
284+
public static bool ResidesInNamespace(
285+
this IType e,
286+
string pattern,
287+
bool useRegularExpressions
288+
)
289+
{
290+
return e.Namespace.FullNameMatches(pattern, useRegularExpressions);
291+
}
292+
242293
public static bool ResidesInNamespace(this IType e, string fullName)
243294
{
244295
return e.Namespace.FullNameEquals(fullName);
@@ -249,6 +300,18 @@ public static bool ResidesInNamespaceMatching(this IType e, string pattern)
249300
return e.Namespace.FullNameMatches(pattern);
250301
}
251302

303+
[Obsolete(
304+
"Either ResidesInAssembly() without the useRegularExpressions parameter or ResidesInAssemblyMatching() should be used"
305+
)]
306+
public static bool ResidesInAssembly(
307+
this IType e,
308+
string pattern,
309+
bool useRegularExpressions
310+
)
311+
{
312+
return e.Assembly.FullNameMatches(pattern, useRegularExpressions);
313+
}
314+
252315
public static bool ResidesInAssembly(this IType e, string fullName)
253316
{
254317
return e.Assembly.FullNameEquals(fullName);
@@ -259,6 +322,21 @@ public static bool ResidesInAssemblyMatching(this IType e, string pattern)
259322
return e.Assembly.FullNameMatches(pattern);
260323
}
261324

325+
[Obsolete(
326+
"Either IsDeclaredAsFieldIn() without the useRegularExpressions parameter or IsDeclaredAsFieldInTypeMatching() should be used"
327+
)]
328+
public static bool IsDeclaredAsFieldIn(
329+
this IType type,
330+
string pattern,
331+
bool useRegularExpressions
332+
)
333+
{
334+
return type.GetFieldTypeDependencies(true)
335+
.Any(dependency =>
336+
dependency.Target.FullNameMatches(pattern, useRegularExpressions)
337+
);
338+
}
339+
262340
public static bool IsDeclaredAsFieldIn(this IType type, string fullName)
263341
{
264342
return type.GetFieldTypeDependencies(true)

ArchUnitNET/Domain/PlantUml/Export/DependencyFilters.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public static Func<ITypeDependency, bool> FocusOn(IEnumerable<IType> types)
5050
};
5151
}
5252

53+
[Obsolete(
54+
"Another overload of this method should be used. This will be removed in a future update."
55+
)]
56+
public static Func<ITypeDependency, bool> FocusOn(
57+
string pattern,
58+
bool useRegularExpressions = false
59+
)
60+
{
61+
return dependency =>
62+
dependency.Target.FullNameMatches(pattern, useRegularExpressions)
63+
^ dependency.Origin.FullNameMatches(pattern, useRegularExpressions);
64+
}
65+
5366
public static Func<ITypeDependency, bool> HasOrigin(IType type)
5467
{
5568
return dependency => dependency.Origin.Equals(type);
@@ -60,6 +73,17 @@ public static Func<ITypeDependency, bool> HasOrigin(IEnumerable<IType> types)
6073
return dependency => types.Contains(dependency.Origin);
6174
}
6275

76+
[Obsolete(
77+
"Another overload of this method should be used. This will be removed in a future update."
78+
)]
79+
public static Func<ITypeDependency, bool> HasOrigin(
80+
string pattern,
81+
bool useRegularExpressions = false
82+
)
83+
{
84+
return dependency => dependency.Origin.FullNameMatches(pattern, useRegularExpressions);
85+
}
86+
6387
public static Func<ITypeDependency, bool> HasTarget(IType type)
6488
{
6589
return dependency => dependency.Target.Equals(type);
@@ -69,5 +93,16 @@ public static Func<ITypeDependency, bool> HasTarget(IEnumerable<IType> types)
6993
{
7094
return dependency => types.Contains(dependency.Target);
7195
}
96+
97+
[Obsolete(
98+
"Another overload of this method should be used. This will be removed in a future update."
99+
)]
100+
public static Func<ITypeDependency, bool> HasTarget(
101+
string pattern,
102+
bool useRegularExpressions = false
103+
)
104+
{
105+
return dependency => dependency.Target.FullNameMatches(pattern, useRegularExpressions);
106+
}
72107
}
73108
}

0 commit comments

Comments
 (0)