Community
Participate
Working Groups
If we have the following method in the code public abstract java.lang.String mappedName() default "TEST"; There is no way to get the default value OR string representation of the default value. Since this information is part of the method declaration, it would be very useful to get it from IMethod.
To be added for 3.4M4
Proposed API on IMethod: /** * Returns the source of the default value of this annotation method. * Returns <code>null</code> if this method's parent is not an annotation * type, if it is a binary method, or if it has no default value. * * @exception JavaModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource. * @since 3.4 */ String getDefaultValueSource() throws JavaModelException; Leho, does it correspond to what you expect?
Jerome, I am concerned that this won't work for binary methods. Is there any way to get this information for binary method using Java model? ( If not, does it mean that we will be forced to use some kind of reflection calls (getDefaultValue() on java.lang.reflect.Method) to get it ?). Thanks !
(In reply to comment #3) > Jerome, I am concerned that this won't work for binary methods. Is there any > way to get this information for binary method using Java model? ( If not, does > it mean that we will be forced to use some kind of reflection calls > (getDefaultValue() on java.lang.reflect.Method) to get it ?). > Thanks ! > I guess we could use the attached source for binary method. However this would still return null if no source is attached. But do you really need the source of the default value? Or would you rather have a default IMemberValuePair? This way you could get the value (using IMemberValuePair#getValue()) in both source and binary case. However note that getValue() would return null in the case of: public abstract java.lang.String mappedName() default "TEST" + 1; Would that be ok?
Hi Jerome, your proposal sounds promising :), however could you explain a bit more what do you mean by "default IMemberValuePair" ? Are you thinking of introducing new method on IAnnotation ? (something like getDefaultMemberValuePairs ?) that would certainly work for us if that is what you are thinking.
In fact, we will not be able to provide a getDefaultMemberValuePairs() method on IAnnotation as this would need resolving the annotation reference. Instead here is a new API proposal on IMethod: /** * Returns a {@link IMemberValuePair member value pair} representing the default * value of this annotation method. * Returns <code>null</code> if this method's parent is not an annotation * type, or if it does not have a default value. * <p> * Note that {@link IMemberValuePair#getValue()} might return <code>null</code>. * Please see this method for more details. * </p> * * @exception JavaModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource. * @since 3.4 */ IMemberValuePair getDefaultValue() throws JavaModelException;
This works for us, thanks A LOT Jerome !
Created attachment 83518 [details] Corresponding implementation and tests
API, implementation and tests released for 3.4M4
Implementation and tests are here in I20071211-0010. I would suggest that you improve the documentation.
I'm not sure what needs to be improved. Any suggestion?
Documentation looks OK for me. Verified for 3.4M4 looking at v_829 contents
After Maxime's feedback, the latest version of this API has been released as: /** * Returns a {@link IMemberValuePair member value pair} representing the default * value of this method if any, or <code>null</code> if this method's parent is * not an annotation type, or else if this method does not have a default value. * <p> * Note that {@link IMemberValuePair#getValue()} might return <code>null</code>. * Please see this method for more details. * </p> * * @exception JavaModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource. * @return a member pair value if any, or <code>null</code> if none * @since 3.4 */ IMemberValuePair getDefaultValue() throws JavaModelException;