### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/ClassFileInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileInfo.java,v retrieving revision 1.44 diff -u -r1.44 ClassFileInfo.java --- model/org/eclipse/jdt/internal/core/ClassFileInfo.java 7 Mar 2009 01:08:08 -0000 1.44 +++ model/org/eclipse/jdt/internal/core/ClassFileInfo.java 8 Apr 2009 19:51:40 -0000 @@ -57,12 +57,49 @@ private void generateAnnotationInfo(JavaElement parent, HashMap newElements, IBinaryAnnotation annotationInfo) { char[] typeName = org.eclipse.jdt.core.Signature.toCharArray(CharOperation.replaceOnCopy(annotationInfo.getTypeName(), '/', '.')); Annotation annotation = new Annotation(parent, new String(typeName)); + while (newElements.containsKey(annotation)) { + annotation.occurrenceCount++; + } + newElements.put(annotation, annotationInfo); + IBinaryElementValuePair[] pairs = annotationInfo.getElementValuePairs(); + for (int i = 0, length = pairs.length; i < length; i++) { + Object value = pairs[i].getValue(); + if (value instanceof IBinaryAnnotation) { + generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) value, new String(pairs[i].getName())); + } else if (value instanceof Object[]) { + // if the value is an array, it can have no more than 1 dimension - no need to recurse + Object[] valueArray = (Object[]) value; + for (int j = 0, valueArrayLength = valueArray.length; j < valueArrayLength; j++) { + Object nestedValue = valueArray[j]; + if (nestedValue instanceof IBinaryAnnotation) { + generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) nestedValue, new String(pairs[i].getName())); + } + } + } + } +} +private void generateAnnotationInfo(JavaElement parent, HashMap newElements, IBinaryAnnotation annotationInfo, String memberName) { + char[] typeName = org.eclipse.jdt.core.Signature.toCharArray(CharOperation.replaceOnCopy(annotationInfo.getTypeName(), '/', '.')); + Annotation annotation = new Annotation(parent, new String(typeName)); + annotation.memberValueName = memberName; + while (newElements.containsKey(annotation)) { + annotation.occurrenceCount++; + } newElements.put(annotation, annotationInfo); IBinaryElementValuePair[] pairs = annotationInfo.getElementValuePairs(); for (int i = 0, length = pairs.length; i < length; i++) { Object value = pairs[i].getValue(); if (value instanceof IBinaryAnnotation) { - generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) value); + generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) value, new String(pairs[i].getName())); + } else if (value instanceof Object[]) { + // if the value is an array, it can have no more than 1 dimension - no need to recurse + Object[] valueArray = (Object[]) value; + for (int j = 0, valueArrayLength = valueArray.length; j < valueArrayLength; j++) { + Object nestedValue = valueArray[j]; + if (nestedValue instanceof IBinaryAnnotation) { + generateAnnotationInfo(annotation, newElements, (IBinaryAnnotation) nestedValue, new String(pairs[i].getName())); + } + } } } } Index: model/org/eclipse/jdt/internal/core/Annotation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/Annotation.java,v retrieving revision 1.5 diff -u -r1.5 Annotation.java --- model/org/eclipse/jdt/internal/core/Annotation.java 7 Mar 2009 01:08:08 -0000 1.5 +++ model/org/eclipse/jdt/internal/core/Annotation.java 8 Apr 2009 19:51:40 -0000 @@ -26,6 +26,8 @@ public static final IMemberValuePair[] NO_MEMBER_VALUE_PAIRS = new IMemberValuePair[0]; protected String name; + // require to distinguish same annotations in different member value pairs + public String memberValueName; public Annotation(JavaElement parent, String name) { super(parent); @@ -33,7 +35,16 @@ } public boolean equals(Object o) { - if (!(o instanceof Annotation)) return false; + if (!(o instanceof Annotation)) { + return false; + } + Annotation other = (Annotation) o; + if (this.memberValueName == null) { + if (other.memberValueName != null) + return false; + } else if (!this.memberValueName.equals(other.memberValueName)) { + return false; + } return super.equals(o); } @@ -107,6 +118,14 @@ return ((JavaElement)getParent()).getClassFile(); } + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.memberValueName == null) ? 0 : this.memberValueName.hashCode()); + result = prime * result + this.name.hashCode(); + return result; + } + protected void toStringName(StringBuffer buffer) { buffer.append('@'); buffer.append(getElementName()); Index: model/org/eclipse/jdt/internal/core/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v retrieving revision 1.129 diff -u -r1.129 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 7 Mar 2009 00:58:54 -0000 1.129 +++ model/org/eclipse/jdt/internal/core/util/Util.java 8 Apr 2009 19:51:42 -0000 @@ -3065,7 +3065,7 @@ } return typeArguments; } - public static IAnnotation getAnnotation(JavaElement parent, IBinaryAnnotation binaryAnnotation) { + public static Annotation getAnnotation(JavaElement parent, IBinaryAnnotation binaryAnnotation) { char[] typeName = org.eclipse.jdt.core.Signature.toCharArray(CharOperation.replaceOnCopy(binaryAnnotation.getTypeName(), '/', '.')); return new Annotation(parent, new String(typeName)); } @@ -3075,7 +3075,9 @@ return getAnnotationMemberValue(memberValuePair, (Constant) binaryValue); } else if (binaryValue instanceof IBinaryAnnotation) { memberValuePair.valueKind = IMemberValuePair.K_ANNOTATION; - return getAnnotation(parent, (IBinaryAnnotation) binaryValue); + Annotation annotation = getAnnotation(parent, (IBinaryAnnotation) binaryValue); + annotation.memberValueName = memberValuePair.getMemberName(); + return annotation; } else if (binaryValue instanceof ClassSignature) { memberValuePair.valueKind = IMemberValuePair.K_CLASS; char[] className = Signature.toCharArray(CharOperation.replaceOnCopy(((ClassSignature) binaryValue).getTypeName(), '/', '.')); @@ -3098,6 +3100,15 @@ // values are heterogeneous, value kind is thus unknown memberValuePair.valueKind = IMemberValuePair.K_UNKNOWN; } + if (value instanceof Annotation) { + Annotation annotation = (Annotation) value; + annotation.memberValueName = memberValuePair.getMemberName(); + for (int j = 0; j < i; j++) { + if (annotation.equals(values[j])) { + annotation.occurrenceCount++; + } + } + } values[i] = value; } if (memberValuePair.valueKind == -1)