Search in sources :

Example 26 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver 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"));
}
Also used : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.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.kie.soup.project.datamodel.commons.types.ClassTypeResolver) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with ClassTypeResolver

use of org.kie.soup.project.datamodel.commons.types.ClassTypeResolver in project drools by kiegroup.

the class GeneratorHelper method getTypeResolver.

static TypeResolver getTypeResolver(final InvokerStub stub, final WorkingMemory workingMemory, final ClassLoader classLoader) {
    InternalKnowledgePackage pkg = workingMemory.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 : ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) HashSet(java.util.HashSet)

Aggregations

ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)28 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)9 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)3 KieSession (org.kie.api.runtime.KieSession)3 HashMap (java.util.HashMap)2 Cheese (org.drools.core.test.model.Cheese)2 FirstClass (org.drools.core.test.model.FirstClass)2 Mouse (org.drools.workbench.models.testscenarios.backend.Mouse)2 FactData (org.drools.workbench.models.testscenarios.shared.FactData)2 Before (org.junit.Before)2 Date (java.util.Date)1 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)1 InternalAgendaGroup (org.drools.core.common.InternalAgendaGroup)1 ProjectClassLoader (org.drools.core.common.ProjectClassLoader)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1