コード例 #1
0
        private void AnalyzeClassSuperTrees(SyntaxNodeAnalysisContext context)
        {
            ClassDeclarationSyntax @class = context.Node as ClassDeclarationSyntax;

            LeavesInClass         source      = new LeavesInClass(@class);
            NodeToNode            pre         = new NodeToNode();
            SingleTreeInformation information = new SingleTreeInformation(context.SemanticModel);
            ISyntaxComparator <SyntaxLeafPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation> comparator = new SuperTreeComparator <SyntaxLeafPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation>();

            SimilarityFinder <SyntaxLeafPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation> analyzer = new SimilarityFinder <SyntaxLeafPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation>(source, pre, Enumerable.Repeat(comparator, 1).ToList(), information);
            IEnumerable <SyntaxLeafPair <NodeAsRepresentation> > similarities = analyzer.FindAll();
        }
コード例 #2
0
        private void AnalyzeClassSubTrees(SyntaxNodeAnalysisContext context)
        {
            ClassDeclarationSyntax @class = context.Node as ClassDeclarationSyntax;

            MethodFragmentsInClass source = new MethodFragmentsInClass(@class);
            NodeToNode             pre    = new NodeToNode();
            ISyntaxComparator <SyntaxPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation> comparator = (ISyntaxComparator <SyntaxPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation>) new StructuralComparator <SyntaxPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation>();
            SingleTreeInformation information = new SingleTreeInformation(context.SemanticModel);

            SimilarityFinder <SyntaxPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation> analyzer = new SimilarityFinder <SyntaxPair <NodeAsRepresentation>, NodeAsRepresentation, SingleTreeInformation>(source, pre, Enumerable.Repeat(comparator, 1).ToList(), information);
            IEnumerable <SyntaxPair <NodeAsRepresentation> > similarities = analyzer.FindAll();

            SyntaxPair <NodeAsRepresentation> similarity = similarities.OrderByDescending(s => s.Left.Node.DescendantNodes().Count()).Take(1).Single();


            Report(context, similarity.Left.Node, similarity.Right.Node);
        }