Skip to main content
summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorkmoore2012-07-18 17:51:34 +0000
committerkmoore2012-07-18 17:51:34 +0000
commit332f3582be71f0fe4f66a1f6d154039dd13e9219 (patch)
tree0586f4e7e03a968978ae81449575d6c17dcc79f1 /common
parent31f72e59aafd035dda1fb8698d23c67689b6d8aa (diff)
downloadwebtools.dali-332f3582be71f0fe4f66a1f6d154039dd13e9219.tar.gz
webtools.dali-332f3582be71f0fe4f66a1f6d154039dd13e9219.tar.xz
webtools.dali-332f3582be71f0fe4f66a1f6d154039dd13e9219.zip
Bug 376787 - Performance - JavaResourceAnnotatedElement.getAnnotation(String), added getContainerAnnotation(String)
Diffstat (limited to 'common')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java56
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceAnnotatedElement.java57
3 files changed, 76 insertions, 44 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java
index dfb509060d..7fe55722c0 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java
@@ -79,7 +79,7 @@ abstract class BinaryAnnotatedElement
private void addAnnotation(IAnnotation jdtAnnotation) {
String jdtAnnotationName = jdtAnnotation.getElementName();
// check whether the annotation is a valid container annotation first
- // because container validations are also valid annotations
+ // because container annotations are also valid annotations
// TODO remove container annotations from list of annotations???
if (this.annotationIsValidContainer(jdtAnnotationName)) {
String nestableAnnotationName = this.getAnnotationProvider().getNestableAnnotationName(jdtAnnotationName);
@@ -142,6 +142,11 @@ abstract class BinaryAnnotatedElement
return this.annotations.get(annotationName);
}
+ public Annotation getContainerAnnotation(String containerAnnotationName) {
+ AnnotationContainer container = this.annotationContainers.get(this.getAnnotationProvider().getNestableAnnotationName(containerAnnotationName));
+ return (container == null) ? null : container.getContainerAnnotation();
+ }
+
public Annotation getNonNullAnnotation(String annotationName) {
Annotation annotation = this.getAnnotation(annotationName);
return (annotation != null) ? annotation : this.getNullAnnotation(annotationName);
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 d5d80754fd..4338ce476b 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
@@ -123,8 +123,7 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
for (Map.Entry<String, org.eclipse.jdt.core.dom.Annotation> entry : astAnnotations.entrySet()) {
String annotationName = entry.getKey();
org.eclipse.jdt.core.dom.Annotation astAnnotation = entry.getValue();
- Annotation annotation = this.buildAnnotation(annotationName);
- annotation.initialize((CompilationUnit) astAnnotation.getRoot()); // TODO pass the AST annotation!
+ Annotation annotation = this.buildAnnotation(annotationName, astAnnotation);
this.annotations.put(annotationName, annotation);
}
}
@@ -182,32 +181,19 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
}
public Annotation getAnnotation(String annotationName) {
- // 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();
- }
return this.annotations.get(annotationName);
}
+ public Annotation getContainerAnnotation(String containerAnnotationName) {
+ CombinationAnnotationContainer container = this.annotationContainers.get(this.getAnnotationProvider().getNestableAnnotationName(containerAnnotationName));
+ return (container == null) ? null : container.getContainerAnnotation();
+ }
+
public Annotation getNonNullAnnotation(String annotationName) {
- Annotation annotation = this.performantGetAnnotation(annotationName);
+ Annotation annotation = this.getAnnotation(annotationName);
return (annotation != null) ? annotation : this.getNullAnnotation(annotationName);
}
- /**
- * TODO performance - hack for performance so we don't have to break API in M7.
- * Our calls to getNonNullAnnotation are never used for container annotations, so
- * I can use this method to avoid the expensive {@link #annotationIsValidContainer(String)} check
- * in {@link #getAnnotation(String)}. In the next release I think we need
- * to change the genAnnotation api to not check for container annotations and instead have
- * separate API.
- */
- protected Annotation performantGetAnnotation(String annotationName) {
- return this.annotations.get(annotationName);
- }
-
private Annotation getNullAnnotation(String annotationName) {
Annotation annotation = this.nullAnnotationCache.get(annotationName);
if (annotation == null) {
@@ -230,9 +216,7 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
public void removeAnnotation(String annotationName) {
Annotation annotation = this.annotations.remove(annotationName);
- if (annotation != null) {
- annotation.removeAnnotation();
- }
+ annotation.removeAnnotation();
}
/* CU private */ boolean annotationIsValid(String annotationName) {
@@ -243,6 +227,13 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
return this.getAnnotationProvider().buildAnnotation(this, this.annotatedElement, annotationName);
}
+ /* CU private */ Annotation buildAnnotation(String annotationName, org.eclipse.jdt.core.dom.Annotation astAnnotation) {
+ //TODO pass the astAnnotation to the buildAnnotation() method
+ Annotation annotation = this.getAnnotationProvider().buildAnnotation(this, this.annotatedElement, annotationName);
+ annotation.initialize(astAnnotation);
+ return annotation;
+ }
+
// ********** combination annotations **********
@@ -421,11 +412,10 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
org.eclipse.jdt.core.dom.Annotation astAnnotation = entry.getValue();
Annotation annotation = annotationsToRemove.remove(annotationName);
if (annotation == null) {
- annotation = this.buildAnnotation(annotationName);
- annotation.initialize((CompilationUnit) astAnnotation.getRoot()); // TODO pass the AST annotation!
+ annotation = this.buildAnnotation(annotationName, astAnnotation);
annotationsToAdd.put(annotationName, annotation);
} else {
- annotation.synchronizeWith((CompilationUnit) astAnnotation.getRoot()); // TODO pass the AST annotation!
+ annotation.synchronizeWith(astAnnotation);
}
}
@@ -631,7 +621,7 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
return;
}
// check whether the annotation is a valid container annotation first
- // because container validations are also valid annotations
+ // because container annotations are also valid annotations
// TODO remove container annotations from list of annotations???
if (SourceAnnotatedElement.this.annotationIsValidContainer(astAnnotationName)) {
if (this.astContainerAnnotations.get(astAnnotationName) == null) {
@@ -728,13 +718,17 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
@Override
public void initializeFromContainerAnnotation(org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) {
super.initializeFromContainerAnnotation(astContainerAnnotation);
- this.containerAnnotation = this.buildContainerAnnotation(this.containerAnnotationName);
+ this.containerAnnotation = this.buildContainerAnnotation(this.containerAnnotationName, astContainerAnnotation);
}
private Annotation buildContainerAnnotation(String name) {
return SourceAnnotatedElement.this.buildAnnotation(name);
}
+ private Annotation buildContainerAnnotation(String name, org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) {
+ return SourceAnnotatedElement.this.buildAnnotation(name, astContainerAnnotation);
+ }
+
public Annotation getContainerAnnotation() {
return this.containerAnnotation;
}
@@ -770,7 +764,7 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
void initializeFromStandaloneAnnotation(org.eclipse.jdt.core.dom.Annotation astStandaloneNestableAnnotation) {
NestableAnnotation nestedAnnotation = this.buildNestedAnnotation(0);
this.nestedAnnotations.add(nestedAnnotation);
- nestedAnnotation.initialize((CompilationUnit) astStandaloneNestableAnnotation.getRoot()); // TODO pass the AST annotation!
+ nestedAnnotation.initialize(astStandaloneNestableAnnotation);
}
/**
@@ -783,7 +777,7 @@ abstract class SourceAnnotatedElement<E extends AnnotatedElement>
// container annotation is present but empty
this.syncAddNestedAnnotation(astStandaloneNestableAnnotation);
} else {
- this.nestedAnnotations.get(0).synchronizeWith((CompilationUnit) astStandaloneNestableAnnotation.getRoot()); // TODO pass the AST annotation!
+ this.nestedAnnotations.get(0).synchronizeWith(astStandaloneNestableAnnotation);
// remove any remaining nested annotations
this.syncRemoveNestedAnnotations(1);
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceAnnotatedElement.java
index 5176d120ef..39d8cdb4b9 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceAnnotatedElement.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceAnnotatedElement.java
@@ -23,9 +23,6 @@ import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
* stability. It is available at this early stage to solicit feedback from
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
- *
- * @version 3.0
- * @since 3.0
*/
public interface JavaResourceAnnotatedElement
extends JavaResourceNode
@@ -43,25 +40,51 @@ public interface JavaResourceAnnotatedElement
String NESTABLE_ANNOTATIONS_COLLECTION = "nestableAnnotations"; //$NON-NLS-1$
/**
- * Return the member's annotations in the order that they appear.
+ * Return the member's top-level stand-alone annotations in the order that they appear.
+ * <br>
* Do not return duplicate annotations as this error is handled by the Java
* compiler.
+ * <br>
+ * This is only used to return top-level annotations that are not container
+ * or nestable annotations.
+ * @see {@link #getContainerAnnotation(String)}
+ * @see {@link #getAnnotations(String)}
*/
Iterable<Annotation> getAnnotations();
/**
- * Return the number of annotations.
+ * Return the number of top-level stand-alone annotations.
+ * This does not include the number of container or nestable annotations
+ *
+ * @see #getAnnotationsSize(String)
*/
int getAnnotationsSize();
/**
* Return the annotation with the specified name.
* Return the first if there are duplicates in the source code.
+ * <br>
+ * This is only used to return a top-level standalone annotation.
+ * It will not return container or nestable annotations
+ *
+ * @see #getContainerAnnotation(String)
+ * @see #getAnnotation(int, String)
*/
Annotation getAnnotation(String annotationName);
-
+
/**
- * Return the specified annotation.
+ * Return the "container" annotation with the specified name.
+ * Return the first if there are duplicates in the source code.
+ * <br>
+ * This is only used to return a top-level container annotations.
+ *
+ * @see #getAnnotation(String)
+ * @see #getAnnotation(int, String)
+ */
+ Annotation getContainerAnnotation(String containerAnnotationName);
+
+ /**
+ * Return the specified top-level stand-alone annotation.
* Return the first if there are duplicates in the source code.
* Do not return null, but a Null Object instead if no annotation
* with the specified name exists in the source code.
@@ -73,9 +96,10 @@ public interface JavaResourceAnnotatedElement
* they appear.
* If nestable and container annotations are both specified on the
* member directly, the behavior is undefined
+ *
+ * @see #getAnnotations()
+ * @see #getContainerAnnotation(String)
*/
- // TODO tie the singular and plural annotations together so we can generate
- // a validation error when both are specified
ListIterable<NestableAnnotation> getAnnotations(String nestableAnnotationName);
/**
@@ -93,8 +117,11 @@ public interface JavaResourceAnnotatedElement
NestableAnnotation getAnnotation(int index, String nestableAnnotationName);
/**
- * Add an annotation with the specified name.
- * Return the newly-created annotation.
+ * Add a top-level stand-alone annotation with the specified name
+ * and return the newly-created annotation.
+ * <br>
+ * Do not use this to add nestable annotations or container annotations
+ * @see #addAnnotation(int, String)
*/
Annotation addAnnotation(String annotationName);
@@ -118,7 +145,11 @@ public interface JavaResourceAnnotatedElement
void moveAnnotation(int targetIndex, int sourceIndex, String nestableAnnotationName);
/**
- * Remove the specified annotation.
+ * Remove the specified top-level standalone annotation.
+ * <br>
+ * Do not use this to remove container or nestable annotations
+ *
+ * @see #removeAnnotation(int, String)
*/
void removeAnnotation(String annotationName);
@@ -167,7 +198,9 @@ public interface JavaResourceAnnotatedElement
* Return the text range for the nestable annotation if it is currently
* unnested. If it is nested, return the text range for the corresponding
* container annotation.
+ * This is not used for stand-alone annotations
*
+ * @see Annotation#getTextRange(CompilationUnit)
* @see AnnotationProvider#getContainerAnnotationName(String)
*/
TextRange getTextRange(String nestableAnnotationName, CompilationUnit astRoot);

Back to the top