public bool HasRefactoring() { refactorings = Enumerable.Empty<IManualRefactoring>(); SyntaxTree treeBefore = SyntaxTree.ParseCompilationUnit(before); SyntaxTree treeAfter = SyntaxTree.ParseCompilationUnit(after); // Get the classes in the code before and after. var classesBefore = treeBefore.GetRoot().DescendantNodes().Where(n => n.Kind == SyntaxKind.ClassDeclaration); var classesAfter = treeAfter.GetRoot().DescendantNodes().Where(n => n.Kind == SyntaxKind.ClassDeclaration); // Get the pairs of class declaration in the code before and after var paris = GetClassDeclarationPairs(classesBefore, classesAfter); foreach (var pair in paris) { var detector = new InClassExtractMethodDetector((ClassDeclarationSyntax)pair.Key, (ClassDeclarationSyntax)pair.Value); detector.SetSyntaxTreeBefore(treeBefore); detector.SetSyntaxTreeAfter(treeAfter); if(detector.HasRefactoring()) { refactorings = refactorings.Union(detector.GetRefactorings()); return true; } } return false; }
public bool HasRefactoring() { // Clear the memory before. refactorings.Clear(); documentBefore = RefactoringDetectionUtils.Convert2IDocument(sourceBefore); documentAfter = RefactoringDetectionUtils.Convert2IDocument(sourceAfter); // Get the syntax tree in before and after source. var treeBefore = (SyntaxTree)documentBefore.GetSyntaxTree(); var treeAfter = (SyntaxTree)documentAfter.GetSyntaxTree(); // Get their roots. var rootBefore = treeBefore.GetRoot(); var rootAfter = treeAfter.GetRoot(); // Get the clasess in the before and after tree. var beforeClasses = ASTUtil.GetClassDeclarations(rootBefore); var afterClasses = ASTUtil.GetClassDeclarations(rootAfter); var inClassDetector = new InClassExtractMethodDetector(documentBefore, documentAfter); foreach (ClassDeclarationSyntax beforeClass in beforeClasses) { foreach (ClassDeclarationSyntax afterClass in afterClasses) { // If the before class and after class have the identical name. if (beforeClass.Identifier.ValueText.Equals(afterClass.Identifier.ValueText)) { // Configure the in class detector. inClassDetector.SetSyntaxNodeBefore(beforeClass); inClassDetector.SetSyntaxNodeAfter(afterClass); // If the detector finds some refactoring, add these refactorings to the list. if (inClassDetector.HasRefactoring()) { refactorings.AddRange(inClassDetector.GetRefactorings()); } } } } return refactorings.Any(); }