use of org.mvel2.asm.Type in project mvel by mikebrock.
the class TypesAndInferenceTests method testDetermineEgressParametricType.
public final void testDetermineEgressParametricType() {
final ParserContext parserContext = new ParserContext();
parserContext.setStrongTyping(true);
parserContext.addInput("strings", List.class, new Class[] { String.class });
final CompiledExpression expr = new ExpressionCompiler("strings").compile(parserContext);
assertTrue(STRINGS.equals(executeExpression(expr, new A())));
final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
assertTrue(typeParameters != null);
assertTrue(String.class.equals(typeParameters[0]));
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class TypesAndInferenceTests method testDetermineEgressParametricType2.
public final void testDetermineEgressParametricType2() {
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();
assertTrue(STRINGS.equals(executeExpression(expr, new A())));
final Type[] typeParameters = expr.getParserContext().getLastTypeParameters();
assertTrue(null != typeParameters);
assertTrue(String.class.equals(typeParameters[0]));
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class ProtoParser method calculateDecl.
private void calculateDecl() {
if (tk2 != null) {
try {
if (pCtx.hasProtoImport(tk1)) {
type = Proto.class;
} else {
type = ParseTools.findClass(null, tk1, pCtx);
}
name = tk2;
} catch (ClassNotFoundException e) {
if (interpreted) {
type = DeferredTypeResolve.class;
deferredName = tk1;
name = tk2;
} else {
throw new CompileException("could not resolve class: " + tk1, expr, cursor, e);
}
}
} else {
type = Object.class;
name = tk1;
}
tk1 = null;
tk2 = null;
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromMethod.
public final void testInferLastTypeParametersFromMethod() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.values()").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertTrue("Expression did not evaluate correctly: " + val, STRINGS.equals(val));
assertTrue("No type parameters detected", null != context.getLastTypeParameters());
assertTrue("Wrong parametric type inferred", String.class.equals(context.getLastTypeParameters()[0]));
}
use of org.mvel2.asm.Type in project mvel by mikebrock.
the class GenericsTypeInferenceTest method testInferLastTypeParametersFromPropertyMethod.
public final void testInferLastTypeParametersFromPropertyMethod() {
ParserContext context = new ParserContext();
context.setStrongTyping(true);
context.addInput("a", A.class);
final CompiledExpression compiledExpression = new ExpressionCompiler("a.getFooMap()[\"key\"].someMethod()").compile(context);
final Object val = MVEL.executeExpression(compiledExpression, new AWrapper());
assertEquals("Expression did not evaluate correctly: ", "bar", val);
assertNotNull("No type parameters detected", context.getLastTypeParameters());
assertEquals("Wrong parametric type inferred", String.class, context.getLastTypeParameters()[0]);
}
Aggregations