Search in sources :

Example 6 with Dialect

use of org.drools.compiler.compiler.Dialect in project drools by kiegroup.

the class KnowledgeBuilderConfigurationImpl method buildDialectRegistry.

public DialectCompiletimeRegistry buildDialectRegistry(ClassLoader rootClassLoader, KnowledgeBuilderConfigurationImpl pkgConf, PackageRegistry pkgRegistry, InternalKnowledgePackage pkg) {
    DialectCompiletimeRegistry registry = new DialectCompiletimeRegistry();
    for (DialectConfiguration conf : this.dialectConfigurations.values()) {
        Dialect dialect = conf.newDialect(rootClassLoader, pkgConf, pkgRegistry, pkg);
        registry.addDialect(dialect.getId(), dialect);
    }
    return registry;
}
Also used : DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) DialectConfiguration(org.drools.compiler.compiler.DialectConfiguration) Dialect(org.drools.compiler.compiler.Dialect)

Example 7 with Dialect

use of org.drools.compiler.compiler.Dialect in project drools by kiegroup.

the class KnowledgeBuilderImpl method preCompileAddFunction.

private void preCompileAddFunction(final FunctionDescr functionDescr, PackageRegistry pkgRegistry) {
    Dialect dialect = pkgRegistry.getDialectCompiletimeRegistry().getDialect(functionDescr.getDialect());
    dialect.preCompileAddFunction(functionDescr, pkgRegistry.getTypeResolver());
}
Also used : Dialect(org.drools.compiler.compiler.Dialect)

Example 8 with Dialect

use of org.drools.compiler.compiler.Dialect in project drools by kiegroup.

the class TypeDeclarationConfigurator method getMvelAnalysisResult.

private static AnalysisResult getMvelAnalysisResult(KnowledgeBuilderImpl kbuilder, BaseDescr typeDescr, TypeDeclaration type, PackageRegistry pkgRegistry, String durationField, InternalKnowledgePackage pkg) {
    Dialect dialect = pkgRegistry.getDialectCompiletimeRegistry().getDialect("mvel");
    PackageBuildContext context = new PackageBuildContext();
    context.init(kbuilder, pkg, typeDescr, pkgRegistry.getDialectCompiletimeRegistry(), dialect, null);
    if (!type.isTypesafe()) {
        context.setTypesafe(false);
    }
    return context.getDialect().analyzeExpression(context, typeDescr, durationField, new BoundIdentifiers(type.getTypeClass()));
}
Also used : PackageBuildContext(org.drools.compiler.rule.builder.PackageBuildContext) Dialect(org.drools.compiler.compiler.Dialect) BoundIdentifiers(org.drools.compiler.compiler.BoundIdentifiers)

Example 9 with Dialect

use of org.drools.compiler.compiler.Dialect in project drools by kiegroup.

the class KnowledgeBuilderImpl method postCompileAddFunction.

private void postCompileAddFunction(final FunctionDescr functionDescr, PackageRegistry pkgRegistry) {
    Dialect dialect = pkgRegistry.getDialectCompiletimeRegistry().getDialect(functionDescr.getDialect());
    dialect.postCompileAddFunction(functionDescr, pkgRegistry.getTypeResolver());
    if (rootClassLoader instanceof ProjectClassLoader) {
        String functionClassName = functionDescr.getClassName();
        JavaDialectRuntimeData runtime = ((JavaDialectRuntimeData) pkgRegistry.getDialectRuntimeRegistry().getDialectData("java"));
        try {
            registerFunctionClassAndInnerClasses(functionClassName, runtime, ((ProjectClassLoader) rootClassLoader)::storeClass);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ProjectClassLoader(org.drools.wiring.api.classloader.ProjectClassLoader) Dialect(org.drools.compiler.compiler.Dialect) JavaDialectRuntimeData(org.drools.core.rule.JavaDialectRuntimeData)

Example 10 with Dialect

use of org.drools.compiler.compiler.Dialect in project drools by kiegroup.

the class JavaAccumulateBuilderTest method testBuildRuleBuildContextBaseDescr.

@Test
public void testBuildRuleBuildContextBaseDescr() {
    // $total : Integer() from accumulate( Cheese( $price : price ) init( int x = 0; ) action( x += $price ) result( new Integer( x ) ) )
    AccumulateDescr accumDescr = new AccumulateDescr();
    BindingDescr price = new BindingDescr("$price", "price");
    PatternDescr cheeseDescr = new PatternDescr("org.drools.compiler.Cheese");
    cheeseDescr.addConstraint(price);
    accumDescr.setInputPattern(cheeseDescr);
    accumDescr.setInitCode("int x = 0; int y = 0;");
    accumDescr.setActionCode("x += $price;");
    accumDescr.setResultCode("new Integer( x )");
    // org.drools.core.rule.Package pkg = new org.kie.rule.Package( "org.kie" );
    final KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl();
    pkgBuilder.addPackage(new PackageDescr("org.drools"));
    final KnowledgeBuilderConfigurationImpl conf = pkgBuilder.getBuilderConfiguration();
    PackageRegistry pkgReg = pkgBuilder.getPackageRegistry("org.drools");
    InternalKnowledgePackage pkg = pkgReg.getPackage();
    DialectCompiletimeRegistry dialectRegistry = pkgReg.getDialectCompiletimeRegistry();
    Dialect dialect = dialectRegistry.getDialect("java");
    RuleDescr ruleDescr = new RuleDescr("test rule");
    RuleBuildContext context = new RuleBuildContext(pkgBuilder, ruleDescr, dialectRegistry, pkg, dialect);
    Accumulate accumulate = (Accumulate) builder.build(context, accumDescr);
    String generatedCode = (String) context.getMethods().get(0);
    assertTrue(generatedCode.contains("private int x;"));
    assertTrue(generatedCode.contains("private int y;"));
    assertTrue(generatedCode.contains("x = 0;y = 0;"));
// System.out.println( context.getInvokers() );
// System.out.println( context.getMethods() );
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleBuildContext(org.drools.compiler.rule.builder.RuleBuildContext) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr) Accumulate(org.drools.core.rule.Accumulate) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Dialect(org.drools.compiler.compiler.Dialect) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Aggregations

Dialect (org.drools.compiler.compiler.Dialect)17 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)8 Test (org.junit.Test)6 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)5 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)4 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)4 PackageDescr (org.drools.drl.ast.descr.PackageDescr)4 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)3 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)3 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)3 MVELDialect (org.drools.mvel.builder.MVELDialect)3 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Field (java.lang.reflect.Field)2 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)2 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)2 Accumulate (org.drools.core.rule.Accumulate)2