Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-12-16 17:19:24 +0000
committerpfullbright2011-12-16 17:19:24 +0000
commitde09a38142eac48aacc317cbe714bc3cbf1baed9 (patch)
tree9234f81f23e5cf88f3e14874f0c07857a459247a /common/plugins
parent4e9a02ef4b25c00f4913cf01d9aee349ef3d13d3 (diff)
downloadwebtools.dali-de09a38142eac48aacc317cbe714bc3cbf1baed9.tar.gz
webtools.dali-de09a38142eac48aacc317cbe714bc3cbf1baed9.tar.xz
webtools.dali-de09a38142eac48aacc317cbe714bc3cbf1baed9.zip
added getAllAnnotations() to JavaResourceAnnotatedElement
Diffstat (limited to 'common/plugins')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java117
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java19
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceAnnotatedElement.java7
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/NestableAnnotation.java5
4 files changed, 107 insertions, 41 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 293156f479..59335c8450 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
@@ -77,12 +77,14 @@ abstract class BinaryAnnotatedElement
this.annotations.add(this.getAnnotationProvider().buildAnnotation(this, jdtAnnotation));
}
if (this.annotationIsValidNestable(jdtAnnotationName)) {
- AnnotationContainer container = new AnnotationContainer(jdtAnnotation);
+ AnnotationContainer container = new AnnotationContainer();
+ container.initializeFromNestableAnnotation(jdtAnnotation);
this.annotationContainers.put(jdtAnnotationName, container);
}
if (this.annotationIsValidContainer(jdtAnnotationName)) {
String nestableAnnotationName = this.getNestableAnnotationName(jdtAnnotationName);
- AnnotationContainer container = new AnnotationContainer(jdtAnnotation);
+ AnnotationContainer container = new AnnotationContainer();
+ container.initializeFromContainerAnnotation(jdtAnnotation);
this.annotationContainers.put(nestableAnnotationName, container);
}
}
@@ -129,8 +131,8 @@ abstract class BinaryAnnotatedElement
private void updateAnnotations() {
throw new UnsupportedOperationException();
}
-
-
+
+
// ********** annotations **********
public Iterable<Annotation> getAnnotations() {
@@ -194,10 +196,25 @@ abstract class BinaryAnnotatedElement
return container == null ? null : container.nestedAnnotationAt(index);
}
- // ********** simple state **********
+ // ***** queries *****
+
+ public Iterable<Annotation> getAllAnnotations() {
+ return new CompositeIterable<Annotation>(
+ getAnnotations(),
+ getContainerOrNestableAnnotations());
+ }
+
+ protected Iterable<Annotation> getContainerOrNestableAnnotations() {
+ return new TransformationIterable<AnnotationContainer, Annotation>(this.annotationContainers.values()) {
+ @Override
+ protected Annotation transform(AnnotationContainer o) {
+ return (o.getContainerAnnotation() != null) ? o.getContainerAnnotation() : CollectionTools.get(o.getNestedAnnotations(), 0);
+ }
+ };
+ }
public boolean isAnnotated() {
- return ! this.annotations.isEmpty();
+ return ! (this.annotations.isEmpty() && this.annotationContainers.isEmpty());
}
public boolean isAnnotatedWith(Iterable<String> annotationNames) {
@@ -287,46 +304,74 @@ abstract class BinaryAnnotatedElement
}
private static final IMemberValuePair[] EMPTY_MEMBER_VALUE_PAIR_ARRAY = new IMemberValuePair[0];
-
- class AnnotationContainer
- {
- private final IAnnotation containerAnnotation;
-
- /** annotations */
- final Vector<NestableAnnotation> nestedAnnotations = new Vector<NestableAnnotation>();
-
- protected AnnotationContainer(IAnnotation containerAnnotation) {
+
+
+ class AnnotationContainer {
+
+ private Annotation containerAnnotation;
+
+ private final Vector<NestableAnnotation> nestedAnnotations = new Vector<NestableAnnotation>();
+
+ protected AnnotationContainer() {
super();
- this.containerAnnotation = containerAnnotation;
}
-
- protected void initializeNestedAnnotations() {
+
+
+ // ***** init from container *****
+
+ protected void initializeFromContainerAnnotation(IAnnotation jdtContainerAnnotation) {
+ this.containerAnnotation =
+ BinaryAnnotatedElement.this.getAnnotationProvider().buildAnnotation(
+ BinaryAnnotatedElement.this, jdtContainerAnnotation);
+ initializeNestedAnnotations(jdtContainerAnnotation);
+ }
+
+ protected void initializeNestedAnnotations(IAnnotation jdtContainerAnnotation) {
int index = 0;
- for(IMemberValuePair valuePair : this.getJdtMemberValuePairs()) {
- IAnnotation nestedAnnotation = (IAnnotation) valuePair.getValue();
- this.nestedAnnotations.add(getAnnotationProvider().buildAnnotation(BinaryAnnotatedElement.this, nestedAnnotation, index++));
+ for (IMemberValuePair valuePair : this.getJdtMemberValuePairs(jdtContainerAnnotation)) {
+ IAnnotation jdtNestedAnnotation = (IAnnotation) valuePair.getValue();
+ this.nestedAnnotations.add(
+ BinaryAnnotatedElement.this.getAnnotationProvider().buildAnnotation(
+ BinaryAnnotatedElement.this, jdtNestedAnnotation, index++));
}
}
-
- public ListIterable<NestableAnnotation> getNestedAnnotations() {
+
+ private IMemberValuePair[] getJdtMemberValuePairs(IAnnotation jdtContainerAnnotation) {
+ try {
+ return jdtContainerAnnotation.getMemberValuePairs();
+ }
+ catch (JavaModelException ex) {
+ JptCommonCorePlugin.log(ex);
+ return EMPTY_MEMBER_VALUE_PAIR_ARRAY;
+ }
+ }
+
+
+ // ***** init from nestable *****
+
+ protected void initializeFromNestableAnnotation(IAnnotation jdtNestableAnnotation) {
+ this.nestedAnnotations.add(
+ BinaryAnnotatedElement.this.getAnnotationProvider().buildAnnotation(
+ BinaryAnnotatedElement.this, jdtNestableAnnotation, 0));
+ }
+
+
+ // ***** queries *****
+
+ protected Annotation getContainerAnnotation() {
+ return this.containerAnnotation;
+ }
+
+ protected ListIterable<NestableAnnotation> getNestedAnnotations() {
return new LiveCloneListIterable<NestableAnnotation>(this.nestedAnnotations);
}
-
- public int getNestedAnnotationsSize() {
+
+ protected int getNestedAnnotationsSize() {
return this.nestedAnnotations.size();
}
-
- public NestableAnnotation nestedAnnotationAt(int index) {
+
+ protected NestableAnnotation nestedAnnotationAt(int index) {
return this.nestedAnnotations.get(index);
}
-
- private IMemberValuePair[] getJdtMemberValuePairs() {
- try {
- return this.containerAnnotation.getMemberValuePairs();
- } catch (JavaModelException ex) {
- JptCommonCorePlugin.log(ex);
- return EMPTY_MEMBER_VALUE_PAIR_ARRAY;
- }
- }
}
}
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 3de22234cb..ec38a9ee2e 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
@@ -344,9 +344,24 @@ abstract class SourceAnnotatedElement<A extends AnnotatedElement>
// ********** miscellaneous **********
-
+
+ public Iterable<Annotation> getAllAnnotations() {
+ return new CompositeIterable<Annotation>(
+ getAnnotations(),
+ getContainerOrNestableAnnotations());
+ }
+
+ protected Iterable<Annotation> getContainerOrNestableAnnotations() {
+ return new TransformationIterable<AnnotationContainer, Annotation>(this.annotationContainers.values()) {
+ @Override
+ protected Annotation transform(AnnotationContainer o) {
+ return (o.getContainerAnnotation() != null) ? o.getContainerAnnotation() : CollectionTools.get(o.getNestedAnnotations(), 0);
+ }
+ };
+ }
+
public boolean isAnnotated() {
- return ! this.annotations.isEmpty() || ! this.annotationContainers.isEmpty();
+ return ! (this.annotations.isEmpty() && this.annotationContainers.isEmpty());
}
public boolean isAnnotatedWith(Iterable<String> annotationNames) {
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 e7ec964a50..dbc44f7499 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
@@ -133,6 +133,13 @@ public interface JavaResourceAnnotatedElement
// ********** queries **********
/**
+ * Return all top level annotations.
+ * If there is a container annotation, return that and not any nestables within it.
+ * If there is a nestable alone, return that and not the container.
+ */
+ Iterable<Annotation> getAllAnnotations();
+
+ /**
* Return whether the underlying JDT member is currently annotated with any recognized
* annotations.
*/
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/NestableAnnotation.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/NestableAnnotation.java
index b598cbfa85..68d364bcdd 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/NestableAnnotation.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/NestableAnnotation.java
@@ -23,12 +23,11 @@ package org.eclipse.jpt.common.core.resource.java;
* @since 2.0
*/
public interface NestableAnnotation
- extends Annotation
-{
+ extends Annotation {
+
/**
* Move the annotation to the specified index within its container annotation.
* This should only be called when the annotation is actually nested.
*/
void moveAnnotation(int index);
-
}

Back to the top