@@ -511,91 +511,93 @@ protected static Set<String> getRightSideFileNames(Method currentMethod, CommitM
511
511
protected static Set <String > getRightSideFileNames (String currentFilePath , String currentClassName , Set <String > toBeAddedFileNamesIfTheyAreNewFiles , CommitModel commitModel , UMLModelDiff umlModelDiff ) {
512
512
Set <String > fileNames = new HashSet <>();
513
513
fileNames .add (currentFilePath );
514
- UMLAbstractClass classInChildModel = umlModelDiff .findClassInChildModel (currentClassName );
514
+ Set < UMLAbstractClass > classesInChildModel = umlModelDiff .findClassesInChildModel (currentClassName );
515
515
boolean newlyAddedFile = isNewlyAddedFile (commitModel , currentFilePath );
516
- if (classInChildModel instanceof UMLClass ) {
517
- UMLClass umlClass = (UMLClass ) classInChildModel ;
518
-
519
- StringBuilder regxSb = new StringBuilder ();
520
-
521
- String orChar = "" ;
522
- if (umlClass .getSuperclass () != null ) {
523
- regxSb .append (orChar ).append ("\\ s*extends\\ s*" ).append (umlClass .getSuperclass ().getClassType ());
524
- orChar = "|" ;
525
- if (newlyAddedFile ) {
526
- regxSb .append (orChar ).append ("\\ s*class\\ s*" ).append (umlClass .getSuperclass ().getClassType ()).append ("\\ s\\ s*" );
527
- }
528
- }
529
-
530
- for (UMLType implementedInterface : umlClass .getImplementedInterfaces ()) {
531
- regxSb .append (orChar ).append ("\\ s*implements\\ s*.*" ).append (implementedInterface ).append ("\\ s*" );
532
- orChar = "|" ;
533
- if (newlyAddedFile ) {
534
- regxSb .append (orChar ).append ("\\ s*interface\\ s*" ).append (implementedInterface .getClassType ()).append ("\\ s*\\ {" );
535
- }
536
- }
537
-
538
- //newly added file
539
- if (newlyAddedFile ) {
540
- regxSb .append (orChar ).append ("@link\\ s*" ).append (umlClass .getNonQualifiedName ());
541
- orChar = "|" ;
542
- regxSb .append (orChar ).append ("new\\ s*" ).append (umlClass .getNonQualifiedName ()).append ("\\ (" );
543
- regxSb .append (orChar ).append ("@deprecated\\ s*.*" ).append (umlClass .getNonQualifiedName ()).append ("\\ s*.*\n " );
544
- regxSb .append (orChar ).append ("\\ s*extends\\ s*" ).append (umlClass .getNonQualifiedName ()).append ("\\ s*\\ {" );
545
- }
546
-
547
- String regx = regxSb .toString ();
548
- if (!regx .isEmpty ()) {
549
- Pattern pattern = Pattern .compile (regx );
550
- for (Map .Entry <String , String > entry : commitModel .fileContentsCurrentTrimmed .entrySet ()) {
551
- Matcher matcher = pattern .matcher (entry .getValue ());
552
- if (matcher .find ()) {
553
- String matcherGroup = matcher .group ().trim ();
554
- String filePath = entry .getKey ();
555
- boolean isAnExistingFile = commitModel .fileContentsBeforeTrimmed .containsKey (filePath ) || commitModel .renamedFilesHint .values ().stream ().anyMatch (s -> s .equals (filePath ));
556
- if (matcherGroup .startsWith ("extends" ) && matcherGroup .contains (umlClass .getNonQualifiedName ())) {
557
- if (isAnExistingFile ) {
558
- fileNames .add (filePath );
559
- }
560
- } else if (matcherGroup .startsWith ("implements" ) || matcherGroup .startsWith ("extends" )) {
561
- if (isAnExistingFile ) {
562
- String [] split = matcherGroup .split ("\\ s" );
563
- String className = split [split .length - 1 ];
564
- if (className .contains ("." )) {
565
- className = className .substring (0 , className .indexOf ("." ));
566
- }
567
- String [] tokens = CAMEL_CASE_SPLIT_PATTERN .split (className );
568
- final String fileName = className + ".java" ;
569
- if (commitModel .fileContentsCurrentTrimmed .keySet ().stream ().anyMatch (s -> s .endsWith (fileName ) || s .endsWith (tokens [tokens .length - 1 ] + ".java" ))) {
570
- fileNames .add (filePath );
571
- }
572
- }
573
- } else if (matcherGroup .startsWith ("new" )) {
574
- if (isAnExistingFile ) {
575
- fileNames .add (filePath );
576
- }
577
- } else if (matcherGroup .startsWith ("@link" )) {
578
- fileNames .add (filePath ); //TODO: add existing file condition and test
579
- } else if (matcherGroup .startsWith ("class" )) {
580
- if (isAnExistingFile ) {
581
- fileNames .add (filePath );
582
- }
583
- } else if (matcherGroup .startsWith ("@deprecated" )) {
584
- if (isAnExistingFile ) {
585
- fileNames .add (filePath );
586
- }
587
- } else if (matcherGroup .startsWith ("interface" )) {
588
- if (isAnExistingFile ) {
589
- fileNames .add (filePath );
590
- }
591
- }
592
-
593
- }
594
- }
595
- }
596
- if (!umlClass .isTopLevel ()) {
597
- fileNames .addAll (getRightSideFileNames (currentFilePath , umlClass .getPackageName (), toBeAddedFileNamesIfTheyAreNewFiles , commitModel , umlModelDiff ));
598
- }
516
+ for (UMLAbstractClass classInChildModel : classesInChildModel ) {
517
+ if (classInChildModel instanceof UMLClass ) {
518
+ UMLClass umlClass = (UMLClass ) classInChildModel ;
519
+
520
+ StringBuilder regxSb = new StringBuilder ();
521
+
522
+ String orChar = "" ;
523
+ if (umlClass .getSuperclass () != null ) {
524
+ regxSb .append (orChar ).append ("\\ s*extends\\ s*" ).append (umlClass .getSuperclass ().getClassType ());
525
+ orChar = "|" ;
526
+ if (newlyAddedFile ) {
527
+ regxSb .append (orChar ).append ("\\ s*class\\ s*" ).append (umlClass .getSuperclass ().getClassType ()).append ("\\ s\\ s*" );
528
+ }
529
+ }
530
+
531
+ for (UMLType implementedInterface : umlClass .getImplementedInterfaces ()) {
532
+ regxSb .append (orChar ).append ("\\ s*implements\\ s*.*" ).append (implementedInterface ).append ("\\ s*" );
533
+ orChar = "|" ;
534
+ if (newlyAddedFile ) {
535
+ regxSb .append (orChar ).append ("\\ s*interface\\ s*" ).append (implementedInterface .getClassType ()).append ("\\ s*\\ {" );
536
+ }
537
+ }
538
+
539
+ //newly added file
540
+ if (newlyAddedFile ) {
541
+ regxSb .append (orChar ).append ("@link\\ s*" ).append (umlClass .getNonQualifiedName ());
542
+ orChar = "|" ;
543
+ regxSb .append (orChar ).append ("new\\ s*" ).append (umlClass .getNonQualifiedName ()).append ("\\ (" );
544
+ regxSb .append (orChar ).append ("@deprecated\\ s*.*" ).append (umlClass .getNonQualifiedName ()).append ("\\ s*.*\n " );
545
+ regxSb .append (orChar ).append ("\\ s*extends\\ s*" ).append (umlClass .getNonQualifiedName ()).append ("\\ s*\\ {" );
546
+ }
547
+
548
+ String regx = regxSb .toString ();
549
+ if (!regx .isEmpty ()) {
550
+ Pattern pattern = Pattern .compile (regx );
551
+ for (Map .Entry <String , String > entry : commitModel .fileContentsCurrentTrimmed .entrySet ()) {
552
+ Matcher matcher = pattern .matcher (entry .getValue ());
553
+ if (matcher .find ()) {
554
+ String matcherGroup = matcher .group ().trim ();
555
+ String filePath = entry .getKey ();
556
+ boolean isAnExistingFile = commitModel .fileContentsBeforeTrimmed .containsKey (filePath ) || commitModel .renamedFilesHint .values ().stream ().anyMatch (s -> s .equals (filePath ));
557
+ if (matcherGroup .startsWith ("extends" ) && matcherGroup .contains (umlClass .getNonQualifiedName ())) {
558
+ if (isAnExistingFile ) {
559
+ fileNames .add (filePath );
560
+ }
561
+ } else if (matcherGroup .startsWith ("implements" ) || matcherGroup .startsWith ("extends" )) {
562
+ if (isAnExistingFile ) {
563
+ String [] split = matcherGroup .split ("\\ s" );
564
+ String className = split [split .length - 1 ];
565
+ if (className .contains ("." )) {
566
+ className = className .substring (0 , className .indexOf ("." ));
567
+ }
568
+ String [] tokens = CAMEL_CASE_SPLIT_PATTERN .split (className );
569
+ final String fileName = className + ".java" ;
570
+ if (commitModel .fileContentsCurrentTrimmed .keySet ().stream ().anyMatch (s -> s .endsWith (fileName ) || s .endsWith (tokens [tokens .length - 1 ] + ".java" ))) {
571
+ fileNames .add (filePath );
572
+ }
573
+ }
574
+ } else if (matcherGroup .startsWith ("new" )) {
575
+ if (isAnExistingFile ) {
576
+ fileNames .add (filePath );
577
+ }
578
+ } else if (matcherGroup .startsWith ("@link" )) {
579
+ fileNames .add (filePath ); //TODO: add existing file condition and test
580
+ } else if (matcherGroup .startsWith ("class" )) {
581
+ if (isAnExistingFile ) {
582
+ fileNames .add (filePath );
583
+ }
584
+ } else if (matcherGroup .startsWith ("@deprecated" )) {
585
+ if (isAnExistingFile ) {
586
+ fileNames .add (filePath );
587
+ }
588
+ } else if (matcherGroup .startsWith ("interface" )) {
589
+ if (isAnExistingFile ) {
590
+ fileNames .add (filePath );
591
+ }
592
+ }
593
+
594
+ }
595
+ }
596
+ }
597
+ if (!umlClass .isTopLevel ()) {
598
+ fileNames .addAll (getRightSideFileNames (currentFilePath , umlClass .getPackageName (), toBeAddedFileNamesIfTheyAreNewFiles , commitModel , umlModelDiff ));
599
+ }
600
+ }
599
601
}
600
602
601
603
@@ -607,8 +609,10 @@ protected static Set<String> getRightSideFileNames(String currentFilePath, Strin
607
609
);
608
610
609
611
if (newlyAddedFile ) {
610
- final String currentMethodFileName = currentFilePath .substring (currentFilePath .lastIndexOf ("/" ));
611
- fileNames .addAll (commitModel .fileContentsCurrentTrimmed .keySet ().stream ().filter (filePath -> filePath .endsWith (currentMethodFileName )).collect (Collectors .toSet ()));
612
+ for (String s : new HashSet <>(fileNames )) {
613
+ final String currentMethodFileName = s .substring (s .lastIndexOf ("/" ));
614
+ fileNames .addAll (commitModel .fileContentsCurrentTrimmed .keySet ().stream ().filter (filePath -> filePath .endsWith (currentMethodFileName )).collect (Collectors .toSet ()));
615
+ }
612
616
}
613
617
614
618
return fileNames ;
0 commit comments