Search in sources :

Example 1 with TypefaceStyles

use of butterknife.compiler.FieldTypefaceBinding.TypefaceStyles in project butterknife by JakeWharton.

the class ButterKnifeProcessor method parseResourceFont.

private void parseResourceFont(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) {
    boolean hasError = false;
    TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
    // Verify that the target type is a Typeface.
    if (!TYPEFACE_TYPE.equals(element.asType().toString())) {
        error(element, "@%s field type must be 'Typeface'. (%s.%s)", BindFont.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName());
        hasError = true;
    }
    // Verify common generated code restrictions.
    hasError |= isInaccessibleViaGeneratedCode(BindFont.class, "fields", element);
    hasError |= isBindingInWrongPackage(BindFont.class, element);
    // Assemble information on the field.
    String name = element.getSimpleName().toString();
    BindFont bindFont = element.getAnnotation(BindFont.class);
    int styleValue = bindFont.style();
    TypefaceStyles style = TypefaceStyles.fromValue(styleValue);
    if (style == null) {
        error(element, "@%s style must be NORMAL, BOLD, ITALIC, or BOLD_ITALIC. (%s.%s)", BindFont.class.getSimpleName(), enclosingElement.getQualifiedName(), name);
        hasError = true;
    }
    if (hasError) {
        return;
    }
    BindingSet.Builder builder = getOrCreateBindingBuilder(builderMap, enclosingElement);
    Id resourceId = elementToId(element, BindFont.class, bindFont.value());
    builder.addResource(new FieldTypefaceBinding(resourceId, name, style));
    erasedTargetNames.add(enclosingElement);
}
Also used : TypeElement(javax.lang.model.element.TypeElement) TypefaceStyles(butterknife.compiler.FieldTypefaceBinding.TypefaceStyles) BindString(butterknife.BindString) BindFont(butterknife.BindFont)

Aggregations

BindFont (butterknife.BindFont)1 BindString (butterknife.BindString)1 TypefaceStyles (butterknife.compiler.FieldTypefaceBinding.TypefaceStyles)1 TypeElement (javax.lang.model.element.TypeElement)1