Search in sources :

Example 1 with Visibility

use of com.google.auto.common.Visibility in project auto by google.

the class ExtensionClassTypeSpecBuilder method annotationVisibleFrom.

// TODO(b/122509249): Move code copied from com.google.auto.value.processor to auto-common.
private boolean annotationVisibleFrom(AnnotationMirror annotation, Element from) {
    Element annotationElement = annotation.getAnnotationType().asElement();
    Visibility visibility = Visibility.effectiveVisibilityOfElement(annotationElement);
    switch(visibility) {
        case PUBLIC:
            return true;
        case PROTECTED:
            // subclass of anything.
            return getPackage(annotationElement).equals(getPackage(from)) || types.isSubtype(from.asType(), annotationElement.getEnclosingElement().asType());
        case DEFAULT:
            return getPackage(annotationElement).equals(getPackage(from));
        default:
            return false;
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) Visibility(com.google.auto.common.Visibility)

Example 2 with Visibility

use of com.google.auto.common.Visibility in project auto by google.

the class AutoValueishProcessor method annotationVisibleFrom.

private boolean annotationVisibleFrom(AnnotationMirror annotation, Element from) {
    Element annotationElement = annotation.getAnnotationType().asElement();
    Visibility visibility = Visibility.effectiveVisibilityOfElement(annotationElement);
    switch(visibility) {
        case PUBLIC:
            return true;
        case PROTECTED:
            // subclass of anything.
            return getPackage(annotationElement).equals(getPackage(from)) || typeUtils().isSubtype(from.asType(), annotationElement.getEnclosingElement().asType());
        case DEFAULT:
            return getPackage(annotationElement).equals(getPackage(from));
        default:
            return false;
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Visibility(com.google.auto.common.Visibility)

Aggregations

Visibility (com.google.auto.common.Visibility)2 Element (javax.lang.model.element.Element)2 TypeElement (javax.lang.model.element.TypeElement)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeParameterElement (javax.lang.model.element.TypeParameterElement)1 VariableElement (javax.lang.model.element.VariableElement)1