Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2012-04-13 18:16:48 +0000
committerkmoore2012-04-13 18:16:48 +0000
commitfb1a5fc62cfe9d44e110561bbc4673e0fc96653a (patch)
treeb791b3133bdfbc58526d51a054ad7f500bbaa550 /common/plugins
parentb7298b42a3bf04841b204cfa9309f8a41a1820c0 (diff)
downloadwebtools.dali-fb1a5fc62cfe9d44e110561bbc4673e0fc96653a.tar.gz
webtools.dali-fb1a5fc62cfe9d44e110561bbc4673e0fc96653a.tar.xz
webtools.dali-fb1a5fc62cfe9d44e110561bbc4673e0fc96653a.zip
added a null annotation cache for performance
Diffstat (limited to 'common/plugins')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java
index 1c6276717d..a1cc374007 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java
@@ -58,6 +58,13 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
private final Hashtable<String, Annotation> annotations = new Hashtable<String, Annotation>();
/**
+ * Cache the null annotation objects or they will be rebuilt on every access.
+ * Make this a HashMap for performance, not concerned with duplicate creation and
+ * unlikely that multiple threads will access this.
+ */
+ private final HashMap<String, Annotation> nullAnnotationCache = new HashMap<String, Annotation>();
+
+ /**
* Annotation containers keyed by <em>nestable</em> annotation name.
* This is used to store annotations that can be both standalone and nested
* and are moved back and forth between the two.
@@ -138,7 +145,8 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
}
public Annotation getAnnotation(String annotationName) {
- // TODO figure out why we need to search the containers...
+ // TODO one reason we search the containers is validation, we need to have separate API for getting the container annotation.
+ //The validation in org.eclipse.jpt.jaxb.core.internal.context.java.GenericJavaXmlAnyElementMapping is an example
if (this.annotationIsValidContainer(annotationName)) {
CombinationAnnotationContainer container = this.annotationContainers.get(this.getAnnotationProvider().getNestableAnnotationName(annotationName));
return (container == null) ? null : container.getContainerAnnotation();
@@ -148,7 +156,16 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
public Annotation getNonNullAnnotation(String annotationName) {
Annotation annotation = this.getAnnotation(annotationName);
- return (annotation != null) ? annotation : this.buildNullAnnotation(annotationName);
+ return (annotation != null) ? annotation : this.getNullAnnotation(annotationName);
+ }
+
+ private Annotation getNullAnnotation(String annotationName) {
+ Annotation annotation = this.nullAnnotationCache.get(annotationName);
+ if (annotation == null) {
+ annotation = this.buildNullAnnotation(annotationName);
+ this.nullAnnotationCache.put(annotationName, annotation);
+ }
+ return annotation;
}
private Annotation buildNullAnnotation(String annotationName) {

Back to the top