| Summary: | APT creates unnecessary element instances for each annotation on it | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Jay Arthanareeswaran <jarthana> |
| Component: | APT | Assignee: | Jay Arthanareeswaran <jarthana> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | eclipse, srikanth_sankaran |
| Version: | 4.3 | ||
| Target Milestone: | BETA J8 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
I'm not sure I understand what you're proposing? Is your intention to reuse the same Element for multiple bindings, or ... ? (In reply to comment #1) > I'm not sure I understand what you're proposing? Is your intention to reuse > the same Element for multiple bindings, or ... ? No, I was saying we can do with just one Element for a binding (not annotation binding). To be specific, this line: Element element = _factory.newElement(currentBinding); creates one element instance for the same binding multiple times depending on number of annotations. In the example I mentioned in comment #0, we will end up create two TypeElement for 'TypeAnnotationTest' because the type declaration has two annotations. Oh, I see. Yes, that *should* be safe - after all, those elements would have all had the same _referenceBinding internally anyway, so having them be distinct objects doesn't seem to be serving any purpose. I have to say that in real-world code it seems moderately rare for an element to have more than one annotation (though certainly not unheard of) so I am not sure how much this actually costs us. (In reply to comment #3) > I have to say that in real-world code it seems moderately rare for an > element to have more than one annotation (though certainly not unheard of) > so I am not sure how much this actually costs us. Not much I guess. Since I will be touching this part of the code soon, I just thought will fix this along the way. Subsumed by bug 413613 |
Consider this code fed to the APT: @TypeUseAnnotation("class") @Deprecated public class TypeAnnotationTest extends @TypeUseAnnotation("super") Object {} And the following code in AnnotationDiscoveryVisitor: private void resolveAnnotations( BlockScope scope, Annotation[] annotations, Binding currentBinding) { ASTNode.resolveAnnotations(scope, annotations, currentBinding); for (Annotation annotation : annotations) { AnnotationBinding binding = annotation.getCompilerAnnotation(); if (binding != null) { TypeElement anno = (TypeElement)_factory.newElement(binding.getAnnotationType()); Element element = _factory.newElement(currentBinding); _annoToElement.put(anno, element); } } } Looks like the new element instance created for the currentBinding is just not necessary.