Improve code clarity by always returning ImmutableList.
@@ -23,7 +23,6 @@ import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.lang.annotation.Annotation;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.lang.model.element.AnnotationMirror;
@@ -70,17 +69,18 @@ public class MoreApt {
/**
* Returns a list of fully qualified name of a class found in an annotation.
*
- * <p>Reading values for type Class in annotation processors causes issues, see
- * {@link Element#getAnnotation(Class)}. To work around these issues we treat the annotation value
- * as a String.
+ * <p>Reading values for type Class in annotation processors causes issues, see {@link
+ * Element#getAnnotation(Class)}. To work around these issues we treat the annotation value as a
+ * String.
+ *
* <p>Note: If this method is invoked with an annotation and method that does not contain a
* Collection / Array of class files it will throw an {@link IllegalArgumentException}.
*/
- public static List<String> getClassNamesFromAnnotation(
+ public static ImmutableList<String> getClassNamesFromAnnotation(
Element element, final Class<? extends Annotation> annotationClass, String field) {
Optional<AnnotationValue> annotationValue = getAnnotationValue(element, annotationClass, field);
if (!annotationValue.isPresent()) {
- return new ArrayList<>();
+ return ImmutableList.<String>of();
}
Object value = annotationValue.get().getValue();
checkArgument(value instanceof List, "The annotation value does not represent a list");
