當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.getAnnotationMirrors方法代碼示例

本文整理匯總了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()]);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:InlineAnnotationReaderImpl.java

示例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;
}
 
開發者ID:toolisticon,項目名稱:annotation-processor-toolkit,代碼行數:16,代碼來源:AnnotationUtils.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:ButterKnifeProcessor.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:Utilities.java

示例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);
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:8,代碼來源:PrintingProcessor.java

示例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;
}
 
開發者ID:MatthewTamlin,項目名稱:Spyglass,代碼行數:16,代碼來源:AnnotationMirrorHelper.java

示例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;
}
 
開發者ID:linroid,項目名稱:Wrapper,代碼行數:9,代碼來源:WrapperProcessor.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:CodeGenerator.java

示例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);
}
 
開發者ID:chRyNaN,項目名稱:glimpse,代碼行數:33,代碼來源:RClassUtil.java

示例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;
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:16,代碼來源:ClassCrawler.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:AbstractServiceProviderProcessor.java

示例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();
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:18,代碼來源:MoreElements.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:BeanModelBuilder.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:LookupProviderAnnotationProcessor.java

示例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;
}
 
開發者ID:nds842,項目名稱:sql-first-mapper,代碼行數:39,代碼來源:SqlFirstAnnotationProcessor.java


注:本文中的javax.lang.model.element.Element.getAnnotationMirrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。