summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikaelpeltier <mikaelpeltier@google.com>2015-04-02 16:29:40 +0200
committermikaelpeltier <mikaelpeltier@google.com>2015-04-16 11:11:21 +0200
commit837f8201d6b97bdcbe9214d6653a98ad2db74d26 (patch)
tree319b045c605960bbb9ebe61439ed59b24b4cd0a9
parenta2d1074695015c0d0f0e541dbfb4ce1cf2f14dc5 (diff)
downloadtoolchain_jack-837f8201d6b97bdcbe9214d6653a98ad2db74d26.zip
toolchain_jack-837f8201d6b97bdcbe9214d6653a98ad2db74d26.tar.gz
toolchain_jack-837f8201d6b97bdcbe9214d6653a98ad2db74d26.tar.bz2
Remove AnnotationSet
Change-Id: I64be5d5e70e07c448d1ec567063a7344b12ce14f
-rw-r--r--jack/src/com/android/jack/ir/ast/AnnotationSet.java132
-rw-r--r--jack/src/com/android/jack/ir/ast/JDefinedClass.java6
-rw-r--r--jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java16
-rw-r--r--jack/src/com/android/jack/ir/ast/JDefinedInterface.java6
-rw-r--r--jack/src/com/android/jack/ir/ast/JField.java24
-rw-r--r--jack/src/com/android/jack/ir/ast/JLocal.java7
-rw-r--r--jack/src/com/android/jack/ir/ast/JMethod.java22
-rw-r--r--jack/src/com/android/jack/ir/ast/JParameter.java6
-rw-r--r--jack/src/com/android/jack/ir/ast/JThis.java4
-rw-r--r--jack/src/com/android/jack/ir/ast/JVariable.java18
-rw-r--r--jack/src/com/android/jack/util/AnnotationUtils.java60
11 files changed, 130 insertions, 171 deletions
diff --git a/jack/src/com/android/jack/ir/ast/AnnotationSet.java b/jack/src/com/android/jack/ir/ast/AnnotationSet.java
deleted file mode 100644
index 3a3bd60..0000000
--- a/jack/src/com/android/jack/ir/ast/AnnotationSet.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.jack.ir.ast;
-
-import com.android.jack.Jack;
-import com.android.jack.ir.ast.JNode.Transformation;
-import com.android.sched.item.Component;
-import com.android.sched.scheduler.ScheduleInstance;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
-
-class AnnotationSet {
-
- @Nonnull
- private final Map<JAnnotationType, ArrayList<JAnnotation>> annotations =
- new HashMap<JAnnotationType, ArrayList<JAnnotation>>();
-
- AnnotationSet() {
- }
-
- void addAnnotation(@Nonnull JAnnotation annotation) throws UnsupportedOperationException {
- JAnnotationType type = annotation.getType();
- ArrayList<JAnnotation> annotationLiterals = annotations.get(type);
- if (annotationLiterals == null) {
- annotationLiterals = new ArrayList<JAnnotation>(1);
- annotations.put(type, annotationLiterals);
- }
- annotationLiterals.add(annotation);
- }
-
- /**
- * @return {@link List} of {@link JAnnotation} contained into this
- * {@link AnnotationSet} and having the type {@code annotationType}.
- */
- @Nonnull
- List<JAnnotation> getAnnotation(@Nonnull JAnnotationType annotationType) {
- List<JAnnotation> annotationLiterals = annotations.get(annotationType);
- if (annotationLiterals == null) {
- return Collections.emptyList();
- }
- return annotationLiterals;
- }
-
- /**
- * @return {@link Collection} of {@link JAnnotation} contained into this
- * {@link AnnotationSet}.
- */
- @Nonnull
- Collection<JAnnotation> getAnnotations() {
- Collection<JAnnotation> allAnnotations = new ArrayList<JAnnotation>();
- for (Collection<JAnnotation> annotationLiterals : annotations.values()) {
- allAnnotations.addAll(annotationLiterals);
- }
- return Jack.getUnmodifiableCollections().getUnmodifiableCollection(allAnnotations);
- }
-
- /**
- * @return {@link Collection} of {@link JAnnotationType} contained into this
- * {@link AnnotationSet}.
- */
- @Nonnull
- Collection<JAnnotationType> getAnnotationTypes() {
- return Jack.getUnmodifiableCollections().getUnmodifiableCollection(annotations.keySet());
- }
-
- /**
- * @return true if the transformation was applied. False if the transformation could not be
- * applied because {@code existingNode} was not present in this {@link AnnotationSet}.
- */
- boolean transform(@Nonnull JNode existingNode, @CheckForNull JNode newNode,
- @Nonnull Transformation transformation) throws UnsupportedOperationException {
- if (existingNode instanceof JAnnotation) {
- JAnnotation existingAnnotation = (JAnnotation) existingNode;
- List<JAnnotation> annotationLiterals = getAnnotation(existingAnnotation.getType());
- switch (transformation) {
- case INSERT_AFTER:
- case INSERT_BEFORE:
- throw new UnsupportedOperationException();
- case REPLACE:
- assert newNode instanceof JAnnotation;
- annotationLiterals.remove(existingAnnotation);
- annotationLiterals.add((JAnnotation) newNode);
- return true;
- case REMOVE:
- assert newNode == null;
- annotationLiterals.remove(existingAnnotation);
- if (annotationLiterals.isEmpty()) {
- annotations.remove(existingAnnotation.getType());
- }
- return true;
- }
- }
-
- return false;
- }
-
- void traverse(@Nonnull JVisitor visitor) {
- for (ArrayList<JAnnotation> annotation : annotations.values()) {
- visitor.accept(annotation);
- }
- }
-
- void traverse(@Nonnull ScheduleInstance<? super Component> schedule) throws Exception {
- for (List<JAnnotation> annotationLiterals : annotations.values()) {
- for (JAnnotation annotation : annotationLiterals) {
- annotation.traverse(schedule);
- }
- }
- }
-}
diff --git a/jack/src/com/android/jack/ir/ast/JDefinedClass.java b/jack/src/com/android/jack/ir/ast/JDefinedClass.java
index f182d25..be3889a 100644
--- a/jack/src/com/android/jack/ir/ast/JDefinedClass.java
+++ b/jack/src/com/android/jack/ir/ast/JDefinedClass.java
@@ -76,7 +76,7 @@ public class JDefinedClass extends JDefinedClassOrInterface implements CanBeSetF
}
visitor.accept(fields);
visitor.accept(methods);
- annotations.traverse(visitor);
+ visitor.accept(annotations);
}
visitor.endVisit(this);
}
@@ -90,7 +90,9 @@ public class JDefinedClass extends JDefinedClassOrInterface implements CanBeSetF
for (JMethod method : methods) {
method.traverse(schedule);
}
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
diff --git a/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java b/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java
index d61b4e3..60d91ce 100644
--- a/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java
+++ b/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java
@@ -24,6 +24,7 @@ import com.android.jack.load.NopClassOrInterfaceLoader;
import com.android.jack.lookup.JMethodIdLookupException;
import com.android.jack.lookup.JMethodLookupException;
import com.android.jack.lookup.JMethodWithReturnLookupException;
+import com.android.jack.util.AnnotationUtils;
import com.android.jack.util.NamingTools;
import com.android.sched.item.Description;
import com.android.sched.marker.Marker;
@@ -73,7 +74,8 @@ public abstract class JDefinedClassOrInterface extends JDefinedReferenceType
*/
private int modifier;
- protected final AnnotationSet annotations = new AnnotationSet();
+ @Nonnull
+ protected final List<JAnnotation> annotations = new ArrayList<JAnnotation>();
@Nonnull
private JPackage enclosingPackage;
@@ -352,28 +354,30 @@ public abstract class JDefinedClassOrInterface extends JDefinedReferenceType
@Override
public void addAnnotation(@Nonnull JAnnotation annotation) {
- annotations.addAnnotation(annotation);
+ annotations.add(annotation);
}
@Override
@Nonnull
public List<JAnnotation> getAnnotations(@Nonnull JAnnotationType annotationType) {
loader.ensureAnnotation(this, annotationType);
- return annotations.getAnnotation(annotationType);
+ return Jack.getUnmodifiableCollections().getUnmodifiableList(
+ AnnotationUtils.getAnnotation(annotations, annotationType));
}
@Override
@Nonnull
public Collection<JAnnotation> getAnnotations() {
loader.ensureAnnotations(this);
- return annotations.getAnnotations();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(annotations);
}
@Override
@Nonnull
public Collection<JAnnotationType> getAnnotationTypes() {
loader.ensureAnnotations(this);
- return annotations.getAnnotationTypes();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(
+ AnnotationUtils.getAnnotationTypes(annotations));
}
@Nonnull
@@ -397,7 +401,7 @@ public abstract class JDefinedClassOrInterface extends JDefinedReferenceType
protected void transform(@Nonnull JNode existingNode, @CheckForNull JNode newNode,
@Nonnull Transformation transformation) throws UnsupportedOperationException {
if (!transform(inners, existingNode, (JClassOrInterface) newNode, transformation)) {
- if (!annotations.transform(existingNode, newNode, transformation)) {
+ if (!transform(annotations, existingNode, (JAnnotation) newNode, transformation)) {
super.transform(existingNode, newNode, transformation);
}
}
diff --git a/jack/src/com/android/jack/ir/ast/JDefinedInterface.java b/jack/src/com/android/jack/ir/ast/JDefinedInterface.java
index fc17e24..eb16f28 100644
--- a/jack/src/com/android/jack/ir/ast/JDefinedInterface.java
+++ b/jack/src/com/android/jack/ir/ast/JDefinedInterface.java
@@ -48,7 +48,7 @@ public class JDefinedInterface extends JDefinedClassOrInterface implements JInte
}
visitor.accept(fields);
visitor.accept(methods);
- annotations.traverse(visitor);
+ visitor.accept(annotations);
}
visitor.endVisit(this);
}
@@ -62,7 +62,9 @@ public class JDefinedInterface extends JDefinedClassOrInterface implements JInte
for (JMethod method : methods) {
method.traverse(schedule);
}
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
diff --git a/jack/src/com/android/jack/ir/ast/JField.java b/jack/src/com/android/jack/ir/ast/JField.java
index 8422bb9..f72bbc0 100644
--- a/jack/src/com/android/jack/ir/ast/JField.java
+++ b/jack/src/com/android/jack/ir/ast/JField.java
@@ -15,13 +15,16 @@
*/
package com.android.jack.ir.ast;
+import com.android.jack.Jack;
import com.android.jack.ir.JNodeInternalError;
import com.android.jack.ir.sourceinfo.SourceInfo;
+import com.android.jack.util.AnnotationUtils;
import com.android.sched.item.Component;
import com.android.sched.item.Description;
import com.android.sched.scheduler.ScheduleInstance;
import com.android.sched.transform.TransformRequest;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -40,7 +43,7 @@ public class JField extends JNode implements HasName, HasType, JVisitable, CanBe
@Nonnull
private final JFieldId fieldId;
@Nonnull
- protected final AnnotationSet annotations = new AnnotationSet();
+ protected final List<JAnnotation> annotations = new ArrayList<JAnnotation>();
protected int modifier;
@@ -153,8 +156,7 @@ public class JField extends JNode implements HasName, HasType, JVisitable, CanBe
@Override
public void traverse(@Nonnull JVisitor visitor) {
if (visitor.visit(this)) {
- // Do not visit declStmt, it gets visited within its own code block.
- annotations.traverse(visitor);
+ visitor.accept(annotations);
}
visitor.endVisit(this);
}
@@ -162,7 +164,9 @@ public class JField extends JNode implements HasName, HasType, JVisitable, CanBe
@Override
public void traverse(@Nonnull ScheduleInstance<? super Component> schedule) throws Exception {
schedule.process(this);
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
@@ -237,31 +241,33 @@ public class JField extends JNode implements HasName, HasType, JVisitable, CanBe
@Override
public void addAnnotation(@Nonnull JAnnotation annotation) {
- annotations.addAnnotation(annotation);
+ annotations.add(annotation);
}
@Override
@Nonnull
public List<JAnnotation> getAnnotations(@Nonnull JAnnotationType annotationType) {
- return annotations.getAnnotation(annotationType);
+ return Jack.getUnmodifiableCollections().getUnmodifiableList(
+ AnnotationUtils.getAnnotation(annotations, annotationType));
}
@Override
@Nonnull
public Collection<JAnnotation> getAnnotations() {
- return annotations.getAnnotations();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(annotations);
}
@Override
@Nonnull
public Collection<JAnnotationType> getAnnotationTypes() {
- return annotations.getAnnotationTypes();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(
+ AnnotationUtils.getAnnotationTypes(annotations));
}
@Override
protected void transform(@Nonnull JNode existingNode, @CheckForNull JNode newNode,
@Nonnull Transformation transformation) throws UnsupportedOperationException {
- if (!annotations.transform(existingNode, newNode, transformation)) {
+ if (!transform(annotations, existingNode, (JAnnotation) newNode, transformation)) {
super.transform(existingNode, newNode, transformation);
}
}
diff --git a/jack/src/com/android/jack/ir/ast/JLocal.java b/jack/src/com/android/jack/ir/ast/JLocal.java
index 1973123..a8ebe33 100644
--- a/jack/src/com/android/jack/ir/ast/JLocal.java
+++ b/jack/src/com/android/jack/ir/ast/JLocal.java
@@ -60,8 +60,7 @@ public class JLocal extends JVariable implements HasEnclosingMethod {
@Override
public void traverse(@Nonnull JVisitor visitor) {
if (visitor.visit(this)) {
- // Do not visit declStmt, it gets visited within its own code block.
- annotations.traverse(visitor);
+ visitor.accept(annotations);
}
visitor.endVisit(this);
}
@@ -69,7 +68,9 @@ public class JLocal extends JVariable implements HasEnclosingMethod {
@Override
public void traverse(@Nonnull ScheduleInstance<? super Component> schedule) throws Exception {
schedule.process(this);
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
diff --git a/jack/src/com/android/jack/ir/ast/JMethod.java b/jack/src/com/android/jack/ir/ast/JMethod.java
index 3578afe..803e45e 100644
--- a/jack/src/com/android/jack/ir/ast/JMethod.java
+++ b/jack/src/com/android/jack/ir/ast/JMethod.java
@@ -16,9 +16,11 @@
package com.android.jack.ir.ast;
+import com.android.jack.Jack;
import com.android.jack.ir.JNodeInternalError;
import com.android.jack.ir.sourceinfo.SourceInfo;
import com.android.jack.load.MethodLoader;
+import com.android.jack.util.AnnotationUtils;
import com.android.jack.util.NamingTools;
import com.android.sched.item.Component;
import com.android.sched.item.Description;
@@ -55,7 +57,7 @@ public class JMethod extends JNode implements HasEnclosingType, HasName, HasType
private final JType returnType;
@Nonnull
- private final AnnotationSet annotations = new AnnotationSet();
+ private final List<JAnnotation> annotations = new ArrayList<JAnnotation>();
@Nonnull
private JMethodId methodId;
@@ -257,27 +259,29 @@ public class JMethod extends JNode implements HasEnclosingType, HasName, HasType
@Override
public void addAnnotation(@Nonnull JAnnotation annotation) {
- annotations.addAnnotation(annotation);
+ annotations.add(annotation);
}
@Override
@Nonnull
public List<JAnnotation> getAnnotations(@Nonnull JAnnotationType annotationType) {
loader.ensureAnnotation(this, annotationType);
- return annotations.getAnnotation(annotationType);
+ return Jack.getUnmodifiableCollections().getUnmodifiableList(
+ AnnotationUtils.getAnnotation(annotations, annotationType));
}
@Override
@Nonnull
public Collection<JAnnotation> getAnnotations() {
loader.ensureAnnotations(this);
- return annotations.getAnnotations();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(annotations);
}
@Override
@Nonnull
public Collection<JAnnotationType> getAnnotationTypes() {
- return annotations.getAnnotationTypes();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(
+ AnnotationUtils.getAnnotationTypes(annotations));
}
@Override
@@ -318,7 +322,7 @@ public class JMethod extends JNode implements HasEnclosingType, HasName, HasType
if (body != null) {
visitor.accept(body);
}
- annotations.traverse(visitor);
+ visitor.accept(annotations);
}
protected void visitChildren(@Nonnull ScheduleInstance<? super Component> schedule)
@@ -332,14 +336,16 @@ public class JMethod extends JNode implements HasEnclosingType, HasName, HasType
if (body != null) {
body.traverse(schedule);
}
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
protected void transform(@Nonnull JNode existingNode, @CheckForNull JNode newNode,
@Nonnull Transformation transformation) throws UnsupportedOperationException {
if (!transform(params, existingNode, (JParameter) newNode, transformation)) {
- if (!annotations.transform(existingNode, newNode, transformation)) {
+ if (!transform(annotations, existingNode, (JAnnotation) newNode, transformation)) {
super.transform(existingNode, newNode, transformation);
}
}
diff --git a/jack/src/com/android/jack/ir/ast/JParameter.java b/jack/src/com/android/jack/ir/ast/JParameter.java
index cb7646f..c03300a 100644
--- a/jack/src/com/android/jack/ir/ast/JParameter.java
+++ b/jack/src/com/android/jack/ir/ast/JParameter.java
@@ -47,7 +47,7 @@ public class JParameter extends JVariable implements HasEnclosingMethod {
@Override
public void traverse(@Nonnull JVisitor visitor) {
if (visitor.visit(this)) {
- annotations.traverse(visitor);
+ visitor.accept(annotations);
}
visitor.endVisit(this);
}
@@ -55,7 +55,9 @@ public class JParameter extends JVariable implements HasEnclosingMethod {
@Override
public void traverse(@Nonnull ScheduleInstance<? super Component> schedule) throws Exception {
schedule.process(this);
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
diff --git a/jack/src/com/android/jack/ir/ast/JThis.java b/jack/src/com/android/jack/ir/ast/JThis.java
index 4acbe49..3d25ab9 100644
--- a/jack/src/com/android/jack/ir/ast/JThis.java
+++ b/jack/src/com/android/jack/ir/ast/JThis.java
@@ -55,7 +55,9 @@ public class JThis extends JVariable implements HasEnclosingMethod {
@Override
public void traverse(@Nonnull ScheduleInstance<? super Component> schedule) throws Exception {
schedule.process(this);
- annotations.traverse(schedule);
+ for (JAnnotation annotation : annotations) {
+ annotation.traverse(schedule);
+ }
}
@Override
diff --git a/jack/src/com/android/jack/ir/ast/JVariable.java b/jack/src/com/android/jack/ir/ast/JVariable.java
index 06228b3..a6b6e2d 100644
--- a/jack/src/com/android/jack/ir/ast/JVariable.java
+++ b/jack/src/com/android/jack/ir/ast/JVariable.java
@@ -16,11 +16,14 @@
package com.android.jack.ir.ast;
+import com.android.jack.Jack;
import com.android.jack.ir.StringInterner;
import com.android.jack.ir.ast.JPrimitiveType.JPrimitiveTypeEnum;
import com.android.jack.ir.sourceinfo.SourceInfo;
+import com.android.jack.util.AnnotationUtils;
import com.android.sched.item.Description;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -38,7 +41,8 @@ public abstract class JVariable extends JNode implements HasName, CanBeSetFinal,
private String name;
@Nonnull
private final JType type;
- protected final AnnotationSet annotations = new AnnotationSet();
+ @Nonnull
+ protected final List<JAnnotation> annotations = new ArrayList<JAnnotation>();
protected int modifier;
@@ -98,31 +102,33 @@ public abstract class JVariable extends JNode implements HasName, CanBeSetFinal,
@Override
public void addAnnotation(@Nonnull JAnnotation annotation) {
- annotations.addAnnotation(annotation);
+ annotations.add(annotation);
}
@Override
@Nonnull
public List<JAnnotation> getAnnotations(@Nonnull JAnnotationType annotationType) {
- return annotations.getAnnotation(annotationType);
+ return Jack.getUnmodifiableCollections().getUnmodifiableList(
+ AnnotationUtils.getAnnotation(annotations, annotationType));
}
@Override
@Nonnull
public Collection<JAnnotation> getAnnotations() {
- return annotations.getAnnotations();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(annotations);
}
@Override
@Nonnull
public Collection<JAnnotationType> getAnnotationTypes() {
- return annotations.getAnnotationTypes();
+ return Jack.getUnmodifiableCollections().getUnmodifiableCollection(
+ AnnotationUtils.getAnnotationTypes(annotations));
}
@Override
protected void transform(@Nonnull JNode existingNode, @CheckForNull JNode newNode,
@Nonnull Transformation transformation) throws UnsupportedOperationException {
- if (!annotations.transform(existingNode, newNode, transformation)) {
+ if (!transform(annotations, existingNode, (JAnnotation) newNode, transformation)) {
super.transform(existingNode, newNode, transformation);
}
}
diff --git a/jack/src/com/android/jack/util/AnnotationUtils.java b/jack/src/com/android/jack/util/AnnotationUtils.java
new file mode 100644
index 0000000..3cc9757
--- /dev/null
+++ b/jack/src/com/android/jack/util/AnnotationUtils.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.jack.util;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+
+import com.android.jack.ir.ast.JAnnotation;
+import com.android.jack.ir.ast.JAnnotationType;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Class providing tools to manipulate{@link JAnnotation}.
+ */
+public class AnnotationUtils {
+
+ @Nonnull
+ public static Collection<JAnnotationType> getAnnotationTypes(
+ @Nonnull Collection<JAnnotation> annotations) {
+ return Collections2.transform(annotations, new Function<JAnnotation, JAnnotationType>() {
+ @Override
+ public JAnnotationType apply(JAnnotation annotation) {
+ return annotation.getType();
+ }
+ });
+ }
+
+ @Nonnull
+ public static List<JAnnotation> getAnnotation(@Nonnull Collection<JAnnotation> annotations,
+ @Nonnull JAnnotationType annotationType) {
+ List<JAnnotation> foundAnnotations = new ArrayList<JAnnotation>();
+
+ for (JAnnotation annotation : annotations) {
+ if (annotation.getType().equals(annotationType)) {
+ foundAnnotations.add(annotation);
+ }
+ }
+
+ return foundAnnotations;
+ }
+}