Search in sources :

Example 1 with TemplateMarkupOutputModel

use of freemarker.core.TemplateMarkupOutputModel in project freemarker by apache.

the class OverloadedMethods method addMarkupBITipAfterNoNoMarchIfApplicable.

/**
 * Adds tip to the error message if converting a {@link TemplateMarkupOutputModel} argument to {@link String} might
 * allows finding a matching overload.
 */
private void addMarkupBITipAfterNoNoMarchIfApplicable(_ErrorDescriptionBuilder edb, List tmArgs) {
    for (int argIdx = 0; argIdx < tmArgs.size(); argIdx++) {
        Object tmArg = tmArgs.get(argIdx);
        if (tmArg instanceof TemplateMarkupOutputModel) {
            for (Iterator membDescs = fixArgMethods.getMemberDescriptors(); membDescs.hasNext(); ) {
                CallableMemberDescriptor membDesc = (CallableMemberDescriptor) membDescs.next();
                Class[] paramTypes = membDesc.getParamTypes();
                Class paramType = null;
                if (membDesc.isVarargs() && argIdx >= paramTypes.length - 1) {
                    paramType = paramTypes[paramTypes.length - 1];
                    if (paramType.isArray()) {
                        paramType = paramType.getComponentType();
                    }
                }
                if (paramType == null && argIdx < paramTypes.length) {
                    paramType = paramTypes[argIdx];
                }
                if (paramType != null) {
                    if (paramType.isAssignableFrom(String.class) && !paramType.isAssignableFrom(tmArg.getClass())) {
                        edb.tip(SimpleMethodModel.MARKUP_OUTPUT_TO_STRING_TIP);
                        return;
                    }
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) freemarker.core._DelayedConversionToString(freemarker.core._DelayedConversionToString) TemplateMarkupOutputModel(freemarker.core.TemplateMarkupOutputModel)

Aggregations

TemplateMarkupOutputModel (freemarker.core.TemplateMarkupOutputModel)1 freemarker.core._DelayedConversionToString (freemarker.core._DelayedConversionToString)1 Iterator (java.util.Iterator)1