protected void advice( PointCutDefinition pointcut ) //throws RecognitionException, TokenStreamException { Token i = null; TypeReference tr = null; InterceptorDefinition interDef = null; try { // for error handling i = LT(1); match(ADVICEINTERCEPTOR); interDef = new InterceptorDefinition(ToLexicalInfo(i)); match(LCURLY); tr = type_name_or_ref(); interDef.TypeReference = tr; pointcut.Advices.Add(interDef); match(RCURLY); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(tokenSet_13_); } }
private static void AssertEngineConfiguration(AspectEngine engine) { Assert.IsNotNull(engine); Assert.IsNotNull(engine.Configuration); Assert.AreEqual(1, engine.Configuration.Imports.Count); Assert.AreEqual(1, engine.Configuration.Mixins.Count); Assert.AreEqual(1, engine.Configuration.Interceptors.Count); Assert.AreEqual(1, engine.Configuration.Aspects.Count); AspectDefinition aspect = engine.Configuration.Aspects[0]; Assert.AreEqual("McBrother", aspect.Name); Assert.AreEqual(typeof(DummyCustomer), aspect.TargetType.SingleType.ResolvedType); Assert.AreEqual(1, aspect.Mixins.Count); MixinDefinition mixin = aspect.Mixins[0]; Assert.AreEqual(typeof(DummyMixin), mixin.TypeReference.ResolvedType); Assert.AreEqual(1, aspect.PointCuts.Count); PointCutDefinition pointcut = aspect.PointCuts[0]; Assert.AreEqual(AllMethodSignature.Instance, pointcut.Method); Assert.AreEqual(1, pointcut.Advices.Count); InterceptorDefinition advice = pointcut.Advices[0]; Assert.AreEqual(typeof(DummyInterceptor), advice.TypeReference.ResolvedType); }
private void LoadAdvices(XmlNode inner, PointCutDefinition def) { XmlNodeList advices = inner.SelectNodes("interceptor"); foreach (XmlNode advice in advices) { InterceptorDefinition inter = new InterceptorDefinition(LexicalInfo.Empty); inter.TypeReference = CreateTypeReference(advice); def.Advices.Add(inter); } }
public override void OnInterceptorDefinition(InterceptorDefinition interceptor) { if (interceptor.TypeReference.TargetType == TargetTypeEnum.Type) { base.OnInterceptorDefinition(interceptor); } else { interceptor.TypeReference = _interceptorKey2TypeReference[interceptor.TypeReference.LinkRef] as TypeReference; } }
public void ParsingInterceptorRefForProperty() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut property(* Name)" + " advice(\"logger\")" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(1, pointcut.Advices.Count); InterceptorDefinition adv = pointcut.Advices[0]; Assert.IsNotNull(adv); Assert.AreEqual("logger", adv.TypeReference.LinkRef); }
public void ParsingInterceptorTypeForProperty() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut property(* Name)" + " advice( My.NS.Interceptor in My.Assembly )" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(1, pointcut.Advices.Count); InterceptorDefinition adv = pointcut.Advices[0]; Assert.IsNotNull(adv); Assert.AreEqual(TargetTypeEnum.Type, adv.TypeReference.TargetType); Assert.AreEqual("My.NS.Interceptor", adv.TypeReference.TypeName); Assert.AreEqual("My.Assembly", adv.TypeReference.AssemblyReference.AssemblyName); }
public void GlobalsCorrectlyReferenced() { String content = " " + "interceptors \r\n" + "[" + "\"customer\" : System.Collections.Hashtable" + "]" + "mixins \r\n" + "[" + "\"customer\" : AspectSharp.Lang.Tests.Types.Mixins.MockMixin in AspectSharp.Lang.Tests" + "]" + " " + "aspect McBrother for System.Collections.ArrayList " + " " + " include \"customer\"" + " " + " pointcut method(*)" + " advice(\"customer\")" + " end" + " " + "end " + " "; EngineConfiguration conf = ProcessContent(content); Assert.IsFalse(_context.HasErrors); AspectDefinition aspect = conf.Aspects[0]; MixinDefinition mixin = aspect.Mixins[0]; InterceptorDefinition interceptor = aspect.PointCuts[0].Advices[0]; Assert.IsNotNull(mixin.TypeReference); Assert.IsNotNull(mixin.TypeReference.ResolvedType); Assert.AreEqual(typeof(MockMixin), mixin.TypeReference.ResolvedType); Assert.IsNotNull(interceptor.TypeReference); Assert.IsNotNull(interceptor.TypeReference.ResolvedType); Assert.AreEqual(typeof(System.Collections.Hashtable), interceptor.TypeReference.ResolvedType); }
public void BuildUsingCode() { CodeEngineBuilder builder = new CodeEngineBuilder(); EngineConfiguration conf = builder.GetConfiguration(); ImportDirective import = new ImportDirective(LexicalInfo.Empty, "AspectSharp.Tests.Classes"); import.AssemblyReference = new AssemblyReference(LexicalInfo.Empty, "AspectSharp.Tests"); conf.Imports.Add(import); conf.Mixins.Add("key", LexicalInfo.Empty).TypeReference = new TypeReference(LexicalInfo.Empty, "DummyMixin"); conf.Interceptors.Add("key", LexicalInfo.Empty).TypeReference = new TypeReference(LexicalInfo.Empty, "DummyInterceptor"); AspectDefinition aspect = new AspectDefinition(LexicalInfo.Empty, "McBrother"); aspect.TargetType = new TargetTypeDefinition(); aspect.TargetType.SingleType = new TypeReference(LexicalInfo.Empty, "DummyCustomer"); conf.Aspects.Add(aspect); MixinDefinition mixin = new MixinDefinition(LexicalInfo.Empty); mixin.TypeReference = new TypeReference(LexicalInfo.Empty, "key", TargetTypeEnum.Link); aspect.Mixins.Add(mixin); PointCutDefinition pointcut = new PointCutDefinition(LexicalInfo.Empty, PointCutFlags.Method); pointcut.Method = AllMethodSignature.Instance; InterceptorDefinition interceptor = new InterceptorDefinition(LexicalInfo.Empty); interceptor.TypeReference = new TypeReference(LexicalInfo.Empty, "key", TargetTypeEnum.Link); pointcut.Advices.Add(interceptor); aspect.PointCuts.Add(pointcut); AspectEngine engine = builder.Build(); AssertEngineConfiguration(engine); }
public void XmlWithMoreComplexMethodSignature() { String xmlContents = "<configuration>" + "<import namespace=\"AspectSharp.Tests.Classes\" assembly=\"AspectSharp.Tests\" />" + "<mixins>" + "<mixin key=\"key\" type=\"DummyMixin\" refTypeEnum=\"Type\" />" + "</mixins><interceptors>" + "<interceptor key=\"key\" type=\"DummyInterceptor\" refTypeEnum=\"Type\" />" + "</interceptors>" + "<aspect name=\"McBrother\"><for>" + "<singletype type=\"DummyCustomer\" refTypeEnum=\"Type\" />" + "</for>" + "<mixin type=\"key\" refTypeEnum=\"Link\" />" + "<pointcut symbol=\"Method\"><signature>(void Name(*))</signature>" + "<interceptor type=\"key\" refTypeEnum=\"Link\" />" + "</pointcut>" + "</aspect>" + "</configuration>"; XmlEngineBuilder builder = new XmlEngineBuilder(xmlContents); AspectEngine engine = builder.Build(); Assert.IsNotNull(engine); Assert.IsNotNull(engine.Configuration); AspectDefinition aspect = engine.Configuration.Aspects[0]; Assert.AreEqual(1, aspect.Mixins.Count); PointCutDefinition pointcut = aspect.PointCuts[0]; Assert.IsTrue(pointcut.Method.AllArguments); Assert.AreEqual("void", pointcut.Method.RetType); Assert.AreEqual("Name", pointcut.Method.MethodName); Assert.AreEqual(1, pointcut.Advices.Count); InterceptorDefinition advice = pointcut.Advices[0]; Assert.AreEqual(typeof(DummyInterceptor), advice.TypeReference.ResolvedType); }
public override void OnInterceptorDefinition(InterceptorDefinition interceptor) { Push( Document.CreateNode(XmlNodeType.Element, "interceptor", null) ); SerializeTypeReference(interceptor.TypeReference); Pop(); }
public override void OnInterceptorDefinition(InterceptorDefinition interceptor) { AssertIsInterceptor(interceptor.LexicalInfo, interceptor.TypeReference.ResolvedType, INVALID_INTERCEPTOR); }
public virtual void OnInterceptorDefinition(InterceptorDefinition interceptor) { OnTypeReferenceDefinition(interceptor.TypeReference); }
public override void OnInterceptorDefinition(InterceptorDefinition interceptor) { Push(Document.CreateNode(XmlNodeType.Element, "interceptor", null)); SerializeTypeReference(interceptor.TypeReference); Pop(); }