use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolvePrimtiveTypes.
@Test
public void testResolvePrimtiveTypes() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
assertEquals(boolean.class, resolver.resolveType("boolean"));
assertEquals(double.class, resolver.resolveType("double"));
assertEquals(float.class, resolver.resolveType("float"));
assertEquals(int.class, resolver.resolveType("int"));
assertEquals(char.class, resolver.resolveType("char"));
assertEquals(long.class, resolver.resolveType("long"));
assertEquals(byte.class, resolver.resolveType("byte"));
assertEquals(short.class, resolver.resolveType("short"));
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class ClassTypeResolverTest method testResolveMultidimensionnalArrayOfPrimitiveTypes.
@Test
public void testResolveMultidimensionnalArrayOfPrimitiveTypes() throws Exception {
final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
assertEquals(int[][].class, resolver.resolveType("int[][]"));
assertEquals(int[][][].class, resolver.resolveType("int[][][]"));
assertEquals(int[][][][].class, resolver.resolveType("int[][][][]"));
}
use of org.drools.core.addon.ClassTypeResolver 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);
}
}
use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.
the class PackageHeaderLoader method findImportsFromJars.
private void findImportsFromJars(Collection<String> imports, List<JarInputStream> jarInputStreams) throws IOException {
ClassTypeResolver resolver = new ClassTypeResolver(new HashSet<String>(), new VerifierMapBackedClassLoader(jarInputStreams));
for (String className : imports) {
classNames.add(className);
try {
Class clazz = resolver.resolveType(className);
addFields(clazz);
} catch (ClassNotFoundException e) {
missingClasses.add(className);
}
}
}
Aggregations