@@ -543,54 +543,23 @@ private void generateMapper() {
543543
544544 mapperList .removeIf (metadata -> !metadata .isConvertGenerate ());
545545
546- // 兼容同模块下,同名不同包的场景
547546 mapperList .forEach (metadata -> {
548- String mapperName = metadata .mapperName ();
549- // 同名类时,增加后缀
550- Integer index = AUTO_MAPPER_INDEX .getOrDefault (mapperName , 0 );
551- if (index > 0 ) {
552- mapperName = mapperName + "__" + index ;
553- }
554- AUTO_MAPPER_INDEX .put (metadata .mapperName (), ++index );
555- metadata .setMapperName (mapperName );
556- });
547+ // 兼容同模块下,同名不同包的场景
548+ this .mapperNameAddSuffix (metadata );
557549
558- mapperList .forEach (metadata -> {
559550 if (metadata .isCycleAvoiding ()) {
560551 addAdapterMethod (metadata );
561552 } else {
562553 typeRelationMapper (metadata );
563554 }
564555 });
565556
566- // import dependency
567557 mapperList .forEach (metadata -> {
568- Set <TypeName > dependencies = metadata .getDependencies ();
569- if (CollectionUtils .isNotEmpty (dependencies )) {
570- List <ClassName > dependencyMappers = dependencies .stream ().map (dependency ->
571- typeRelationMappers .get (dependency .toString ())
572- ).filter (Objects ::nonNull ).flatMap (Collection ::stream ).collect (Collectors .toList ());
573-
574- if (CollectionUtils .isNotEmpty (dependencyMappers )) {
575- metadata .addUseList (dependencyMappers );
576- }
577- }
578- // source
579- List <ClassName > sourceDependencies =
580- typeRelationMappers .get (metadata .getSourceClassName ().reflectionName ());
581-
582- if (CollectionUtils .isNotEmpty (sourceDependencies )) {
583- metadata .addUseList (sourceDependencies );
584- }
585- // remove itself
586- if (CollectionUtils .isNotEmpty (metadata .getUsesClassNameList ())) {
587- metadata .getUsesClassNameList ()
588- .removeIf (use -> use .reflectionName ().equals (metadata .mapperClass ().reflectionName ()));
589- }
558+ this .relationDependencies (metadata );
559+ this .usesRemoveItself (metadata );
560+ this .writeAutoMapperClassFile (metadata );
590561 });
591562
592- mapperList .forEach (this ::writeAutoMapperClassFile );
593-
594563 adapterMapperGenerator .write (processingEnv ,
595564 methodMap .values (),
596565 AutoMapperProperties .getAdapterClassName (),
@@ -616,6 +585,45 @@ private void generateMapper() {
616585 }
617586 }
618587
588+ private void mapperNameAddSuffix (AutoMapperMetadata metadata ) {
589+ String mapperName = metadata .mapperName ();
590+ // 同名类时,增加后缀
591+ Integer index = AUTO_MAPPER_INDEX .getOrDefault (mapperName , 0 );
592+ if (index > 0 ) {
593+ mapperName = mapperName + "__" + index ;
594+ }
595+ AUTO_MAPPER_INDEX .put (metadata .mapperName (), ++index );
596+ metadata .setMapperName (mapperName );
597+ }
598+
599+ private void relationDependencies (AutoMapperMetadata metadata ) {
600+ Set <TypeName > dependencies = metadata .getDependencies ();
601+ if (CollectionUtils .isNotEmpty (dependencies )) {
602+ List <ClassName > dependencyMappers = dependencies .stream ().map (dependency ->
603+ typeRelationMappers .get (dependency .toString ())
604+ ).filter (Objects ::nonNull ).flatMap (Collection ::stream ).collect (Collectors .toList ());
605+
606+ if (CollectionUtils .isNotEmpty (dependencyMappers )) {
607+ metadata .addUseList (dependencyMappers );
608+ }
609+ }
610+ // source
611+ List <ClassName > sourceDependencies =
612+ typeRelationMappers .get (metadata .getSourceClassName ().reflectionName ());
613+
614+ if (CollectionUtils .isNotEmpty (sourceDependencies )) {
615+ metadata .addUseList (sourceDependencies );
616+ }
617+ }
618+
619+ private void usesRemoveItself (AutoMapperMetadata metadata ) {
620+ // remove itself
621+ if (CollectionUtils .isNotEmpty (metadata .getUsesClassNameList ())) {
622+ metadata .getUsesClassNameList ()
623+ .removeIf (use -> use .reflectionName ().equals (metadata .mapperClass ().reflectionName ()));
624+ }
625+ }
626+
619627 private Set <TypeName > listDependencies (TypeElement autoMapperEle ) {
620628 Set <TypeName > set = new HashSet <>();
621629
0 commit comments