示例#1
0
        private static void ExecuteDuplicationDetection(Result expectedResult, string codeText, string msgFromCodeComment)
        {
            TestLog.EmbedPlainText("The code", codeText);

            CompilationUnit cu = AstMatchHelper.ParseToCompilationUnit(codeText);

            // We require the first class in the file to have the Foo & Bar methods.
            var classes = cu.FindAllClasses();

            Assert.That(classes.Count(), Is.GreaterThan(0), "Expected at least one class to be in the test cs file.");

            // Expect two methods, Foo & Bar.
            IndexableMethodFinderVisitor visitor = new IndexableMethodFinderVisitor();

            classes.First().AcceptVisitor(visitor, null);

            Assert.AreEqual(visitor.FooMethod.Name, "Foo", "Expected a method named Foo.");
            Assert.AreEqual(visitor.BarMethod.Name, "Bar", "Expected a method named Bar.");

            AstComparisonVisitor cv = new AstComparisonVisitor();

            visitor.BarMethod.AcceptVisitor(cv, visitor.FooMethod);


            if (expectedResult == Result.Match)
            {
                Assert.IsTrue(cv.Match, "Expected Foo & Bar to match: " + msgFromCodeComment);
                Assert.That(visitor.BarMethod.Body.Matches2(visitor.FooMethod.Body));
            }
            else
            {
                Assert.IsFalse(cv.Match, "Expected Foo & Bar to not match: " + msgFromCodeComment);
                Assert.That(visitor.BarMethod.Matches2(visitor.FooMethod), Is.False);
            }
        }
示例#2
0
        public ScanResult GetCloneReplacements(CompilationUnit unit)
        {
            var instances = (from typeDec1 in unit.FindAllClasses()
                             from inf1 in ScanForClones(typeDec1)
                             select inf1).ToArray();


            return(new ScanResult(instances));
        }