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;
}
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());
}
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()));
}
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);
}
}
}
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() );
}
Aggregations