public int checkBreak(LineLabel label, VariableResolverFactory factory, CompiledExpression expression) { if (debuggerState == Debugger.STEP || hasBreakpoint(label)) { if (debugger == null) throw new RuntimeException("no debugger registered to handle breakpoint"); return debuggerState = debugger.onBreak(new Frame(label, factory, expression.getParserContext())); } return 0; }
public Type resolveEgressType(String expression) throws ExpressionCompileException { // try to get the type from the cache Type type = egressTypes.get(expression); if (type != null) { return type; } CompiledExpression compiled = compileExpression(expression); final Class<?> egressClass = compiled.getKnownEgressType(); final Type[] parameters = compiled.getParserContext().getLastTypeParameters(); if (parameters == null) { // the class is not parameterised (generic) type = egressClass; } else { // reconstruct the Type from mvel's generics details type = new ParameterizedTypeImpl(egressClass, parameters, egressClass.getEnclosingClass()); } egressTypes.put(expression, type); return type; }
public static Serializable optimizeTree(final CompiledExpression compiled) { /** * If there is only one token, and it's an identifier, we can optimize this as an accessor expression. */ if (!compiled.isImportInjectionRequired() && compiled.getParserContext().isAllowBootstrapBypass() && compiled.isSingleNode()) { return _optimizeTree(compiled); } return compiled; }
public static Object executeDebugger(CompiledExpression expression, Object ctx, VariableResolverFactory vars) { try { if (expression.isImportInjectionRequired()) { return execute(true, expression, ctx, new ClassImportResolverFactory(expression .getParserContext().getParserConfiguration(), vars)); } else { return execute(true, expression, ctx, vars); } } catch (EndWithValue e) { return e.getValue(); } }
@Test public final void determineEgressParametricType() { final ParserContext parserContext = new ParserContext(); parserContext.setStrongTyping(true); parserContext.addInput("strings", List.class, new Class[] { String.class }); final CompiledExpression expr = new ExpressionCompiler("strings", parserContext) .compile(); assert STRINGS.equals(MVEL.executeExpression(expr, new A())) : "faulty expression eval"; final Type[] typeParameters = expr.getParserContext().getLastTypeParameters(); assert null != typeParameters : "no generic egress type"; assert String.class.equals(typeParameters[0]) : "wrong generic egress type"; }
@Test public final void determineEgressParametricTypeInExprChain() { final ParserContext parserContext = new ParserContext(); parserContext.setStrongTyping(true); parserContext.addInput("strings", A.class); final CompiledExpression expr = new ExpressionCompiler("strings.strings", parserContext) .compile(); assert STRINGS.equals(MVEL.executeExpression(expr, new B())) : "faulty expression eval"; final Type[] typeParameters = expr.getParserContext().getLastTypeParameters(); assert null != typeParameters : "no generic egress type"; assert String.class.equals(typeParameters[0]) : "wrong generic egress type"; }