Search in sources :

Example 11 with ClassTypeResolver

use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.

the class ExpressionTyperTest method setUp.

@Before
public void setUp() throws Exception {
    imports = new HashSet<>();
    packageModel = new PackageModel("", "", null, null, new DRLIdGenerator());
    typeResolver = new ClassTypeResolver(imports, getClass().getClassLoader());
    ruleContext = new RuleContext(knowledgeBuilder, packageModel, typeResolver, ruleDescr);
    imports.add("org.drools.modelcompiler.domain.Person");
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) Before(org.junit.Before)

Example 12 with ClassTypeResolver

use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.

the class ConstraintParserTest method setup.

@Before
public void setup() {
    PackageModel packageModel = new PackageModel("org.kie.test:constraint-parser-test:1.0.0", "org.kie.test", null, null, null);
    Set<String> imports = new HashSet<>();
    imports.add("org.drools.modelcompiler.domain.Person");
    TypeResolver typeResolver = new ClassTypeResolver(imports, getClass().getClassLoader());
    RuleContext context = new RuleContext(null, packageModel, typeResolver, null, 0);
    parser = ConstraintParser.defaultConstraintParser(context, packageModel);
}
Also used : RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) TypeResolver(org.drools.core.addon.TypeResolver) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) PackageModel(org.drools.modelcompiler.builder.PackageModel) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 13 with ClassTypeResolver

use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.

the class GeneratorHelper method getTypeResolver.

static TypeResolver getTypeResolver(final InvokerStub stub, final ReteEvaluator reteEvaluator, final ClassLoader classLoader) {
    InternalKnowledgePackage pkg = reteEvaluator.getKnowledgeBase().getPackage(stub.getPackageName());
    TypeResolver typeResolver = pkg == null ? null : pkg.getTypeResolver();
    if (typeResolver == null) {
        Set<String> imports = new HashSet<String>();
        for (String imp : stub.getPackageImports()) {
            imports.add(imp);
        }
        typeResolver = new ClassTypeResolver(imports, classLoader, stub.getPackageName());
    }
    return typeResolver;
}
Also used : TypeResolver(org.drools.core.addon.TypeResolver) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) HashSet(java.util.HashSet)

Example 14 with ClassTypeResolver

use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.

the class ClassTypeResolverTest method testResolveArrayOfObjectsNotFromImport.

@Test
public void testResolveArrayOfObjectsNotFromImport() throws Exception {
    final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
    assertEquals(String[].class, resolver.resolveType("String[]"));
    assertEquals(String[].class, resolver.resolveType("java.lang.String[]"));
    try {
        assertEquals(Cheese[].class, resolver.resolveType("Cheese[]"));
        fail("Should raise a ClassNotFoundException");
    } catch (final ClassNotFoundException e) {
    // success
    }
    assertEquals(Cheese[].class, resolver.resolveType("org.drools.core.test.model.Cheese[]"));
}
Also used : Cheese(org.drools.core.test.model.Cheese) ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with ClassTypeResolver

use of org.drools.core.addon.ClassTypeResolver in project drools by kiegroup.

the class ClassTypeResolverTest method testResolveObjectNotFromImport.

@Test
public void testResolveObjectNotFromImport() throws Exception {
    final ClassTypeResolver resolver = new ClassTypeResolver(new HashSet(), Thread.currentThread().getContextClassLoader());
    assertEquals(String.class, resolver.resolveType("String"));
    assertEquals(String.class, resolver.resolveType("java.lang.String"));
    try {
        assertEquals(Cheese.class, resolver.resolveType("Cheese"));
        fail("Should raise a ClassNotFoundException");
    } catch (final ClassNotFoundException e) {
    // success
    }
    assertEquals(Cheese.class, resolver.resolveType("org.drools.core.test.model.Cheese"));
}
Also used : ClassTypeResolver(org.drools.core.addon.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ClassTypeResolver (org.drools.core.addon.ClassTypeResolver)24 HashSet (java.util.HashSet)22 Test (org.junit.Test)16 TypeResolver (org.drools.core.addon.TypeResolver)6 MvelCompilerContext (org.drools.mvelcompiler.context.MvelCompilerContext)3 Gender (org.drools.Gender)2 Person (org.drools.Person)2 Cheese (org.drools.core.test.model.Cheese)2 FirstClass (org.drools.core.test.model.FirstClass)2 PackageModel (org.drools.modelcompiler.builder.PackageModel)2 Before (org.junit.Before)2 Map (java.util.Map)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 RuleUnitDescriptionLoader (org.drools.core.ruleunit.RuleUnitDescriptionLoader)1 SecondClass (org.drools.core.test.model.SecondClass)1 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)1 ConstraintCompiler (org.drools.mvelcompiler.ConstraintCompiler)1 MvelCompiler (org.drools.mvelcompiler.MvelCompiler)1