public void checkArgumentCount(int passing) { if (passing != parmNum) { throw new CompileException("bad number of arguments in function call: " + passing + " (expected: " + (parmNum == 0 ? "none" : parmNum) + ")", expr, start); } }
public static int captureStringLiteral(final char type, final char[] expr, int cursor, int end) { while (++cursor < end && expr[cursor] != type) { if (expr[cursor] == '\\') cursor++; } if (cursor >= end || expr[cursor] != type) { throw new CompileException("unterminated string literal", expr, cursor); } return cursor; }
private static int nextCondPart(char[] condition, int cursor, int end, boolean allowEnd) { for (; cursor < end; cursor++) { if (condition[cursor] == ';') return ++cursor; } if (!allowEnd) throw new CompileException("expected ;", condition, cursor); return cursor; } }
/** * Expect the next specified character or fail * * @param c character */ public void expectNextChar_IW(char c) { nextNonBlank(); if (cursor == end) throw new CompileException("unexpected end of statement", expr, st); if (expr[cursor] != c) throw new CompileException("unexpected character ('" + expr[cursor] + "'); was expecting: " + c, expr, st); }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { try { return !((Boolean) MVEL.eval(expr, start, offset, ctx, factory)); } catch (NullPointerException e) { throw new CompileException("negation operator applied to a null value", expr, start, e); } catch (ClassCastException e) { throw new CompileException("negation operator applied to non-boolean expression", expr, start, e); } }
public static int nextNonBlank(char[] expr, int cursor) { if ((cursor + 1) >= expr.length) { throw new CompileException("unexpected end of statement", expr, cursor); } int i = cursor; while (i != expr.length && isWhitespace(expr[i])) i++; return i; }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { Object o = MVEL.eval(expr, start, offset, ctx, factory); if (o instanceof Integer) { return ~((Integer) o); } else { throw new CompileException("was expecting type: Integer; but found type: " + (o == null ? "null" : o.getClass().getName()), expr, start); } } }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { try { return compile(valueOf(eval(expr, patternStart, patternOffset, ctx, factory))).matcher(valueOf(eval(expr, start, offset, ctx, factory))).matches(); } catch (PatternSyntaxException e) { throw new CompileException("bad regular expression", expr, patternStart, e); } }
private void enforceTypeSafety(Class required, Class actual) { if (!required.isAssignableFrom(actual) && !DataConversion.canConvert(actual, required)) { throw new CompileException("type mismatch in foreach: expected: " + required.getName() + "; but found: " + getBaseComponentType(actual), expr, start); } } }
public Object call(Object ctx, Object thisCtx, VariableResolverFactory factory, Object[] parms) { switch (type) { case FUNCTION: return ((Function) receiver).call(ctx, thisCtx, new InvokationContextFactory(factory, instance.instanceStates), parms); case PROPERTY: return receiver; case DEFERRED: throw new CompileException("unresolved prototype receiver", expr, start); } return null; }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { if (!factory.isResolveable(name)) factory.createVariable(name, null, egressType); else throw new CompileException("variable defined within scope: " + name, expr, start); return null; }
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { if (!factory.isResolveable(name)) factory.createVariable(name, null, egressType); else throw new CompileException("variable defined within scope: " + name, expr, start); return null; }
private void initSigner(Class type) { if (Integer.class.isAssignableFrom(type = boxPrimitive(type))) signer = new IntegerSigner(); else if (Double.class.isAssignableFrom(type)) signer = new DoubleSigner(); else if (Long.class.isAssignableFrom(type)) signer = new LongSigner(); else if (Float.class.isAssignableFrom(type)) signer = new FloatSigner(); else if (Short.class.isAssignableFrom(type)) signer = new ShortSigner(); else if (BigInteger.class.isAssignableFrom(type)) signer = new BigIntSigner(); else if (BigDecimal.class.isAssignableFrom(type)) signer = new BigDecSigner(); else { throw new CompileException("illegal use of '-': cannot be applied to: " + type.getName(), expr, start); } }
public Negation(char[] expr, int start, int offset, int fields, ParserContext pCtx) { super(pCtx); this.expr = expr; this.start = start; this.offset = offset; if ((fields & COMPILE_IMMEDIATE) != 0) { if (((this.stmt = (ExecutableStatement) subCompileExpression(expr, start, offset, pCtx)).getKnownEgressType() != null) && (!ParseTools.boxPrimitive(stmt.getKnownEgressType()).isAssignableFrom(Boolean.class))) { throw new CompileException("negation operator cannot be applied to non-boolean type", expr, start); } } }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { try { String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory)); if (i == null) throw new ClassCastException(); String x = (String) stmt.getReducedValue(ctx, thisValue, factory); if (x == null) throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), stmt.getStart()); return soundex(i).equals(soundex(x)); } catch (ClassCastException e) { throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart()); } }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { try { String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory)); if (i == null) throw new ClassCastException(); String x = (String) stmt.getReducedValue(ctx, thisValue, factory); if (x == null) throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), getStart()); return similarity(i, x); } catch (ClassCastException e) { throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart()); } }
private void subCompile(int start, int offset) { if (colType == null) { subCompileExpression(property, start, offset, pCtx); } else { Class r = ((ExecutableStatement) subCompileExpression(property, start, offset, pCtx)).getKnownEgressType(); if (r != null && !isAssignableFrom(colType, r) && (isStrongType() || !DataConversion.canConvert(r, colType))) { throw new CompileException("expected type: " + colType.getName() + "; but found: " + r.getName(), property, cursor); } } }
@Override public VariableResolver createIndexedVariable(int index, String name, Object value, Class<?> type) { VariableResolver vr = this.variableResolvers != null ? this.variableResolvers.getByIndex(index) : null; if (vr != null && vr.getType() != null) { throw new CompileException("variable already defined within scope: " + vr.getType() + " " + name, expr, start); } else { return createIndexedVariable(variableIndexOf(name), name, value); } }
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { PrototypalFunctionInstance instance = new PrototypalFunctionInstance(this, new MapVariableResolverFactory()); if (name != null) { if (!factory.isIndexedFactory() && factory.isResolveable(name)) throw new CompileException("duplicate function: " + name, expr, start); factory.createVariable(name, instance); } return instance; }
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { PrototypalFunctionInstance instance = new PrototypalFunctionInstance(this, new MapVariableResolverFactory()); if (name != null) { if (!factory.isIndexedFactory() && factory.isResolveable(name)) throw new CompileException("duplicate function: " + name, expr, start); factory.createVariable(name, instance); } return instance; }