@@ -1826,6 +1826,13 @@ private boolean instanceAttributeMovedAlongWithMethod(UMLAttribute addedAttribut
1826
1826
return true ;
1827
1827
}
1828
1828
}
1829
+ else if (r instanceof MoveCodeRefactoring ) {
1830
+ MoveCodeRefactoring move = (MoveCodeRefactoring )r ;
1831
+ if (move .getSourceContainer ().getClassName ().equals (removedAttribute .getClassName ()) &&
1832
+ move .getTargetContainer ().getClassName ().equals (addedAttribute .getClassName ())) {
1833
+ return true ;
1834
+ }
1835
+ }
1829
1836
else if (r instanceof ExtractOperationRefactoring ) {
1830
1837
ExtractOperationRefactoring extract = (ExtractOperationRefactoring )r ;
1831
1838
if (extract .getSourceOperationBeforeExtraction ().getClassName ().equals (removedAttribute .getClassName ()) &&
@@ -3275,6 +3282,7 @@ else if(!diffs2.isEmpty()) {
3275
3282
if (allOperationsInAddedClasses .size () <= MAXIMUM_NUMBER_OF_COMPARED_METHODS ) {
3276
3283
checkForExtractedAndMovedOperations (getOperationBodyMappersInCommonClasses (), allOperationsInAddedClasses );
3277
3284
}
3285
+ checkForMovedCodeBetweenTestFixtures ();
3278
3286
List <MoveAttributeRefactoring > moveAttributeRefactorings = new ArrayList <MoveAttributeRefactoring >();
3279
3287
moveAttributeRefactorings .addAll (checkForAttributeMovesBetweenCommonClasses (renameMap , refactorings ));
3280
3288
moveAttributeRefactorings .addAll (checkForAttributeMovesIncludingAddedClasses (renameMap , refactorings ));
@@ -5507,6 +5515,56 @@ else if(r instanceof MoveOperationRefactoring) {
5507
5515
}
5508
5516
}
5509
5517
5518
+ private void checkForMovedCodeBetweenTestFixtures () throws RefactoringMinerTimedOutException {
5519
+ List <UMLOperationBodyMapper > mappersWithUnmatchedStatementsInSetUpT1 = new ArrayList <UMLOperationBodyMapper >();
5520
+ List <UMLOperationBodyMapper > mappersWithUnmatchedStatementsInSetUpT2 = new ArrayList <UMLOperationBodyMapper >();
5521
+ List <UMLOperationBodyMapper > mappersWithUnmatchedStatementsInTearDownT1 = new ArrayList <UMLOperationBodyMapper >();
5522
+ List <UMLOperationBodyMapper > mappersWithUnmatchedStatementsInTearDownT2 = new ArrayList <UMLOperationBodyMapper >();
5523
+ for (UMLClassDiff classDiff : commonClassDiffList ) {
5524
+ for (UMLOperationBodyMapper mapper : classDiff .getOperationBodyMapperList ()) {
5525
+ if (mapper .involvesSetUpMethods () || mapper .getContainer1 ().getName ().equals ("setUp" )) {
5526
+ if (mapper .getNonMappedLeavesT1 ().size () > 0 || mapper .getNonMappedInnerNodesT1 ().size () > 0 ) {
5527
+ mappersWithUnmatchedStatementsInSetUpT1 .add (mapper );
5528
+ }
5529
+ else if (mapper .getNonMappedLeavesT2 ().size () > 0 || mapper .getNonMappedInnerNodesT2 ().size () > 0 ) {
5530
+ mappersWithUnmatchedStatementsInSetUpT2 .add (mapper );
5531
+ }
5532
+ }
5533
+ else if (mapper .involvesTearDownMethods () || mapper .getContainer1 ().getName ().equals ("tearDown" )) {
5534
+ if (mapper .getNonMappedLeavesT1 ().size () > 0 || mapper .getNonMappedInnerNodesT1 ().size () > 0 ) {
5535
+ mappersWithUnmatchedStatementsInTearDownT1 .add (mapper );
5536
+ }
5537
+ else if (mapper .getNonMappedLeavesT2 ().size () > 0 || mapper .getNonMappedInnerNodesT2 ().size () > 0 ) {
5538
+ mappersWithUnmatchedStatementsInTearDownT2 .add (mapper );
5539
+ }
5540
+ }
5541
+ }
5542
+ }
5543
+ List <UMLOperationBodyMapper > moveCodeMappers = new ArrayList <>();
5544
+ for (UMLOperationBodyMapper mapperT1 : mappersWithUnmatchedStatementsInSetUpT1 ) {
5545
+ for (UMLOperationBodyMapper mapperT2 : mappersWithUnmatchedStatementsInSetUpT2 ) {
5546
+ UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper (mapperT1 , mapperT2 , mapperT1 .getClassDiff ());
5547
+ if (moveCodeMapper .getMappings ().size () > 0 ) {
5548
+ MoveCodeRefactoring ref = new MoveCodeRefactoring (moveCodeMapper .getContainer1 (), moveCodeMapper .getContainer2 (), moveCodeMapper , Type .MOVE_BETWEEN_FILES );
5549
+ if (!moveCodeMappers .contains (moveCodeMapper ))
5550
+ moveCodeMappers .add (moveCodeMapper );
5551
+ refactorings .add (ref );
5552
+ }
5553
+ }
5554
+ }
5555
+ for (UMLOperationBodyMapper mapperT1 : mappersWithUnmatchedStatementsInTearDownT1 ) {
5556
+ for (UMLOperationBodyMapper mapperT2 : mappersWithUnmatchedStatementsInTearDownT2 ) {
5557
+ UMLOperationBodyMapper moveCodeMapper = new UMLOperationBodyMapper (mapperT1 , mapperT2 , mapperT1 .getClassDiff ());
5558
+ if (moveCodeMapper .getMappings ().size () > 0 ) {
5559
+ MoveCodeRefactoring ref = new MoveCodeRefactoring (moveCodeMapper .getContainer1 (), moveCodeMapper .getContainer2 (), moveCodeMapper , Type .MOVE_BETWEEN_FILES );
5560
+ if (!moveCodeMappers .contains (moveCodeMapper ))
5561
+ moveCodeMappers .add (moveCodeMapper );
5562
+ refactorings .add (ref );
5563
+ }
5564
+ }
5565
+ }
5566
+ }
5567
+
5510
5568
private Map <UMLTypeParameter , UMLType > typeParameterToTypeArgumentMap (String subclass , String superclass ) {
5511
5569
Map <UMLTypeParameter , UMLType > typeParameterToTypeArgumentMap = new LinkedHashMap <UMLTypeParameter , UMLType >();
5512
5570
UMLClassBaseDiff subclassDiff = getUMLClassDiff (subclass );
0 commit comments