Search in sources :

Example 1 with FormatType

use of org.checkerframework.checker.i18nformatter.I18nFormatterTreeUtil.FormatType in project checker-framework by typetools.

the class I18nFormatterVisitor method checkInvocationFormatFor.

private void checkInvocationFormatFor(I18nFormatCall fc) {
    I18nFormatterTreeUtil tu = atypeFactory.treeUtil;
    Result<FormatType> type = fc.getFormatType();
    Result<InvocationType> invc;
    I18nConversionCategory[] formatCats;
    switch(type.value()) {
        case I18NINVALID:
            tu.failure(type, "i18nformat.string.invalid", fc.getInvalidError());
            break;
        case I18NFORMATFOR:
            if (!fc.isValidFormatForInvocation()) {
                Result<FormatType> failureType = fc.getInvalidInvocationType();
                tu.failure(failureType, "i18nformat.invalid.formatfor");
            }
            break;
        case I18NFORMAT:
            invc = fc.getInvocationType();
            formatCats = fc.getFormatCategories();
            switch(invc.value()) {
                case VARARG:
                    Result<TypeMirror>[] paramTypes = fc.getParamTypes();
                    int paraml = paramTypes.length;
                    int formatl = formatCats.length;
                    // from commonAssignmentCheck.
                    if (paraml < formatl) {
                        tu.warning(invc, "i18nformat.missing.arguments", formatl, paraml);
                    }
                    if (paraml > formatl) {
                        tu.warning(invc, "i18nformat.excess.arguments", formatl, paraml);
                    }
                    for (int i = 0; i < formatl && i < paraml; ++i) {
                        I18nConversionCategory formatCat = formatCats[i];
                        Result<TypeMirror> param = paramTypes[i];
                        TypeMirror paramType = param.value();
                        switch(formatCat) {
                            case UNUSED:
                                tu.warning(param, "i18nformat.argument.unused", " " + (1 + i));
                                break;
                            case GENERAL:
                                break;
                            default:
                                if (!fc.isValidParameter(formatCat, paramType)) {
                                    tu.failure(param, "argument.type.incompatible", paramType, formatCat);
                                }
                        }
                    }
                    break;
                case NULLARRAY:
                // fall-through
                case ARRAY:
                    for (I18nConversionCategory cat : formatCats) {
                        if (cat == I18nConversionCategory.UNUSED) {
                            tu.warning(invc, "i18nformat.argument.unused", "");
                        }
                    }
                    tu.warning(invc, "i18nformat.indirect.arguments");
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) InvocationType(org.checkerframework.checker.formatter.FormatterTreeUtil.InvocationType) FormatType(org.checkerframework.checker.i18nformatter.I18nFormatterTreeUtil.FormatType) I18nConversionCategory(org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory) Result(org.checkerframework.checker.formatter.FormatterTreeUtil.Result)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)1 InvocationType (org.checkerframework.checker.formatter.FormatterTreeUtil.InvocationType)1 Result (org.checkerframework.checker.formatter.FormatterTreeUtil.Result)1 FormatType (org.checkerframework.checker.i18nformatter.I18nFormatterTreeUtil.FormatType)1 I18nConversionCategory (org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1