Closed sviperll closed 9 years ago
Well I extended the API slightly, but providing APIs like "getParameterIntValue" is a tricky thing because the members can be of arbitrary classes (JAnnotationArrayMember, JAnnotationStringValue or JAnnotationUse itself). Instead I provided a generic "getParam" returning AbstractJAnnotationValue, a "getConstantParam" returning only JAnnotationStringValue and finally "getConstantParamValue" returning the value expression inside the JAnnotationStringValue. Now if accessors for primitives are required there are imho 2 options: 1. provide a default value in the method (like 'int getParamIntValue (String name, int defaultValue)') or 2. return the primitive wrapper type (like 'Integer getParamIntValue (String name)') which can therefore be null.
I personally think the second alternative looks nicer.
Actually I was thinking about accessing actual parameter values, not their code model. See this two classes to get an idea of what I want:
I do get your point. Currently the following types are supported: 8 primitives, String, Class<?> -> no problem for them IJExpression, AbstractJType, JEnumConstant -> they are already "code modelled"
I could add a method "public Object getNativeValue()" to JAnnotationStringValue that returns the original object before it is wrapped. I would really like to spare the additional map from name to value if possible. Ok?
This sounds good, thank you.
About code modeled values... My reasoning was that annotation parameters should be "compile-time constants", they always have some native value during compilation time, so this IJExpression, AbstractJType, JEnumConstant should always have some known value... May be it's better to deprecate this methods, and always ask for some actual value...
Please check the trunk if that fits your needs. I deprecated the version with "IJExpression" but left the ones with AbstractJType and JEnumConstant, because otherwise generated enums could not be used in there
Checked latest version. Works for my needs. Thanx.
OK, so I will start the release process...
2.7.6 out now - already on Maven Central
Annotation parameters are compile-time values. It would be convinient to access them all the way through code generation. AnnotationUse class should be extended to provide access to parameter values
Add
method or add collection of methods corresponding to AnnotationUse.param methods:
int getParameterIntValue(String parameterName); long getParameterLongValue(String parameterName); ... int[] getParameterIntArrayValue(String parameterName); long[] getParameterLongArrayValue(String parameterName); ... String getParameterStringValue(String parameterName); Annotation getParameterAnnotationValue(String parameterName); Class<?> getParameterClassValue(String parameterName); Enum<?> getParameterEnumValue(String parameterName); ... String[] getParameterStringArrayValue(String parameterName); ...