use of org.drools.core.addon.TypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveFullTypeName.
@Test
public void testResolveFullTypeName() throws Exception {
final TypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
resolver.addImport("org.drools.core.test.model.Cheese");
resolver.addImport("org.drools.core.test.model.FirstClass");
assertEquals("org.drools.core.test.model.Cheese", resolver.getFullTypeName("Cheese"));
assertEquals("org.drools.core.test.model.FirstClass", resolver.getFullTypeName("FirstClass"));
}
use of org.drools.core.addon.TypeResolver in project drools by kiegroup.
the class Evaluator method compileWithMvelCompiler.
private static CompiledResult compileWithMvelCompiler(Object compiledExpression, Map<String, Object> vars, ClassLoader classLoader) {
String expressionString = compiledExpression.toString();
Set<String> imports = new HashSet<>();
imports.add("java.util.List");
imports.add("java.util.ArrayList");
imports.add("java.util.HashMap");
imports.add("java.util.Map");
imports.add("java.math.BigDecimal");
imports.add("org.drools.Address");
TypeResolver classTypeResolver = new ClassTypeResolver(imports, classLoader);
MvelCompilerContext context = new MvelCompilerContext(classTypeResolver);
for (Map.Entry<String, Object> o : vars.entrySet()) {
Object value1 = o.getValue();
if (value1 != null) {
context.addDeclaration(o.getKey(), value1.getClass());
}
}
MvelCompiler mvelCompiler = new MvelCompiler(context);
ConstraintCompiler constraintCompiler = new ConstraintCompiler(context);
if (isAStatement(expressionString)) {
String expressionStringWithBraces = String.format("{%s}", expressionString);
return mvelCompiler.compileStatement(expressionStringWithBraces);
} else {
return constraintCompiler.compileExpression(expressionString);
}
}
Aggregations