protected void pointcut( AspectDefinition aspect ) //throws RecognitionException, TokenStreamException { Token p = null; PointCutDefinition pointcut = null; PointCutFlags flags = PointCutFlags.Unspecified; try { // for error handling p = LT(1); match(POINTCUT); flags = pointcutflags(); pointcut = new PointCutDefinition(ToLexicalInfo(p), flags); aspect.PointCuts.Add(pointcut); pointcuttarget(pointcut); advices(pointcut); match(END); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(tokenSet_11_); } }
protected void advices( PointCutDefinition pointcut ) //throws RecognitionException, TokenStreamException { try { // for error handling { // ( ... )* for (;;) { if ((LA(1) == ADVICEINTERCEPTOR)) { advice(pointcut); } else { goto _loop43_breakloop; } } _loop43_breakloop :; } // ( ... )* } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(tokenSet_14_); } }
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 void LoadAspects() { XmlNodeList aspects = _node.SelectNodes("aspect"); foreach (XmlNode node in aspects) { String name = GetRequiredAttribute(node, "name"); AspectDefinition aspect = new AspectDefinition(LexicalInfo.Empty, name); Configuration.Aspects.Add(aspect); XmlNode singleType = node.SelectSingleNode("for/singletype"); aspect.TargetType = new TargetTypeDefinition(); aspect.TargetType.SingleType = CreateTypeReference(singleType); XmlNodeList mixins = node.SelectNodes("mixin"); foreach (XmlNode inner in mixins) { MixinDefinition def = new MixinDefinition(LexicalInfo.Empty); def.TypeReference = CreateTypeReference(inner); aspect.Mixins.Add(def); } XmlNodeList pointcuts = node.SelectNodes("pointcut"); foreach (XmlNode inner in pointcuts) { PointCutDefinition def = CreatePointCutDefinition(inner); aspect.PointCuts.Add(def); } } }
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); }
protected virtual bool FlagsMatchMethodType(MethodInfo method, PointCutDefinition pointcut) { if (!method.IsSpecialName && ((int)(pointcut.Flags & PointCutFlags.Method)) == 0) { return(false); } if (method.IsSpecialName) { if (pointcut.Flags == PointCutFlags.Method) { return(false); } if (((int)(pointcut.Flags & PointCutFlags.Property)) == 0) { bool isPropertyGet = method.Name.StartsWith("get"); if ((!isPropertyGet && ((int)(pointcut.Flags & PointCutFlags.PropertyRead)) != 0) || (isPropertyGet && ((int)(pointcut.Flags & PointCutFlags.PropertyWrite) != 0))) { return(false); } } } return(true); }
private void ParseSignature(XmlNode inner, PointCutDefinition def) { XmlNode signature = inner.SelectSingleNode("signature"); StringReader reader = new StringReader(signature.InnerText); AspectLanguageLexer lexer = new AspectLanguageLexer(reader); AspectParser parser = new AspectParser(lexer); parser.ParsePointcutSignature(def); }
private PointCutDefinition CreatePointCutDefinition(XmlNode inner) { String flags = GetRequiredAttribute(inner, "symbol"); PointCutFlags pcflags = (PointCutFlags)Enum.Parse(typeof(PointCutFlags), flags); PointCutDefinition def = new PointCutDefinition(LexicalInfo.Empty, pcflags); ParseSignature(inner, def); LoadAdvices(inner, def); return(def); }
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); } }
protected void pointcutsignature( PointCutDefinition pointcut ) //throws RecognitionException, TokenStreamException { try { // for error handling pointcutsig1(pointcut); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(tokenSet_13_); } }
public override void OnPointCutDefinition(PointCutDefinition pointcut) { Push(Document.CreateNode(XmlNodeType.Element, "pointcut", null)); XmlAttribute att = Document.CreateAttribute("symbol"); att.Value = pointcut.Flags.ToString(); Current.Attributes.Append(att); Push(Document.CreateNode(XmlNodeType.Element, "signature", null)); Current.InnerText = pointcut.Method.ToString(); Pop(); base.OnPointCutDefinition(pointcut); Pop(); }
protected void DoParsing(string method, string access, string type, string name, string param1) { string allparams; if (param1 != null) { allparams = "(" + param1 + ")"; } else { allparams = string.Empty; } AspectParser parser = CreateParser(string.Format( "aspect XPTO for MyNamespace.MyType \n\n" + " pointcut {0}({1} {2} {3}{4}) \n" + " advice(My.NS.Interceptor in My.Assembly ) \n" + " end \n" + "end", method, access, type, name, allparams)); string s = string.Format("{0}({1} {2} {3}{4})", method, access, type, name, allparams); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pc = def.PointCuts[0]; if (name == "*") { name = ".*"; } Assert.AreEqual(string.Format("({0} {1} {2}({3}))", access == "" ? "*" : access, type, name, param1 == null ? "" : param1), pc.Method.ToString()); Assert.AreEqual(method == "method", ((pc.Flags & PointCutFlags.Method) != 0), "method check: " + s); Assert.AreEqual(access == "*" || access == "", pc.Method.AllAccess, "AllAccess: " + s); Assert.AreEqual(type == "*", pc.Method.AllRetTypes, "AllRetTypes: " + s); Assert.AreEqual(name, pc.Method.MethodName, "MethodName: " + s); Assert.AreEqual(access == "" ? "*" : access, pc.Method.Access, "Access: " + s); Assert.AreEqual(type, pc.Method.RetType, "RetType: " + s); if (param1 == null || param1.Length == 0) { Assert.AreEqual(0, pc.Method.Arguments.Length, "No Params: " + s); } else { Assert.AreEqual(1, pc.Method.Arguments.Length, "1 Param: " + s); Assert.AreEqual(param1, pc.Method.Arguments[0], "Param: " + s); } }
protected void pointcutsig1( PointCutDefinition pointcut ) //throws RecognitionException, TokenStreamException { String part1; MethodSignature ms = null; try { // for error handling { switch (LA(1)) { case ALL: { match(ALL); part1 = "*"; ms = AllMethodSignature.Instance; break; } case ID: { part1 = reg_ex(true); ms = new MethodSignature(part1, methodAll("*")); break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } } pointcut.Method = pointcutsig2(part1, ms); } catch (RecognitionException ex) { reportError(ex); consume(); consumeUntil(tokenSet_13_); } }
public void ParsingMethodAndPropertyWritePointcutDeclaration() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method|propertywrite(*)" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; Assert.AreEqual(1, def.PointCuts.Count); PointCutDefinition pointcut = def.PointCuts[0]; Assert.IsNotNull(pointcut); Assert.AreEqual(PointCutFlags.PropertyWrite | PointCutFlags.Method, pointcut.Flags); Assert.AreEqual(AllMethodSignature.Instance, pointcut.Method); }
public void ParsingPointcutDeclarationForPropertyNameNoArguments() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut property(* Name)" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(PointCutFlags.Property, pointcut.Flags); Assert.AreEqual("Name", pointcut.Method.MethodName); Assert.AreEqual(0, pointcut.Method.Arguments.Length); Assert.IsTrue(pointcut.Method.AllRetTypes); Assert.IsTrue(!pointcut.Method.AllArguments); }
public void ParsingPointcutDeclarationForMethodWithRegExp() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method(* DoS.*(*))" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(PointCutFlags.Method, pointcut.Flags); Assert.AreEqual("DoS.*", pointcut.Method.MethodName); Assert.AreEqual(1, pointcut.Method.Arguments.Length); Assert.IsTrue(pointcut.Method.AllRetTypes); Assert.IsTrue(pointcut.Method.AllArguments); }
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 ParsingPointcutDeclarationForMethodDoSomethingWithTwoArgumentsAndRegEx() { AspectParser parser = CreateParser( "aspect XPTO for MyNamespace.MyType \r\n" + " " + " pointcut method(int DoSomething(string, *))" + " end" + " " + "end"); EngineConfiguration conf = parser.Parse(); AspectDefinition def = conf.Aspects[0]; PointCutDefinition pointcut = def.PointCuts[0]; Assert.AreEqual(PointCutFlags.Method, pointcut.Flags); Assert.AreEqual("DoSomething", pointcut.Method.MethodName); Assert.AreEqual(2, pointcut.Method.Arguments.Length); Assert.IsTrue(!pointcut.Method.AllRetTypes); Assert.AreEqual("int", pointcut.Method.RetType); Assert.IsTrue(!pointcut.Method.AllArguments); Assert.AreEqual("string", pointcut.Method.Arguments[0]); Assert.AreEqual("*", pointcut.Method.Arguments[1]); }
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 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 virtual void OnPointCutDefinition(PointCutDefinition pointcut) { pointcut.Advices.Accept(this); }
public override void OnPointCutDefinition(PointCutDefinition pointcut) { Push( Document.CreateNode(XmlNodeType.Element, "pointcut", null) ); XmlAttribute att = Document.CreateAttribute("symbol"); att.Value = pointcut.Flags.ToString(); Current.Attributes.Append( att ); Push( Document.CreateNode(XmlNodeType.Element, "signature", null) ); Current.InnerText = pointcut.Method.ToString(); Pop(); base.OnPointCutDefinition (pointcut); Pop(); }
public void ParsePointcutSignature(PointCutDefinition pointcut) { base.pointcuttarget(pointcut); }