本文整理汇总了Java中com.google.auto.common.MoreElements.getAnnotationMirror方法的典型用法代码示例。如果您正苦于以下问题:Java MoreElements.getAnnotationMirror方法的具体用法?Java MoreElements.getAnnotationMirror怎么用?Java MoreElements.getAnnotationMirror使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.auto.common.MoreElements
的用法示例。
在下文中一共展示了MoreElements.getAnnotationMirror方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findOptionsMirror
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private static Optional<AnnotationMirror> findOptionsMirror(TypeElement element) {
Optional<AnnotationMirror> result =
MoreElements.getAnnotationMirror(element, PaperParcel.Options.class);
if (!result.isPresent()) {
ImmutableSet<? extends AnnotationMirror> annotatedAnnotations =
AnnotationMirrors.getAnnotatedAnnotations(element, PaperParcel.Options.class);
if (annotatedAnnotations.size() > 1) {
throw new IllegalStateException("PaperParcel options applied twice.");
} else if (annotatedAnnotations.size() == 1) {
AnnotationMirror annotatedAnnotation = annotatedAnnotations.iterator().next();
result = MoreElements.getAnnotationMirror(
annotatedAnnotation.getAnnotationType().asElement(), PaperParcel.Options.class);
} else {
TypeMirror superType = element.getSuperclass();
if (superType.getKind() != TypeKind.NONE) {
TypeElement superElement = asType(asDeclared(superType).asElement());
result = findOptionsMirror(superElement);
}
}
}
return result;
}
示例2: getParameterFrom
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
private static Optional<AnnotationValue> getParameterFrom(TypeElement typeElement
, Class<? extends Annotation> annotationClass
, String paramName
, ProcessingEnvironment env) {
Optional<AnnotationMirror> annotationMirror = MoreElements.getAnnotationMirror(typeElement, annotationClass);
if (annotationMirror.isPresent()) {
AnnotationValue value = getAnnotationValue(annotationMirror.get(), paramName, env);
return Optional.fromNullable(value);
}
return Optional.absent();
}
示例3: getAnnotationValue
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/**
* If the given {@code element} is annotated with an {@link Annotation} of class {@code clazz}
* it's value for {@code key} will be returned. Otherwise it will return null.
*
* @throws IllegalArgumentException if no element is defined with the given key.
*/
public static Object getAnnotationValue(
Element element, Class<? extends Annotation> clazz, String key) {
Optional<AnnotationMirror> annotation = MoreElements.getAnnotationMirror(element, clazz);
if (annotation.isPresent()) {
return AnnotationMirrors.getAnnotationValue(annotation.get(), key).getValue();
}
return null;
}
示例4: getValueFromAnnotation
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
public static <T> T getValueFromAnnotation(Element element, Class<? extends Annotation> annotation, String name) {
Optional<AnnotationMirror> annotationMirror = MoreElements.getAnnotationMirror(element, annotation);
if (!annotationMirror.isPresent()) {
return null;
}
AnnotationValue annotationValue = getAnnotationValue(annotationMirror.get(), name);
return annotationValue != null ? (T) annotationValue.getValue() : null;
}
示例5: getFieldsToParcel
import com.google.auto.common.MoreElements; //导入方法依赖的package包/类
/** Returns all non-excluded fields on a {@link PaperParcel} annotated {@link TypeElement}. */
static ImmutableList<VariableElement> getFieldsToParcel(
TypeElement element, OptionsDescriptor options) {
Optional<AnnotationMirror> paperParcelMirror =
MoreElements.getAnnotationMirror(element, PaperParcel.class);
if (paperParcelMirror.isPresent()) {
ImmutableList.Builder<VariableElement> fields = ImmutableList.builder();
getFieldsToParcelImpl(element, options, fields, new HashSet<Name>());
return fields.build();
} else {
throw new IllegalArgumentException("element must be annotated with @PaperParcel");
}
}