Project: JDT
Bug 79112 [1.5] [model] accessing annotation on Java elements
Reported: 2004-11-19 15:58:48 | Status: verified fixed

In J2SE5, package, class, field, and method declaration can all carry annotations. Tools that work with Java code will need to be able to find out how a Java element has been annotated. They have no way to do this now. The support that is there now in DOM/AST is no sufficient: (1) Both Java compilation units and class files can carry annotations (DOM/AST only addresses annotations on source code). (2) The annotations that client tools would be looking for would be best described as "resolved annotations" that would have defaulted values. This will require new API. Proposal: Add IJavaElemement.resolveAnnotations() to return a list of resolved annotations. The data structure used to represent the resolved annotations is the interesting part. The value of an annotation type member can be a primitive type, String, Class, annotation, enumeration, or 1-dimensional arrays thereof. The data structure must be capable of describing all of these. The classes that appear in the class literals, enumeration types, and annotation types, could be local classes, meaning that there is no way to refer to these things using any sort of qualified name. The most general way to represent these classes is to use an DOM/AST ITypeBinding: public interface IResolvedAnnotation { ITypeBinding getAnnotationType(); /** key is annotation member name * value is one of boxed primitive (Integer, Boolean, Character, etc.) * String, ITypeBinding (Class literals), IResolvedAnnotation (nested annotations), IVariable (enum constants) */ public Map<String, Object> getValues(); }

Files changed in fix:
org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/JavaElementProperties.java org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/properties/MemberValuePairProperties.java org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEMemberValuePair.java org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JEViewLabelProvider.java org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElement.java org.eclipse.jdt.jeview/src/org/eclipse/jdt/jeview/views/JavaElementView.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/GenericRefactoringHandleTransplanter.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/EditorUtility.java org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java