@@ -522,7 +522,12 @@ public ArgGroupSpec.Builder visitExecutable(ExecutableElement e, Void aVoid) {
522522
523523 DeclaredType declaredType = getDeclaredTypeForArgGroupVarOrMethod (element , this );
524524 if (declaredType != null ) {
525- context .argGroupElementsByType .put (declaredType , builder );
525+ List <ArgGroupSpec .Builder > existingBuilders = context .argGroupElementsByType .get (declaredType );
526+ if (existingBuilders == null ) {
527+ existingBuilders = new ArrayList <ArgGroupSpec .Builder >();
528+ context .argGroupElementsByType .put (declaredType , existingBuilders );
529+ }
530+ existingBuilders .add (builder );
526531 processEnclosedElements (context , roundEnv , declaredType .asElement ().getEnclosedElements ());
527532 }
528533 }
@@ -638,7 +643,12 @@ private void buildOptionsAndPositionalsFromMethodParameters(ExecutableElement me
638643
639644 DeclaredType declaredType = getDeclaredTypeForArgGroupVarOrMethod (variable , this );
640645 if (declaredType != null ) {
641- context .argGroupElementsByType .put (declaredType , builder );
646+ List <ArgGroupSpec .Builder > existingBuilders = context .argGroupElementsByType .get (declaredType );
647+ if (existingBuilders == null ) {
648+ existingBuilders = new ArrayList <ArgGroupSpec .Builder >();
649+ context .argGroupElementsByType .put (declaredType , existingBuilders );
650+ }
651+ existingBuilders .add (builder );
642652 }
643653
644654 } else if (!isMixin ) { // params without any annotation are also positional
@@ -859,7 +869,7 @@ static class Context {
859869 Map <Element , OptionSpec .Builder > options = new LinkedHashMap <Element , OptionSpec .Builder >();
860870 Map <Element , PositionalParamSpec .Builder > parameters = new LinkedHashMap <Element , PositionalParamSpec .Builder >();
861871 Map <Element , ArgGroupSpec .Builder > argGroupElementsByVar = new LinkedHashMap <Element , ArgGroupSpec .Builder >();
862- Map <DeclaredType , ArgGroupSpec .Builder > argGroupElementsByType = new LinkedHashMap <DeclaredType , ArgGroupSpec .Builder >();
872+ Map <DeclaredType , List < ArgGroupSpec .Builder >> argGroupElementsByType = new LinkedHashMap <DeclaredType , List < ArgGroupSpec .Builder > >();
863873 Map <CommandSpec , Set <MixinInfo >> mixinInfoMap = new IdentityHashMap <CommandSpec , Set <MixinInfo >>();
864874 Map <Element , IAnnotatedElement > parentCommandElements = new LinkedHashMap <Element , IAnnotatedElement >();
865875 Map <Element , IAnnotatedElement > specElements = new LinkedHashMap <Element , IAnnotatedElement >();
@@ -882,10 +892,12 @@ private void connectModel(AbstractCommandSpecProcessor proc) {
882892
883893 for (Map .Entry <Element , OptionSpec .Builder > option : options .entrySet ()) {
884894 TypeMirror typeMirror = option .getKey ().getEnclosingElement ().asType ();
885- ArgGroupSpec .Builder group = argGroupElementsByType .get (typeMirror );
886- if (group != null ) {
887- logger .fine ("Building OptionSpec for " + option + " in arg group " + group );
888- group .addArg (option .getValue ().build ());
895+ List <ArgGroupSpec .Builder > groups = argGroupElementsByType .get (typeMirror );
896+ if (groups != null && !groups .isEmpty ()) {
897+ for (ArgGroupSpec .Builder group : groups ) {
898+ logger .fine ("Building OptionSpec for " + option + " in arg group " + group );
899+ group .addArg (option .getValue ().build ());
900+ }
889901 } else {
890902 CommandSpec commandSpec = getOrCreateCommandSpecForArg (option .getKey (), commands );
891903 logger .fine ("Building OptionSpec for " + option + " in spec " + commandSpec );
@@ -894,10 +906,12 @@ private void connectModel(AbstractCommandSpecProcessor proc) {
894906 }
895907 for (Map .Entry <Element , PositionalParamSpec .Builder > parameter : parameters .entrySet ()) {
896908 TypeMirror typeMirror = parameter .getKey ().getEnclosingElement ().asType ();
897- ArgGroupSpec .Builder group = argGroupElementsByType .get (typeMirror );
898- if (group != null ) {
899- logger .fine ("Building PositionalParamSpec for " + parameter + " in arg group " + group );
900- group .addArg (parameter .getValue ().build ());
909+ List <ArgGroupSpec .Builder > groups = argGroupElementsByType .get (typeMirror );
910+ if (groups != null && !groups .isEmpty ()) {
911+ for (ArgGroupSpec .Builder group : groups ) {
912+ logger .fine ("Building PositionalParamSpec for " + parameter + " in arg group " + group );
913+ group .addArg (parameter .getValue ().build ());
914+ }
901915 } else {
902916 CommandSpec commandSpec = getOrCreateCommandSpecForArg (parameter .getKey (), commands );
903917 logger .fine ("Building PositionalParamSpec for " + parameter );
0 commit comments