picocli icon indicating copy to clipboard operation
picocli copied to clipboard

API provide IAnnotatedElement getter for all model xxSpec classes

Open remkop opened this issue 2 years ago • 2 comments

Discussion in #1718 showed that it may be useful if the API for each xxSpec class (CommandSpec, OptionSpec, ArgGroupSpec, etc) had a getAnnotatedElement method that would return the IAnnotatedElement for that xxSpec instance.

If the xxSpec instance was created programmatically, not from an annotation, then this method would return null.

remkop avatar Jul 19 '22 23:07 remkop

Just to clarify, when having something like:

@RequiredExclusive
@CommandLine.ArgGroup(multiplicity = "1", exclusive = true, validate = false)
GroupOpts group = new GroupOpts()

the IAnnotatedElement would correspond to the group field, so groupSpec.getAnnotatedElement().getAnnotation(RequiredExclusive.class) would return the RequiredExclusive annotation defined for the group field.

Also, IAnnotatedElement doesn't seem to have a method to get all defined annotations.

siilike avatar Jul 20 '22 10:07 siilike

Just to clarify, when having something like:

@RequiredExclusive
@CommandLine.ArgGroup(multiplicity = "1", exclusive = true, validate = false)
GroupOpts group = new GroupOpts()

the IAnnotatedElement would correspond to the group field, so groupSpec.getAnnotatedElement().getAnnotation(RequiredExclusive.class) would return the RequiredExclusive annotation defined for the group field.

Yes, that matches my understanding.

Also, IAnnotatedElement doesn't seem to have a method to get all defined annotations.

Okay, good point, so the IAnnotatedElement interface may need an additional method like getAnnotations.

remkop avatar Jul 20 '22 11:07 remkop