@@ -122,22 +122,24 @@ private void processModules(RoundEnvironment roundEnv) throws IOException {
122
122
}
123
123
}
124
124
125
- AlternativeMethod m = new AlternativeMethod (
126
- exec .getReturnType ().toString (),
125
+ // the conditional component name, is the one specified in @Alternative annotation or the simple name of the produced class
126
+ String componentName = !alternative .named ().isEmpty () ? alternative .named () : alternativeTo .getSimpleName ().toString ();
127
+
128
+ ConditionalProviderMethod m = new ConditionalProviderMethod (
127
129
alternativeTo .getQualifiedName ().toString (),
128
- alternativeTo . getSimpleName (). toString () ,
130
+ componentName ,
129
131
exec .getSimpleName ().toString (),
130
132
alternative .priority (),
131
- !alternative .named ().isEmpty () ? Optional .of (alternative .named ()) : Optional .<String >absent (),
132
133
when .name (),
133
134
when .value (),
135
+ "Alternative" ,
134
136
exec );
135
137
136
138
buildInjectableParams (exec , m .parameters );
137
139
138
140
buildCheckedExceptions (exec , m .exceptions );
139
141
140
- module .alternativeMethods .add (m );
142
+ module .conditionalProviderMethods .add (m );
141
143
}
142
144
}
143
145
}
@@ -315,7 +317,7 @@ private Optional<String> getInjectionName(Named named) {
315
317
316
318
private void generateMachineFile (ModuleClass moduleClass ) throws IOException {
317
319
List <ImmutableMap <String , Object >> engines = Lists .newArrayList ();
318
- List <ImmutableMap <String , Object >> alternativesEngines = Lists .newArrayList ();
320
+ List <ImmutableMap <String , Object >> conditionalsEngines = Lists .newArrayList ();
319
321
320
322
for (ProviderMethod method : moduleClass .providerMethods ) {
321
323
engines .add (ImmutableMap .<String , Object >builder ()
@@ -331,12 +333,11 @@ private void generateMachineFile(ModuleClass moduleClass) throws IOException {
331
333
.build ());
332
334
}
333
335
334
- for (AlternativeMethod method : moduleClass .alternativeMethods ) {
335
- alternativesEngines .add (ImmutableMap .<String , Object >builder ()
336
+ for (ConditionalProviderMethod method : moduleClass .conditionalProviderMethods ) {
337
+ conditionalsEngines .add (ImmutableMap .<String , Object >builder ()
336
338
.put ("componentType" , method .componentType )
337
- .put ("alternativeToComponentType" , method .alternativeType )
338
- .put ("alternativeToComponentName" , method .injectionName .or (method .alternativeName ))
339
- .put ("alternativeToComponentSimpleName" , method .alternativeName )
339
+ .put ("componentName" , method .componentName )
340
+ .put ("conditionalFactoryMachineName" , method .methodName + method .componentName + method .factoryMachineNameSuffix )
340
341
.put ("whenName" , method .whenName )
341
342
.put ("whenValue" , method .whenValue )
342
343
.put ("priority" , method .priority )
@@ -355,7 +356,7 @@ private void generateMachineFile(ModuleClass moduleClass) throws IOException {
355
356
.put ("moduleType" , moduleClass .name )
356
357
.put ("priority" , moduleClass .priority )
357
358
.put ("engines" , engines )
358
- .put ("alternativesEngines " , alternativesEngines )
359
+ .put ("conditionalsEngines " , conditionalsEngines )
359
360
.build ();
360
361
361
362
generateJavaClass (moduleClass .fqcn + "FactoryMachine" , moduleMachineTpl , ctx ,
@@ -580,7 +581,7 @@ private static class ModuleClass {
580
581
final String fqcn ;
581
582
582
583
final List <ProviderMethod > providerMethods = Lists .newArrayList ();
583
- final List <AlternativeMethod > alternativeMethods = Lists .newArrayList ();
584
+ final List <ConditionalProviderMethod > conditionalProviderMethods = Lists .newArrayList ();
584
585
final Element originatingElement ;
585
586
final String pack ;
586
587
final String name ;
@@ -613,31 +614,29 @@ private static class ProviderMethod {
613
614
}
614
615
}
615
616
616
- private static class AlternativeMethod {
617
+ private static class ConditionalProviderMethod {
617
618
final Element originatingElement ;
618
619
final String componentType ;
619
- final String alternativeType ;
620
- final String alternativeName ;
620
+ final String componentName ;
621
621
final String methodName ;
622
622
final int priority ;
623
- final Optional <String > injectionName ;
624
623
final String whenName ;
625
624
final String whenValue ;
625
+ final String factoryMachineNameSuffix ;
626
626
final List <InjectableParameter > parameters = Lists .newArrayList ();
627
627
final List <String > exceptions = Lists .newArrayList ();
628
628
629
- AlternativeMethod (String componentType , String alternativeType ,
630
- String alternativeName , String methodName , int priority , Optional < String > injectionName ,
631
- String whenName , String whenValue , Element originatingElement ) {
629
+ ConditionalProviderMethod (String componentType ,
630
+ String componentName , String methodName , int priority ,
631
+ String whenName , String whenValue , String factoryMachineNameSuffix , Element originatingElement ) {
632
632
this .componentType = componentType ;
633
- this .alternativeType = alternativeType ;
634
- this .alternativeName = alternativeName ;
633
+ this .componentName = componentName ;
635
634
this .methodName = methodName ;
636
635
this .priority = priority ;
637
- this .injectionName = injectionName ;
638
636
this .whenName = whenName ;
639
637
this .whenValue = whenValue ;
640
638
this .originatingElement = originatingElement ;
639
+ this .factoryMachineNameSuffix = factoryMachineNameSuffix ;
641
640
}
642
641
}
643
642
0 commit comments