Search in sources :

Example 6 with ParseTools.findClass

use of org.mvel2.util.ParseTools.findClass in project mvel by mikebrock.

the class ForEachNode method handleCond.

private void handleCond(char[] condition, int start, int offset, int fields, ParserContext pCtx) {
    int cursor = start;
    int end = start + offset;
    while (cursor < end && condition[cursor] != ':') cursor++;
    if (cursor == end || condition[cursor] != ':')
        throw new CompileException("expected : in foreach", condition, cursor);
    int x;
    if ((x = (item = createStringTrimmed(condition, start, cursor - start)).indexOf(' ')) != -1) {
        String tk = new String(condition, start, x).trim();
        try {
            itemType = ParseTools.findClass(null, tk, pCtx);
            item = new String(condition, start + x, (cursor - start) - x).trim();
        } catch (ClassNotFoundException e) {
            throw new CompileException("cannot resolve identifier: " + tk, condition, start);
        }
    }
    // this.start = ++cursor;
    this.start = cursor + 1;
    this.offset = offset - (cursor - start) - 1;
    if ((fields & COMPILE_IMMEDIATE) != 0) {
        Class egress = (this.condition = (ExecutableStatement) subCompileExpression(expr, this.start, this.offset, pCtx)).getKnownEgressType();
        if (itemType != null && egress.isArray()) {
            enforceTypeSafety(itemType, getBaseComponentType(this.condition.getKnownEgressType()));
        } else if (pCtx.isStrongTyping()) {
            determineIterType(egress);
        }
    }
}
Also used : CompileException(org.mvel2.CompileException)

Aggregations

CompileException (org.mvel2.CompileException)5 AccessorNode (org.mvel2.compiler.AccessorNode)2 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)2 Constructor (java.lang.reflect.Constructor)1 ConstructorAccessor (org.mvel2.optimizers.impl.refl.nodes.ConstructorAccessor)1