1010import com .squareup .javapoet .TypeName ;
1111import com .squareup .javapoet .TypeSpec ;
1212import java .util .Collection ;
13- import java .util .HashSet ;
13+ import java .util .TreeSet ;
1414import javax .lang .model .element .Modifier ;
1515
1616/**
@@ -29,7 +29,7 @@ public class HensonNavigatorGenerator extends BaseGenerator {
2929 public static final String HENSON_NAVIGATOR_CLASS_NAME = "Henson" ;
3030 public static final String WITH_CONTEXT_SET_STATE_CLASS_NAME = "WithContextSetState" ;
3131 private String packageName ;
32- private Collection <String > targetClassNames ;
32+ private Collection <InjectionTarget > targets ;
3333
3434 public HensonNavigatorGenerator (String packageName , Collection <InjectionTarget > targets ) {
3535 if (packageName != null ) {
@@ -38,7 +38,7 @@ public HensonNavigatorGenerator(String packageName, Collection<InjectionTarget>
3838 this .packageName = findCommonPackage (targets );
3939 }
4040
41- this .targetClassNames = getClassNamesWhereHensonCanGoto (targets );
41+ this .targets = getTargetsWhereHensonCanGoto (targets );
4242 }
4343
4444 private String hensonNavigatorClassName () {
@@ -78,8 +78,8 @@ private void emitNavigationMethods(TypeSpec.Builder hensonNavigatorTypeBuilder)
7878 .addParameter (ClassName .get ("android.content" , "Context" ), "context" )
7979 .addStatement ("this.context = context" )
8080 .build ());
81- for (String targetClassName : targetClassNames ) {
82- emitNavigationMethod (withContextSetStateBuilder , targetClassName );
81+ for (InjectionTarget target : targets ) {
82+ emitNavigationMethod (withContextSetStateBuilder , target );
8383 }
8484 hensonNavigatorTypeBuilder .addType (withContextSetStateBuilder .build ());
8585 }
@@ -99,7 +99,9 @@ private void emitWith(TypeSpec.Builder builder) {
9999 builder .addMethod (gotoMethodBuilder .build ());
100100 }
101101
102- private void emitNavigationMethod (TypeSpec .Builder builder , String targetClassName ) {
102+ private void emitNavigationMethod (TypeSpec .Builder builder , InjectionTarget target ) {
103+ String targetClassName = target .targetClass ;
104+ targetClassName = targetClassName .replace (target .className .replaceAll ("\\ $" , "." ), "" ) + target .className ;
103105 TypeName intentBuilderClassName =
104106 ClassName .bestGuess (targetClassName + IntentBuilderGenerator .BUNDLE_BUILDER_SUFFIX );
105107 String simpleTargetClassName = targetClassName .substring (targetClassName .lastIndexOf ('.' ) + 1 );
@@ -147,13 +149,13 @@ private String findCommonPackage(String commonPackageName, String packageName) {
147149 return commonRoot ;
148150 }
149151
150- private Collection <String > getClassNamesWhereHensonCanGoto (Collection <InjectionTarget > targets ) {
151- Collection <String > classNames = new HashSet <>();
152+ private Collection <InjectionTarget > getTargetsWhereHensonCanGoto (Collection <InjectionTarget > targets ) {
153+ Collection <InjectionTarget > canGotoTargets = new TreeSet <>();
152154 for (InjectionTarget injectionTarget : targets ) {
153155 if (!injectionTarget .isAbstractTargetClass ) {
154- classNames .add (injectionTarget . targetClass );
156+ canGotoTargets .add (injectionTarget );
155157 }
156158 }
157- return classNames ;
159+ return canGotoTargets ;
158160 }
159161}
0 commit comments