Search in sources :

Example 21 with TypeResolver

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

the class ModelGenerator method generateModel.

public static void generateModel(KnowledgeBuilderImpl kbuilder, InternalKnowledgePackage pkg, PackageDescr packageDescr, PackageModel packageModel, boolean isPattern) {
    TypeResolver typeResolver = pkg.getTypeResolver();
    packageModel.addImports(pkg.getTypeResolver().getImports());
    packageModel.addGlobals(pkg.getGlobals());
    packageModel.addAccumulateFunctions(pkg.getAccumulateFunctions());
    packageModel.setInternalKnowledgePackage(pkg);
    new WindowReferenceGenerator(packageModel, typeResolver).addWindowReferences(kbuilder, packageDescr.getWindowDeclarations());
    packageModel.addAllFunctions(packageDescr.getFunctions().stream().map(FunctionGenerator::toFunction).collect(toList()));
    for (RuleDescr descr : packageDescr.getRules()) {
        if (descr instanceof QueryDescr) {
            QueryGenerator.processQueryDef(kbuilder, typeResolver, packageModel, (QueryDescr) descr, isPattern);
        }
    }
    for (RuleDescr descr : packageDescr.getRules()) {
        if (descr instanceof QueryDescr) {
            QueryGenerator.processQuery(kbuilder, packageModel, (QueryDescr) descr);
        } else {
            processRule(kbuilder, typeResolver, packageModel, packageDescr, descr, isPattern);
        }
    }
}
Also used : QueryDescr(org.drools.compiler.lang.descr.QueryDescr) TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) RuleDescr(org.drools.compiler.lang.descr.RuleDescr)

Example 22 with TypeResolver

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

the class TypeDeclarationNameResolver method resolveTypes.

public void resolveTypes(Collection<? extends PackageDescr> packageDescrs, List<TypeDefinition> unresolvedTypes) {
    for (PackageDescr packageDescr : packageDescrs) {
        TypeResolver typeResolver = kbuilder.getPackageRegistry(packageDescr.getName()).getTypeResolver();
        ensureQualifiedDeclarationName(unresolvedTypes, packageDescr, typeResolver);
    }
    for (PackageDescr packageDescr : packageDescrs) {
        TypeResolver typeResolver = kbuilder.getPackageRegistry(packageDescr.getName()).getTypeResolver();
        qualifyNames(unresolvedTypes, packageDescr, typeResolver);
    }
}
Also used : TypeResolver(org.kie.soup.project.datamodel.commons.types.TypeResolver) PackageDescr(org.drools.compiler.lang.descr.PackageDescr)

Example 23 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.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"));
}
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 24 with TypeResolver

use of org.kie.soup.project.datamodel.commons.types.TypeResolver 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

TypeResolver (org.kie.soup.project.datamodel.commons.types.TypeResolver)24 Test (org.junit.Test)16 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)14 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)8 Cheese (org.drools.workbench.models.testscenarios.backend.Cheese)7 FactData (org.drools.workbench.models.testscenarios.shared.FactData)7 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)7 HashMap (java.util.HashMap)6 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 CollectionFieldData (org.drools.workbench.models.testscenarios.shared.CollectionFieldData)5 Field (org.drools.workbench.models.testscenarios.shared.Field)4 HashSet (java.util.HashSet)3 FactAssignmentField (org.drools.workbench.models.testscenarios.shared.FactAssignmentField)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)2 Cheesery (org.drools.workbench.models.testscenarios.backend.Cheesery)2 Mouse (org.drools.workbench.models.testscenarios.backend.Mouse)2 OuterFact (org.drools.workbench.models.testscenarios.backend.OuterFact)2 KieSession (org.kie.api.runtime.KieSession)2