Search in sources :

Example 1 with Verifier

use of com.twitter.common.args.Verifier in project commons by twitter.

the class CmdLineProcessor method processVerifiers.

private void processVerifiers(Set<? extends Element> elements) {
    TypeElement verifierType = typeElement(Verifier.class);
    TypeElement verifierForType = typeElement(VerifierFor.class);
    for (Element element : elements) {
        if (element.getKind() != ElementKind.CLASS) {
            error("Found a @VerifierFor annotation on a non-class %s", element);
        } else {
            TypeElement verifier = (TypeElement) element;
            if (!isAssignable(verifier, Verifier.class)) {
                error("Found a @Verifier annotation on a non-Verifier %s", element);
                return;
            }
            String verifierClassName = getBinaryName(verifier);
            @Nullable AnnotationMirror verifierFor = getAnnotationMirror(verifier, verifierForType);
            if (verifierFor != null) {
                @Nullable TypeElement verifyAnnotationType = getClassType(verifierFor, "value", null);
                if (verifyAnnotationType != null) {
                    @Nullable String verifiedType = getTypeArgument(verifier, verifierType);
                    if (verifiedType != null) {
                        String verifyAnnotationClassName = elementUtils.getBinaryName(verifyAnnotationType).toString();
                        getBuilder(verifierClassName).addVerifier(verifiedType, verifyAnnotationClassName, verifierClassName);
                    }
                }
            }
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) Verifier(com.twitter.common.args.Verifier) Nullable(javax.annotation.Nullable)

Aggregations

Verifier (com.twitter.common.args.Verifier)1 Nullable (javax.annotation.Nullable)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1