本文整理汇总了Java中javax.lang.model.element.Element.getAnnotationMirrors方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getAnnotationMirrors方法的具体用法?Java Element.getAnnotationMirrors怎么用?Java Element.getAnnotationMirrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.Element
的用法示例。
在下文中一共展示了Element.getAnnotationMirrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAllAnnotations
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* Gets all the annotations on the given declaration.
*/
private Annotation[] getAllAnnotations(Element decl, Locatable srcPos) {
List<Annotation> r = new ArrayList<Annotation>();
for( AnnotationMirror m : decl.getAnnotationMirrors() ) {
try {
String fullName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName().toString();
Class<? extends Annotation> type =
SecureLoader.getClassClassLoader(getClass()).loadClass(fullName).asSubclass(Annotation.class);
Annotation annotation = decl.getAnnotation(type);
if(annotation!=null)
r.add( LocatableAnnotation.create(annotation,srcPos) );
} catch (ClassNotFoundException e) {
// just continue
}
}
return r.toArray(new Annotation[r.size()]);
}
示例2: getAnnotationMirror
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* Gets the AnnotationMirror for a passed annotation type from the passed element.
*
* @param element the element to get the AnnotationMirror from.
* @param fqClassName the annotations full qualified class name to get
* @return the AnnotationMirror or null if it can't be found.
*/
public static AnnotationMirror getAnnotationMirror(Element element, String fqClassName) {
for (AnnotationMirror m : element.getAnnotationMirrors()) {
if (m.getAnnotationType().toString().equals(fqClassName)) {
return m;
}
}
return null;
}
示例3: hasAnnotationWithName
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private static boolean hasAnnotationWithName(Element element, String simpleName) {
for (AnnotationMirror mirror : element.getAnnotationMirrors()) {
String annotationName = mirror.getAnnotationType().asElement().getSimpleName().toString();
if (simpleName.equals(annotationName)) {
return true;
}
}
return false;
}
示例4: findAnnotations
import javax.lang.model.element.Element; //导入方法依赖的package包/类
public static List<AnnotationMirror> findAnnotations(Element element, String annotationClass){
ArrayList<AnnotationMirror> ret = new ArrayList<AnnotationMirror>();
for (AnnotationMirror ann : element.getAnnotationMirrors()){
if (annotationClass.equals(ann.getAnnotationType().toString())){
ret.add(ann);
}
}
return ret;
}
示例5: printAnnotations
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private void printAnnotations(Element e) {
List<? extends AnnotationMirror> annots = e.getAnnotationMirrors();
for(AnnotationMirror annotationMirror : annots) {
indent();
writer.println(annotationMirror);
}
}
示例6: getAnnotationMirror
import javax.lang.model.element.Element; //导入方法依赖的package包/类
public static AnnotationMirror getAnnotationMirror(
final Element element,
final Class<? extends Annotation> annotationClass) {
checkNotNull(element, "Argument \'element\' cannot be null.");
checkNotNull(annotationClass, "Argument \'annotationClass\' cannot be null.");
for (final AnnotationMirror mirror : element.getAnnotationMirrors()) {
if (mirror.getAnnotationType().toString().equals(annotationClass.getName())) {
return mirror;
}
}
return null;
}
示例7: isAnnotatedUiThread
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private boolean isAnnotatedUiThread(Element element) {
for (AnnotationMirror mirror : element.getAnnotationMirrors()) {
if ("android.support.annotation.UiThread".equals(mirror.getAnnotationType().toString())) {
return true;
}
}
return false;
}
示例8: addDeprecated
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private <T extends Tree> T addDeprecated(Element e, T orig) {
if (!wc.getElements().isDeprecated(e) || true) return orig;
for (AnnotationMirror am : e.getAnnotationMirrors()) {
if (((TypeElement) am.getAnnotationType().asElement()).getQualifiedName().contentEquals("java.lang.Deprecated")) {
return orig; //do not add the artificial @deprecated javadoc when there is a @Deprecated annotation
}
}
Comment javadoc = Comment.create(Comment.Style.JAVADOC, "@deprecated");
wc.getTreeMaker().addComment(orig, javadoc, true);
return orig;
}
示例9: getStyleableAnnotationValues
import javax.lang.model.element.Element; //导入方法依赖的package包/类
static StyleableAnnotationValues getStyleableAnnotationValues(final Trees trees, final Elements elementUtils, final Types typeUtils, final Messager messager, final Element annotatedElement) {
RClassReference styleableReference = null;
RClassReference defaultValueReference = null;
AnnotationMirror annotationMirror = null;
for (final AnnotationMirror mirror : annotatedElement.getAnnotationMirrors()) {
if (mirror.getAnnotationType().toString().equals(Styleable.class.getCanonicalName())) {
annotationMirror = mirror;
break;
}
}
AnnotationValue value = null;
AnnotationValue defaultValue = null;
//noinspection ConstantConditions
for (final Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) {
if (entry.getKey().getSimpleName().toString().equals("value")) {
value = entry.getValue();
} else if (entry.getKey().getSimpleName().toString().equals("defaultRes")) {
defaultValue = entry.getValue();
}
}
styleableReference = getRClassReference(trees, elementUtils, typeUtils, messager, annotatedElement, annotationMirror, value, StyleableField.VALUE_FIELD);
if (defaultValue != null) {
defaultValueReference = getRClassReference(trees, elementUtils, typeUtils, messager, annotatedElement, annotationMirror, defaultValue, StyleableField.DEFAULT_RES_FIELD);
}
return new StyleableAnnotationValues(styleableReference, defaultValueReference);
}
示例10: findAnnotationMirror
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* Find specified annotation for some element.
* @param element element where we look for annotation.
* @param annotationType Type of annotation we are looking for.
* @return the annotation mirror of same type as annotationType or null if doesn't exist
*/
private AnnotationMirror findAnnotationMirror(Element element, TypeMirror annotationType) {
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
// FIXME: use proper comparison of TypeMirror, Types.isSameType, but no idea how to instantiate it
if (annotationType.toString().equals(annotationMirror.getAnnotationType().toString())) {
return annotationMirror;
}
}
return null;
}
示例11: findAnnotationMirror
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* @param element a source element
* @param annotation a type of annotation
* @return the instance of that annotation on the element, or null if not found
*/
private AnnotationMirror findAnnotationMirror(Element element, Class<? extends Annotation> annotation) {
for (AnnotationMirror ann : element.getAnnotationMirrors()) {
if (processingEnv.getElementUtils().getBinaryName((TypeElement) ann.getAnnotationType().asElement()).
contentEquals(annotation.getName())) {
return ann;
}
}
return null;
}
示例12: getAnnotationMirror
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* Returns an {@link AnnotationMirror} for the annotation of type {@code annotationClass} on
* {@code element}, or {@link Optional#absent()} if no such annotation exists. This method is a
* safer alternative to calling {@link Element#getAnnotation} as it avoids any interaction with
* annotation proxies.
*/
public static Optional<AnnotationMirror> getAnnotationMirror(Element element,
Class<? extends Annotation> annotationClass) {
String annotationClassName = annotationClass.getCanonicalName();
for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
TypeElement annotationTypeElement = asType(annotationMirror.getAnnotationType().asElement());
if (annotationTypeElement.getQualifiedName().contentEquals(annotationClassName)) {
return Optional.of(annotationMirror);
}
}
return Optional.absent();
}
示例13: isAccessible
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private boolean isAccessible(Element m) {
if (!m.getModifiers().contains(Modifier.PUBLIC)) {
for (AnnotationMirror am : m.getAnnotationMirrors()) {
String atype = ((TypeElement)am.getAnnotationType().asElement()).getQualifiedName().toString();
if (ANNOTATION_TYPE_FXML.equals(atype)) {
return true;
}
}
return false;
} else {
return true;
}
}
示例14: findServiceAnnotation
import javax.lang.model.element.Element; //导入方法依赖的package包/类
private List<TypeMirror> findServiceAnnotation(Element e) throws LayerGenerationException {
for (AnnotationMirror ann : e.getAnnotationMirrors()) {
if (!ProjectServiceProvider.class.getName().equals(ann.getAnnotationType().toString())) {
continue;
}
for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> attr : ann.getElementValues().entrySet()) {
if (!attr.getKey().getSimpleName().contentEquals("service")) {
continue;
}
List<TypeMirror> r = new ArrayList<TypeMirror>();
for (Object item : (List<?>) attr.getValue().getValue()) {
TypeMirror type = (TypeMirror) ((AnnotationValue) item).getValue();
Types typeUtils = processingEnv.getTypeUtils();
for (TypeMirror otherType : r) {
for (boolean swap : new boolean[] {false, true}) {
TypeMirror t1 = swap ? type : otherType;
TypeMirror t2 = swap ? otherType : type;
if (typeUtils.isSubtype(t1, t2)) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "registering under both " + typeUtils.asElement(t2).getSimpleName() + " and its subtype " + typeUtils.asElement(t1).getSimpleName() + " will not work if LookupMerger<" + typeUtils.asElement(t2).getSimpleName() + "> is used (#205151)", e, ann, attr.getValue());
}
}
}
r.add(type);
}
return r;
}
throw new LayerGenerationException("No service attr found", e);
}
throw new LayerGenerationException("No @ProjectServiceProvider found", e);
}
示例15: getTypesFromAnnotation
import javax.lang.model.element.Element; //导入方法依赖的package包/类
/**
* At compile time classes can not be obtained from annotation directly.
* This method extracts class information from annotation mirrors.
*
* @param element element annotated with {@link SqlSource} annotation
* @param isReq true for request, false for result parameters
* @return list of class names from {@link SqlSource} annotation
*/
private List<String> getTypesFromAnnotation(Element element, boolean isReq) {
TypeMirror sqlSourceTypeMirror = processingEnv.getElementUtils().getTypeElement(SqlSource.class.getName()).asType();
//method names from SqlSource annotation
String methodName = isReq ? "reqImpl" : "resImpl";
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
List<String> typeNames = new ArrayList<>();
for (AnnotationMirror am : annotationMirrors) {
if (!am.getAnnotationType().equals(sqlSourceTypeMirror)) {
continue;
}
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
if (!methodName.equals(entry.getKey().getSimpleName().toString())) {
continue;
}
AnnotationValue impResVal = entry.getValue();
impResVal.accept(new SimpleAnnotationValueVisitor8<Void, Void>() {
@Override
public Void visitArray(List<? extends AnnotationValue> list, Void s) {
for (AnnotationValue val : list) {
TypeMirror typeMirror = (TypeMirror) val.getValue();
typeNames.add(typeMirror.toString());
}
return null;
}
}, null);
break;
}
}
return typeNames;
}