ポイントカットを表します ポイントカットは以下の属性から構成されます
Наследование: IAspectElement
Пример #1
0
 // TODO テストを書く
 public Pointcut DeepCopy()
 {
     var copy = new Pointcut();
     copy.SetElementType(GetPointcutType());
     copy.SetName(GetName());
     copy.SetType(GetTargetType());
     // TODO パラメータもコピーする
     foreach (var name in GetTargetName()) {
         copy.SetTarget(name);
     }
     return copy;
 }
        public void ExecutionBeforeが正しく動作することを検証します(string language, string ext, string code)
        {
            var model = UnifiedGenerators.GenerateProgramFromFile(
                FixtureUtil.GetInputPath("Aspect", "Execution", "Fibonacci" + ext));
            var actual = UnifiedGenerators.GenerateProgramFromFile(
                FixtureUtil.GetInputPath("Aspect", "Execution", "Fibonacci_expectation_before" + ext));

            var pointcut = new Pointcut();
            pointcut.SetTarget("*");
            pointcut.SetTarget("fibonacci");

            CodeProcessorProvider.WeavingBefore("execution", model, pointcut, UcoGenerator.CreateAdvice(language, code));
            Assert.That(model,
                    Is.EqualTo(actual).Using(StructuralEqualityComparer.Instance));
        }
Пример #3
0
        public void 例外ポイントカットを作成してcatch節の中にコードを追加する()
        {
            // オリジナルのソースコードのUCOとアスペクト合成後に期待されるソースコードのUCOを生成する
            var model = UnifiedGenerators.GenerateProgramFromFile(_sourcePath);
            var actual = UnifiedGenerators.GenerateProgramFromFile(_expectationSourcePath);

            var pointcut = new Pointcut();
            pointcut.SetTarget("*");
            pointcut.SetTarget("Exception");

            // オリジナルのUCOに対して、アスペクトを合成する
            CodeProcessorProvider.WeavingBefore("exception", model, pointcut,
                UcoGenerator.CreateAdvice("Java", "System.out.println(\"test\");"));

            model.Normalize();

            var gen = UnifiedGenerators.GetCodeGeneratorByExtension(".java");
            Console.WriteLine(gen.Generate(model));
            Console.WriteLine(gen.Generate(actual));

            // 両者の構造を比較する
            Assert.That(model, Is.EqualTo(actual).Using(StructuralEqualityComparer.Instance));
        }
Пример #4
0
        public IAspectElement Visit(
            CommonTree root, int depth, IAspectElement element)
        {
            if (root.Token == null)
                return element;

            var token = root.Token.Text;
            switch (token) {
            case "ASPECT":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ASPECT_BODY":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ELEMENTS":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ELEMENT":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "INTERTYPE_DECLARATION":
                element = new Intertype();
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                Intertypes.Add((Intertype)element);
                return element;

            case "POINTCUT_DECLARATION":
                element = new Pointcut();
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                Pointcuts.Add((Pointcut)element);
                return element;

            case "ADVICE_DECLARATION":
                element = new Advice();
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                Advices.Add((Advice)element);
                return element;

            case "TYPE":
                element.SetType(root.GetChild(0).Text);
                return element;

            case "TARGET_CLASS":
                element.SetTarget(root.GetChild(0).Text);
                return element;

            case "POINTCUT_NAME":
                element.SetName(root.GetChild(0).Text);
                return element;

            case "IDENTIFIER_WITH_CLASS_NAME":
                foreach (var child in root.Children) {
                    element.SetTarget(((CommonTree)child).Text);
                }
                return element;

            case "PARAMETERS":
                if (root.ChildCount > 0) {
                    foreach (var child in root.Children) {
                        element = Visit((CommonTree)child, depth + 1, element);
                    }
                }
                return element;

            case "PARAMETER":
                element = Visit((CommonTree)root.Children[0], depth + 1, element);
                element.SetParameter(((CommonTree)root.Children[1]).Text);
                return element;

            case "PARAMETER_TYPE":
                element.SetParameterType(root.GetChild(0).Text);
                return element;

            case "ARGUMENTS":
                WriteIndent(depth);
                Console.WriteLine("<" + token + ">");
                foreach (var child in root.Children) {
                    Visit((CommonTree)child, depth + 1, element);
                }
                WriteIndent(depth);
                Console.WriteLine("</ " + token + ">");
                return element;

            case "ARGUMENT":
                WriteIndent(depth);
                Console.WriteLine("<" + token + ">");
                foreach (var child in root.Children) {
                    Visit((CommonTree)child, depth + 1, element);
                }
                WriteIndent(depth);
                Console.WriteLine("</ " + token + ">");
                return element;

            case "POINTCUT_DECLARATOR":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "POINTCUT_TYPE":
                element.SetElementType(root.GetChild(0).Text);
                return element;

            case "ADVICE_BODY":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ADVICE_TYPE":
                element.SetElementType(root.GetChild(0).Text);
                return element;

            case "ADVICE_TARGET":
                element.SetTarget(root.GetChild(0).Text);
                return element;

            case "CONTENTS":
                foreach (var child in root.Children) {
                    element.SetContents(((CommonTree)child).Text);
                }
                return element;

            case "LANGUAGE_DECLARATION":
                element.SetLanguageType(root.GetChild(0).Text);
                return element;

            case "LANGUAGE_DEPEND_BLOCK":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            default:
                return element;
            }
        }