Skip to content

Commit

Permalink
fixed regression for string array elements, now aspect are forced to …
Browse files Browse the repository at this point in the history
…be public
  • Loading branch information
pamidur committed Jan 19, 2020
1 parent 6ea888f commit f6c9b8d
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion external/FluentIL
8 changes: 7 additions & 1 deletion src/AspectInjector.Core/Models/AspectDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public bool Validate(ILogger log)
{
var result = true;

if(Scope!= Scope.Global && Scope!= Scope.PerInstance)
if (Scope != Scope.Global && Scope != Scope.PerInstance)
log.Log(GeneralRules.UnknownCompilationOption, Host, GeneralRules.Literals.UnknownAspectScope(Scope.ToString()));

if (!Effects.Any())
Expand All @@ -59,6 +59,12 @@ public bool Validate(ILogger log)
result = false;
}

if (!Host.IsPublic && !Host.IsNestedPublic)
{
log.Log(AspectRules.AspectMustHaveValidSignature, Host, Host.Name, AspectRules.Literals.IsNotPublic);
result = false;
}

if (Host.IsAbstract)
{
if (Host.IsSealed)
Expand Down
5 changes: 3 additions & 2 deletions src/AspectInjector.Rules/AspectRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class Literals
{
public static readonly string HasGenericParams = "has generic parameters";
public static readonly string IsAbstract = "is abstract";
public static readonly string IsNotPublic = "is not public";
public static readonly string IsStatic = "is static";
}

Expand All @@ -20,9 +21,9 @@ public static class Literals

public static readonly Rule AspectMustHaveValidSignature =
GeneralRules.Make("AI_A001",
"Aspect must not be generic, abstract or static",
"Aspect must not be generic, abstract or static. And it should be public.",
"Aspect '{0}' {1}",
"Aspect must have valid signature. Aspect must be non-generic, non-abstract and non-static class.");
"Aspect must have valid signature. Aspect must be non-generic, non-abstract and non-static public class.");

public static readonly Rule AspectFactoryMustContainFactoryMethod =
GeneralRules.Make("AI_A002",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Public() { }

[Aspect(Scope.Global)]
[Injection(typeof(AccessTestAspect))]
internal class AccessTestAspect : Attribute
public class AccessTestAspect : Attribute
{
[Advice(Kind.Around, Targets = Target.Internal)]
public object TestAccess([Argument(Source.Metadata)] MethodBase method)
Expand Down
4 changes: 2 additions & 2 deletions tests/AspectInjector.Tests.Runtime/Advices/AfterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public int TestCustomSetterProperty
//aspects
[Aspect(Scope.Global)]
[Injection(typeof(AfterTests_AfterMethodAspect))]
internal class AfterTests_AfterMethodAspect : Attribute
public class AfterTests_AfterMethodAspect : Attribute
{
//Property
[Advice(Kind.After, Targets = Target.Setter)]
Expand All @@ -161,7 +161,7 @@ internal class AfterTests_AfterMethodAspect : Attribute

[Aspect(Scope.Global)]
[Injection(typeof(AfterTests_AfterConstructorAspect))]
internal class AfterTests_AfterConstructorAspect : Attribute
public class AfterTests_AfterConstructorAspect : Attribute
{
[Advice(Kind.After, Targets = Target.Constructor)]
public void AfterConstructor() { Checker.Passed = true; }
Expand Down
20 changes: 10 additions & 10 deletions tests/AspectInjector.Tests.Runtime/Advices/ArgumentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void Fact()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_InstanceAspect))]
internal class ArgumentsTests_InstanceAspect : Attribute
public class ArgumentsTests_InstanceAspect : Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod([Argument(Source.Instance)] object instance)
Expand All @@ -151,7 +151,7 @@ public static void Fact()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_StaticInstanceAspect))]
internal class ArgumentsTests_StaticInstanceAspect:Attribute
public class ArgumentsTests_StaticInstanceAspect:Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod([Argument(Source.Instance)] object instance)
Expand All @@ -170,7 +170,7 @@ public static void Fact()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_ReturnTypeAspect))]
internal class ArgumentsTests_ReturnTypeAspect: Attribute
public class ArgumentsTests_ReturnTypeAspect: Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod([Argument(Source.Type)] System.Type type)
Expand All @@ -197,7 +197,7 @@ static ArgumentsTests_StaticConstructorTarget()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_StaticMethodAspect))]
internal class ArgumentsTests_StaticMethodAspect : Attribute
public class ArgumentsTests_StaticMethodAspect : Attribute
{
[Advice(Kind.Before, Targets = Target.Method | Target.Constructor)]
public void BeforeMethod([Argument(Source.Metadata)] MethodBase method)
Expand Down Expand Up @@ -245,7 +245,7 @@ public ArgumentsTests_ConstructorTarget()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_MethodAspect))]
internal class ArgumentsTests_MethodAspect:Attribute
public class ArgumentsTests_MethodAspect:Attribute
{
[Advice(Kind.Before, Targets = Target.Method | Target.Constructor)]
public void BeforeMethod([Argument(Source.Metadata)] MethodBase method)
Expand All @@ -266,7 +266,7 @@ public void Fact(object obj, ref object objRef, out object objOut, int value, re

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_ArgumentsAspect))]
internal class ArgumentsTests_ArgumentsAspect:Attribute
public class ArgumentsTests_ArgumentsAspect:Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod([Argument(Source.Arguments)] object[] args)
Expand All @@ -287,7 +287,7 @@ public static void Fact(int a, string b)

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_StaticArgumentsAspect))]
internal class ArgumentsTests_StaticArgumentsAspect :Attribute
public class ArgumentsTests_StaticArgumentsAspect :Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod([Argument(Source.Arguments)] object[] args)
Expand All @@ -306,7 +306,7 @@ public void Fact()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_AroundMethodAspect))]
internal class ArgumentsTests_AroundMethodAspect : Attribute
public class ArgumentsTests_AroundMethodAspect : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object BeforeMethod([Argument(Source.Metadata)] MethodBase method)
Expand All @@ -327,7 +327,7 @@ public object Fact()

[Aspect(Scope.Global)]
[Injection(typeof(ArgumentsTests_AroundRetValAspect))]
internal class ArgumentsTests_AroundRetValAspect:Attribute
public class ArgumentsTests_AroundRetValAspect:Attribute
{
[Advice(Kind.After, Targets = Target.Method)]
public void AfterMethod([Argument(Source.ReturnValue)] object ret)
Expand All @@ -344,7 +344,7 @@ internal class ArgumentsTests_PropertyTarget

[Injection(typeof(ArgumentsTests_PropertyTarget_Aspect))]
[Aspect(Scope.Global)]
class ArgumentsTests_PropertyTarget_Aspect : Attribute
public class ArgumentsTests_PropertyTarget_Aspect : Attribute
{
[Advice(Kind.Before)]
public void TestName([Argument(Source.Name)] string name)
Expand Down
8 changes: 4 additions & 4 deletions tests/AspectInjector.Tests.Runtime/Advices/AroundTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public T Generic<T>(T data)

[Aspect(Scope.Global)]
[Injection(typeof(AroundTests_Simple))]
internal class AroundTests_Simple : Attribute
public class AroundTests_Simple : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundMethod([Argument(Source.Target)] Func<object[], object> target,
Expand All @@ -201,7 +201,7 @@ public object AroundMethod([Argument(Source.Target)] Func<object[], object> targ

[Aspect(Scope.Global)]
[Injection(typeof(AroundTests_Aspect1))]
internal class AroundTests_Aspect1 : Attribute
public class AroundTests_Aspect1 : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundMethod([Argument(Source.Target)] Func<object[], object> target,
Expand All @@ -213,7 +213,7 @@ public object AroundMethod([Argument(Source.Target)] Func<object[], object> targ

[Aspect(Scope.Global)]
[Injection(typeof(AroundTests_Aspect2))]
internal class AroundTests_Aspect2 : Attribute
public class AroundTests_Aspect2 : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundMethod([Argument(Source.Target)] Func<object[], object> target,
Expand All @@ -235,7 +235,7 @@ public void Fact(ref int i)

[Aspect(Scope.Global)]
[Injection(typeof(AroundTests_ArgumentsModificationAspect))]
internal class AroundTests_ArgumentsModificationAspect : Attribute
public class AroundTests_ArgumentsModificationAspect : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundMethod(
Expand Down
6 changes: 3 additions & 3 deletions tests/AspectInjector.Tests.Runtime/Advices/BeforeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void Fact(string data)
//aspects
[Aspect(Scope.Global)]
[Injection(typeof(BeforeTests_Aspect))]
internal class BeforeTests_Aspect : Attribute
public class BeforeTests_Aspect : Attribute
{
//Property
[Advice(Kind.Before, Targets = Target.Setter)]
Expand All @@ -122,7 +122,7 @@ internal class BeforeTests_Aspect : Attribute

[Aspect( Scope.Global)]
[Injection(typeof(BeforeTests_BeforeConstructorAspect))]
internal class BeforeTests_BeforeConstructorAspect : Attribute
public class BeforeTests_BeforeConstructorAspect : Attribute
{
[Advice(Kind.Before, Targets = Target.Constructor)]
public void BeforeConstructor([Argument(Source.Instance)] object instance)
Expand All @@ -135,7 +135,7 @@ public void BeforeConstructor([Argument(Source.Instance)] object instance)
[Mixin(typeof(IDisposable))]
[Aspect(Scope.Global)]
[Injection(typeof(BeforeTests_BeforeConstructorWithInterfaceAspect))]
internal class BeforeTests_BeforeConstructorWithInterfaceAspect : Attribute, IDisposable
public class BeforeTests_BeforeConstructorWithInterfaceAspect : Attribute, IDisposable
{
[Advice(Kind.Before, Targets = Target.Constructor)]
public void BeforeConstructor() { Checker.Passed = true; }
Expand Down
6 changes: 3 additions & 3 deletions tests/AspectInjector.Tests.Runtime/Advices/GenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void TestGenericMethod<U>()

[Aspect(Scope.Global)]
[Injection(typeof(GenericTests_Aspect))]
internal class GenericTests_Aspect : Attribute
public class GenericTests_Aspect : Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod() { Checker.Passed = true; }
Expand All @@ -80,7 +80,7 @@ public void Fact()

[Aspect(Scope.Global)]
[Injection(typeof(GenericTests_OpenGenericAspect))]
internal class GenericTests_OpenGenericAspect:Attribute
public class GenericTests_OpenGenericAspect:Attribute
{
[Advice(Kind.Before, Targets = Target.Method)]
public void BeforeMethod() { Checker.Passed = true; }
Expand All @@ -98,7 +98,7 @@ public T Fact<T>(ref T value)

[Aspect(Scope.Global)]
[Injection(typeof(GenericAroundTests_Aspect))]
internal class GenericAroundTests_Aspect : Attribute
public class GenericAroundTests_Aspect : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundAdvice([Argument(Source.Target)] Func<object[], object> target,
Expand Down
6 changes: 3 additions & 3 deletions tests/AspectInjector.Tests.Runtime/Advices/OrderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Fact()
class Trigger : Attribute { }

[Aspect(Scope.Global)]
internal class OrderTests_Aspect1
public class OrderTests_Aspect1
{
[Advice(Kind.Before)]
public void BeforeMethod()
Expand All @@ -41,7 +41,7 @@ public void BeforeMethod()
}

[Aspect(Scope.Global)]
internal class OrderTests_Aspect2
public class OrderTests_Aspect2
{
[Advice(Kind.Before)]
public void BeforeMethod()
Expand All @@ -51,7 +51,7 @@ public void BeforeMethod()
}

[Aspect(Scope.Global)]
internal class OrderTests_Aspect3
public class OrderTests_Aspect3
{
[Advice(Kind.Before)]
public void BeforeMethod()
Expand Down
6 changes: 3 additions & 3 deletions tests/AspectInjector.Tests.Runtime/Advices/StaticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static int Do123(int data, StringBuilder sb, object to, bool passed, bool

[Aspect(Scope.Global)]
[Injection(typeof(StaticTests_AroundAspect1))]
internal class StaticTests_AroundAspect1 : Attribute
public class StaticTests_AroundAspect1 : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundMethod([Argument(Source.Target)] Func<object[], object> target,
Expand All @@ -57,7 +57,7 @@ public object AroundMethod([Argument(Source.Target)] Func<object[], object> targ

[Aspect(Scope.Global)]
[Injection(typeof(StaticTests_AroundAspect2))]
internal class StaticTests_AroundAspect2 : Attribute
public class StaticTests_AroundAspect2 : Attribute
{
[Advice(Kind.Around, Targets = Target.Method)]
public object AroundMethod([Argument(Source.Target)] Func<object[], object> target,
Expand All @@ -81,7 +81,7 @@ public void TestInstanceMethod()

[Aspect(Scope.Global)]
[Injection(typeof(StaticTests_BeforeAspect))]
internal class StaticTests_BeforeAspect : Attribute
public class StaticTests_BeforeAspect : Attribute
{
//Property
[Advice(Kind.Before, Targets = Target.Method)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void SCOPE_Create_Global_Aspect()

[Aspect(Scope.PerInstance)]
[Injection(typeof(AspectScopeTests_PerInstanceAspect))]
internal class AspectScopeTests_PerInstanceAspect:Attribute
public class AspectScopeTests_PerInstanceAspect:Attribute
{
public static int _counter;

Expand All @@ -48,7 +48,7 @@ public void Do()

[Aspect(Scope.Global)]
[Injection(typeof(AspectScopeTests_GlobalAspect))]
internal class AspectScopeTests_GlobalAspect: Attribute
public class AspectScopeTests_GlobalAspect: Attribute
{
public static int _counter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class UnmanagedTests

[Aspect(Scope.Global)]
[Injection(typeof(UnmanagedTests_Aspect))]
internal class UnmanagedTests_Aspect : Attribute
public class UnmanagedTests_Aspect : Attribute
{
[Advice(Kind.After, Targets = Target.Method)]
public void Trace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private class TestTarget

[Aspect(Scope.Global)]
[Injection(typeof(TestAspect))]
private class TestAspect : Attribute
public class TestAspect : Attribute
{
private int _count = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void AspectInstance_InHierarchy_MustBeOne()

[Aspect(Scope.PerInstance)]
[Injection(typeof(TestAspect))]
private class TestAspect : Attribute
public class TestAspect : Attribute
{
public int Count { get; private set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Test() { }
}

[Aspect(Scope.Global)]
private class TestAspect
public class TestAspect
{
[Advice(Kind.Before, Targets = Target.Method)]
public void Before()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private class GeneralTests_Trigger : Attribute
[Mixin(typeof(IGeneralTests))]
[Mixin(typeof(INotifyPropertyChanged))]
[Aspect(Scope.Global)]
internal class GeneralTests_Aspect : IGeneralTests, INotifyPropertyChanged
public class GeneralTests_Aspect : IGeneralTests, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = (s, e) => { };

Expand Down
2 changes: 1 addition & 1 deletion tests/AspectInjector.Tests.Runtime/Issues/0098.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Fixed()

[Aspect(Scope.PerInstance)]
[Injection(typeof(TestAspect))]
private class TestAspect : Attribute
public class TestAspect : Attribute
{
[Advice(Kind.Before)]
public void Before()
Expand Down

0 comments on commit f6c9b8d

Please sign in to comment.