Exemplo n.º 1
0
        public void ParsingInterceptorDeclaration()
        {
            AspectParser parser = CreateParser(
                "interceptors \r\n" +
                "[" +
                "\"customer\" : Interceptor" +
                "]");
            EngineConfiguration conf = parser.Parse();

            Assert.IsNotNull(conf);
            Assert.IsNotNull(conf.Interceptors);
            Assert.AreEqual(1, conf.Interceptors.Count);
            InterceptorEntryDefinition def = conf.Interceptors[0];

            Assert.IsNotNull(def);
            Assert.AreEqual("customer", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Interceptor", def.TypeReference.TypeName);
        }
        public void ParsingAspectWithMixinRefDeclaration()
        {
            AspectParser parser = CreateParser(
                "aspect XPTO for MyNamespace.MyType \r\n" +
                "" +
                "  include \"customer\"" +
                "" +
                "" +
                "end");
            EngineConfiguration conf = parser.Parse();
            AspectDefinition    def  = conf.Aspects[0];

            Assert.AreEqual(1, def.Mixins.Count);

            MixinDefinition typeName = def.Mixins[0];

            Assert.AreEqual(TargetTypeEnum.Link, typeName.TypeReference.TargetType);
            Assert.AreEqual("customer", typeName.TypeReference.LinkRef);
        }
        public void ParsingAspectForNamespaceWithExcludes()
        {
            AspectParser parser = CreateParser(
                "aspect XPTO for [ my.namespace.types excludes(Customer;Author) ] \r\n" +
                "end");
            EngineConfiguration conf = parser.Parse();

            Assert.IsNotNull(conf);
            Assert.IsNotNull(conf.Aspects);
            Assert.AreEqual(1, conf.Aspects.Count);
            AspectDefinition def = conf.Aspects[0];

            Assert.IsNotNull(def);
            Assert.AreEqual("XPTO", def.Name);
            Assert.AreEqual(TargetStrategyEnum.Namespace, def.TargetType.TargetStrategy);
            Assert.AreEqual("my.namespace.types", def.TargetType.NamespaceRoot);
            Assert.IsFalse(def.TargetType.IncludeSubNamespace);
            Assert.AreEqual(2, def.TargetType.Excludes.Count);
        }
        protected EngineConfiguration ParseContents()
        {
            AspectLanguageLexer lexer  = new AspectLanguageLexer(_reader);
            AspectParser        parser = new AspectParser(lexer);

            try
            {
                return(parser.Parse());
            }
            catch (antlr.RecognitionException e)
            {
                int         line        = e.getLine();
                int         startColumn = e.getColumn();
                String      filename    = e.getFilename();
                LexicalInfo info        = new LexicalInfo(filename, line, startColumn, -1);

                throw new BuilderException(info, e.Message);
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void ParsingPointcutDeclarationForMethodWithRegExpOnReturnType()
        {
            AspectParser parser = CreateParser(
                "aspect XPTO for MyNamespace.MyType \r\n" +
                " " +
                " pointcut method(strin.* DoSomething(*))" +
                " 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(1, pointcut.Method.Arguments.Length);
            Assert.IsTrue(!pointcut.Method.AllRetTypes);
            Assert.IsTrue(pointcut.Method.AllArguments);
            Assert.AreEqual("strin.*", pointcut.Method.RetType);
        }
Exemplo n.º 7
0
        public void ParsingMixinDeclarationWithAssembly()
        {
            AspectParser parser = CreateParser(
                "mixins \r\n" +
                "[" +
                "\"customer\" : Namespace.CustomerMixin in MyAssembly" +
                "]");
            EngineConfiguration conf = parser.Parse();

            Assert.IsNotNull(conf);
            Assert.IsNotNull(conf.Mixins);
            Assert.AreEqual(1, conf.Mixins.Count);
            MixinEntryDefinition def = conf.Mixins[0];

            Assert.IsNotNull(def);
            Assert.AreEqual("customer", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.CustomerMixin", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);
        }
        public void ParsingAspectWithSingleMixinDeclaration()
        {
            AspectParser parser = CreateParser(
                "aspect XPTO for MyNamespace.MyType \r\n" +
                "" +
                "  include MyNamespace.Type in MyAssembly " +
                "" +
                "" +
                "end");
            EngineConfiguration conf = parser.Parse();
            AspectDefinition    def  = conf.Aspects[0];

            Assert.AreEqual(1, def.Mixins.Count);

            MixinDefinition typeName = def.Mixins[0];

            Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType);
            Assert.AreEqual("MyNamespace.Type", typeName.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", typeName.TypeReference.AssemblyReference.AssemblyName);
        }
Exemplo n.º 9
0
        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 GenerateAspect()
        {
            AspectParser parser = CreateParser(
                "import XPTO " +
                "import XY in My.Assembly " +
                " " +
                " aspect McBrother for MyType in MyAssembly " +
                " end" +
                " ");
            EngineConfiguration conf = parser.Parse();

            XmlTreeVisitor visitor = new XmlTreeVisitor();

            visitor.Visit(conf);
            String content = visitor.Document.InnerXml;

            Assert.AreEqual("<configuration>" +
                            "<import namespace=\"XPTO\" />" +
                            "<import namespace=\"XY\" assembly=\"My.Assembly\" />" +
                            "<aspect name=\"McBrother\"><for>" +
                            "<singletype type=\"MyType\" refTypeEnum=\"Type\" assembly=\"MyAssembly\" />" +
                            "</for></aspect></configuration>", content);
        }
Exemplo n.º 11
0
        public void ParsingMixinsDeclarations()
        {
            AspectParser parser = CreateParser(
                "mixins \r\n" +
                "[" +
                "  \"key1\" : Namespace.CustomerMixin1 in MyAssembly;" +
                "  \"key2\" : Namespace.CustomerMixin2 in MyAssembly;" +
                "  \"key3\" : Namespace.CustomerMixin3 in MyAssembly" +
                "]");
            EngineConfiguration conf = parser.Parse();

            Assert.IsNotNull(conf);
            Assert.IsNotNull(conf.Mixins);
            Assert.AreEqual(3, conf.Mixins.Count);

            MixinEntryDefinition def = conf.Mixins[0];

            Assert.IsNotNull(def);
            Assert.AreEqual("key1", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.CustomerMixin1", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);

            def = conf.Mixins[1];
            Assert.IsNotNull(def);
            Assert.AreEqual("key2", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.CustomerMixin2", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);

            def = conf.Mixins[2];
            Assert.IsNotNull(def);
            Assert.AreEqual("key3", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.CustomerMixin3", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);
        }
Exemplo n.º 12
0
        public void ParsingInterceptorDeclarations()
        {
            AspectParser parser = CreateParser(
                "interceptors \r\n" +
                "[" +
                "  \"key1\" : Namespace.Interceptor1 in MyAssembly;" +
                "  \"key2\" : Namespace.Interceptor2 in MyAssembly;" +
                "  \"key3\" : Namespace.Interceptor3 in MyAssembly" +
                "]");
            EngineConfiguration conf = parser.Parse();

            Assert.IsNotNull(conf);
            Assert.IsNotNull(conf.Interceptors);
            Assert.AreEqual(3, conf.Interceptors.Count);

            InterceptorEntryDefinition def = conf.Interceptors[0];

            Assert.IsNotNull(def);
            Assert.AreEqual("key1", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.Interceptor1", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);

            def = conf.Interceptors[1];
            Assert.IsNotNull(def);
            Assert.AreEqual("key2", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.Interceptor2", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);

            def = conf.Interceptors[2];
            Assert.IsNotNull(def);
            Assert.AreEqual("key3", def.Key);
            Assert.AreEqual(TargetTypeEnum.Type, def.TypeReference.TargetType);
            Assert.AreEqual("Namespace.Interceptor3", def.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly", def.TypeReference.AssemblyReference.AssemblyName);
        }
Exemplo n.º 13
0
        public void InvalidImportDeclaration()
        {
            AspectParser parser = CreateParser("import \r\nimport \r\n");

            parser.Parse();
        }
Exemplo n.º 14
0
        protected EngineConfiguration CreateEngineConfiguration(String content)
        {
            AspectParser parser = base.CreateParser(content);

            return(parser.Parse());
        }