10
10
import com .squareup .javapoet .TypeName ;
11
11
import com .squareup .javapoet .TypeSpec ;
12
12
import java .util .Collection ;
13
- import java .util .HashSet ;
13
+ import java .util .TreeSet ;
14
14
import javax .lang .model .element .Modifier ;
15
15
16
16
/**
@@ -29,7 +29,7 @@ public class HensonNavigatorGenerator extends BaseGenerator {
29
29
public static final String HENSON_NAVIGATOR_CLASS_NAME = "Henson" ;
30
30
public static final String WITH_CONTEXT_SET_STATE_CLASS_NAME = "WithContextSetState" ;
31
31
private String packageName ;
32
- private Collection <String > targetClassNames ;
32
+ private Collection <InjectionTarget > targets ;
33
33
34
34
public HensonNavigatorGenerator (String packageName , Collection <InjectionTarget > targets ) {
35
35
if (packageName != null ) {
@@ -38,7 +38,7 @@ public HensonNavigatorGenerator(String packageName, Collection<InjectionTarget>
38
38
this .packageName = findCommonPackage (targets );
39
39
}
40
40
41
- this .targetClassNames = getClassNamesWhereHensonCanGoto (targets );
41
+ this .targets = getTargetsWhereHensonCanGoto (targets );
42
42
}
43
43
44
44
private String hensonNavigatorClassName () {
@@ -78,8 +78,8 @@ private void emitNavigationMethods(TypeSpec.Builder hensonNavigatorTypeBuilder)
78
78
.addParameter (ClassName .get ("android.content" , "Context" ), "context" )
79
79
.addStatement ("this.context = context" )
80
80
.build ());
81
- for (String targetClassName : targetClassNames ) {
82
- emitNavigationMethod (withContextSetStateBuilder , targetClassName );
81
+ for (InjectionTarget target : targets ) {
82
+ emitNavigationMethod (withContextSetStateBuilder , target );
83
83
}
84
84
hensonNavigatorTypeBuilder .addType (withContextSetStateBuilder .build ());
85
85
}
@@ -99,7 +99,10 @@ private void emitWith(TypeSpec.Builder builder) {
99
99
builder .addMethod (gotoMethodBuilder .build ());
100
100
}
101
101
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 =
105
+ targetClassName .replace (target .className .replaceAll ("\\ $" , "." ), "" ) + target .className ;
103
106
TypeName intentBuilderClassName =
104
107
ClassName .bestGuess (targetClassName + IntentBuilderGenerator .BUNDLE_BUILDER_SUFFIX );
105
108
String simpleTargetClassName = targetClassName .substring (targetClassName .lastIndexOf ('.' ) + 1 );
@@ -147,13 +150,14 @@ private String findCommonPackage(String commonPackageName, String packageName) {
147
150
return commonRoot ;
148
151
}
149
152
150
- private Collection <String > getClassNamesWhereHensonCanGoto (Collection <InjectionTarget > targets ) {
151
- Collection <String > classNames = new HashSet <>();
153
+ private Collection <InjectionTarget > getTargetsWhereHensonCanGoto (
154
+ Collection <InjectionTarget > targets ) {
155
+ Collection <InjectionTarget > canGotoTargets = new TreeSet <>();
152
156
for (InjectionTarget injectionTarget : targets ) {
153
157
if (!injectionTarget .isAbstractTargetClass ) {
154
- classNames .add (injectionTarget . targetClass );
158
+ canGotoTargets .add (injectionTarget );
155
159
}
156
160
}
157
- return classNames ;
161
+ return canGotoTargets ;
158
162
}
159
163
}
0 commit comments