Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions ArchUnitNET/Domain/Extensions/AttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
using System;
using System.Linq;

namespace ArchUnitNET.Domain.Extensions
{
public static class AttributeExtensions
{
[Obsolete(
"Either HasAttribute() without the useRegularExpressions parameter or HasAttributeMatching() should be used"
)]
public static bool HasAttribute(
this IHasAttributes a,
string pattern,
bool useRegularExpressions = false
bool useRegularExpressions
)
{
return a.Attributes.Any(attribute =>
attribute.FullNameMatches(pattern, useRegularExpressions)
);
}

public static bool HasAttribute(this IHasAttributes a, string fullName)
{
return a.Attributes.Any(attribute => attribute.FullNameEquals(fullName));
}

[Obsolete(
"Either OnlyHasAttributes() without the useRegularExpressions parameter or OnlyHasAttributesMatching() should be used"
)]
public static bool OnlyHasAttributes(
this IHasAttributes a,
string pattern,
bool useRegularExpressions = false
bool useRegularExpressions
)
{
return a.Attributes.IsNullOrEmpty()
|| a.Attributes.All(attribute =>
attribute.FullNameMatches(pattern, useRegularExpressions)
);
}

public static bool HasAttributeMatching(this IHasAttributes a, string pattern)
{
return a.Attributes.Any(attribute => attribute.FullNameMatches(pattern));
}

public static bool OnlyHasAttributes(this IHasAttributes a, string name)
{
return a.Attributes.IsNullOrEmpty()
|| a.Attributes.All(attribute => attribute.FullNameEquals(name));
}

public static bool OnlyHasAttributesMatching(this IHasAttributes a, string pattern)
{
return a.Attributes.IsNullOrEmpty()
|| a.Attributes.All(attribute => attribute.FullNameMatches(pattern));
}
}
}
42 changes: 41 additions & 1 deletion ArchUnitNET/Domain/Extensions/DependencyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ArchUnitNET.Domain.Dependencies;
Expand All @@ -6,16 +7,29 @@ namespace ArchUnitNET.Domain.Extensions
{
public static class DependencyExtensions
{
[Obsolete(
"Either CallsMethod() without the useRegularExpressions parameter or CallsMethodMatching() should be used"
)]
public static bool CallsMethod(
this IHasDependencies type,
string pattern,
bool useRegularExpressions = false
bool useRegularExpressions
)
{
return type.GetCalledMethods()
.Any(member => member.FullNameMatches(pattern, useRegularExpressions));
}

public static bool CallsMethod(this IHasDependencies type, string fullName)
{
return type.GetCalledMethods().Any(member => member.FullNameEquals(fullName));
}

public static bool CallsMethodMatching(this IHasDependencies type, string pattern)
{
return type.GetCalledMethods().Any(member => member.FullNameMatches(pattern));
}

public static IEnumerable<MethodMember> GetCalledMethods(this IHasDependencies type)
{
return type
Expand All @@ -30,6 +44,9 @@ public static IEnumerable<FieldMember> GetAccessedFieldMembers(this IHasDependen
.Select(dependency => (FieldMember)dependency.TargetMember);
}

[Obsolete(
"Either DependsOnType() without the useRegularExpressions parameter or DependsOnTypeMatching() should be used"
)]
public static bool DependsOn(
this IHasDependencies c,
string pattern,
Expand All @@ -40,6 +57,19 @@ public static bool DependsOn(
.Any(d => d.FullNameMatches(pattern, useRegularExpressions));
}

public static bool DependsOnType(this IHasDependencies c, string fullName)
{
return c.GetTypeDependencies().Any(d => d.FullNameEquals(fullName));
}

public static bool DependsOnTypeMatching(this IHasDependencies c, string pattern)
{
return c.GetTypeDependencies().Any(d => d.FullNameMatches(pattern));
}

[Obsolete(
"Either OnlyDependsOnType() without the useRegularExpressions parameter or OnlyDependsOnTypesMatching() should be used"
)]
public static bool OnlyDependsOn(
this IHasDependencies c,
string pattern,
Expand All @@ -50,6 +80,16 @@ public static bool OnlyDependsOn(
.All(d => d.FullNameMatches(pattern, useRegularExpressions));
}

public static bool OnlyDependsOnType(this IHasDependencies c, string fullName)
{
return c.GetTypeDependencies().All(d => d.FullNameEquals(fullName));
}

public static bool OnlyDependsOnTypesMatching(this IHasDependencies c, string pattern)
{
return c.GetTypeDependencies().All(d => d.FullNameMatches(pattern));
}

public static IEnumerable<IType> GetTypeDependencies(this IHasDependencies c)
{
return c.Dependencies.Select(dependency => dependency.Target);
Expand Down
56 changes: 55 additions & 1 deletion ArchUnitNET/Domain/Extensions/MemberExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ArchUnitNET.Domain.Dependencies;
Expand All @@ -6,15 +7,28 @@ namespace ArchUnitNET.Domain.Extensions
{
public static class MemberExtensions
{
[Obsolete(
"Either IsDeclaredIn() without the useRegularExpressions parameter or IsDeclaredInTypeMatching() should be used"
)]
public static bool IsDeclaredIn(
this IMember member,
string pattern,
bool useRegularExpressions = false
bool useRegularExpressions
)
{
return member.DeclaringType.FullNameMatches(pattern, useRegularExpressions);
}

public static bool IsDeclaredIn(this IMember member, string fullName)
{
return member.DeclaringType.FullNameEquals(fullName);
}

public static bool IsDeclaredInTypeMatching(this IMember member, string pattern)
{
return member.DeclaringType.FullNameMatches(pattern);
}

public static bool IsDeclaredIn(this IMember member, IType type)
{
return member.DeclaringType.Equals(type);
Expand Down Expand Up @@ -56,6 +70,9 @@ public static bool HasMethodCallDependencies(
return member.GetMethodCallDependencies(getBackwardsDependencies).Any();
}

[Obsolete(
"Either IsCalledByType() without the useRegularExpressions parameter or IsCalledByTypeMatching() should be used"
)]
public static bool IsCalledBy(
this MethodMember member,
string pattern,
Expand All @@ -69,6 +86,20 @@ public static bool IsCalledBy(
);
}

public static bool IsCalledByType(this MethodMember member, string fullName)
{
return member
.GetMethodCallDependencies(true)
.Any(dependency => dependency.Origin.FullNameEquals(fullName));
}

public static bool IsCalledByTypeMatching(this MethodMember member, string pattern)
{
return member
.GetMethodCallDependencies(true)
.Any(dependency => dependency.Origin.FullNameMatches(pattern));
}

public static IEnumerable<IType> GetCallingTypes(this MethodMember member)
{
return member
Expand All @@ -77,6 +108,9 @@ public static IEnumerable<IType> GetCallingTypes(this MethodMember member)
.Distinct();
}

[Obsolete(
"Either HasDependencyInMethodBodyToType() without the useRegularExpressions parameter or HasDependencyInMethodBodyToTypeMatching() should be used"
)]
public static bool HasDependencyInMethodBodyTo(
this MethodMember member,
string pattern,
Expand All @@ -90,6 +124,26 @@ public static bool HasDependencyInMethodBodyTo(
);
}

public static bool HasDependencyInMethodBodyToType(
this MethodMember member,
string fullName
)
{
return member
.GetBodyTypeMemberDependencies()
.Any(dependency => dependency.Target.FullNameEquals(fullName));
}

public static bool HasDependencyInMethodBodyToTypeMatching(
this MethodMember member,
string pattern
)
{
return member
.GetBodyTypeMemberDependencies()
.Any(dependency => dependency.Target.FullNameMatches(pattern));
}

public static bool HasFieldTypeDependencies(
this IMember member,
bool getBackwardsDependencies = false
Expand Down
30 changes: 28 additions & 2 deletions ArchUnitNET/Domain/Extensions/NamingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public static bool NameContains(
return cls.Name.IndexOf(pattern, stringComparison) >= 0;
}

[Obsolete(
"Either NameEquals() or NameMatches() without the useRegularExpressions parameter should be used"
)]
public static bool NameMatches(
this IHasName cls,
string pattern,
bool useRegularExpressions = false
bool useRegularExpressions
)
{
if (useRegularExpressions)
Expand All @@ -50,10 +53,23 @@ public static bool NameMatches(
return string.Equals(cls.Name, pattern, StringComparison.OrdinalIgnoreCase);
}

public static bool NameEquals(this IHasName cls, string name)
{
return string.Equals(cls.Name, name, StringComparison.OrdinalIgnoreCase);
}

public static bool NameMatches(this IHasName cls, string pattern)
{
return pattern != null && Regex.IsMatch(cls.Name, pattern);
}

[Obsolete(
"Either FullNameEquals() or FullNameMatches() without the useRegularExpressions parameter should be used"
)]
public static bool FullNameMatches(
this IHasName cls,
string pattern,
bool useRegularExpressions = false
bool useRegularExpressions
)
{
if (useRegularExpressions)
Expand All @@ -64,6 +80,16 @@ public static bool FullNameMatches(
return string.Equals(cls.FullName, pattern, StringComparison.OrdinalIgnoreCase);
}

public static bool FullNameEquals(this IHasName cls, string fullName)
{
return string.Equals(cls.FullName, fullName, StringComparison.OrdinalIgnoreCase);
}

public static bool FullNameMatches(this IHasName cls, string pattern)
{
return pattern != null && Regex.IsMatch(cls.FullName, pattern);
}

public static bool FullNameContains(this IHasName cls, string pattern)
{
return pattern != null && cls.FullName.ToLower().Contains(pattern.ToLower());
Expand Down
Loading