use of org.drools.core.addon.TypeResolver in project drools by kiegroup.
the class ModelGenerator method generateModel.
public static void generateModel(KnowledgeBuilderImpl kbuilder, InternalKnowledgePackage pkg, PackageDescr packageDescr, PackageModel packageModel) {
TypeResolver typeResolver = pkg.getTypeResolver();
List<RuleDescr> ruleDescrs = packageDescr.getRules();
if (ruleDescrs.isEmpty()) {
return;
}
for (RuleDescr descr : ruleDescrs) {
RuleContext context = new RuleContext(kbuilder, packageModel, typeResolver, descr);
context.setDialectFromAttributes(packageDescr.getAttributes());
if (descr instanceof QueryDescr) {
QueryGenerator.processQueryDef(packageModel, context);
}
}
int parallelRulesBuildThreshold = kbuilder.getBuilderConfiguration().getParallelRulesBuildThreshold();
boolean parallelRulesBuild = parallelRulesBuildThreshold != -1 && ruleDescrs.size() > parallelRulesBuildThreshold;
if (parallelRulesBuild) {
List<RuleContext> ruleContexts = new ArrayList<>();
int i = 0;
for (RuleDescr ruleDescr : packageDescr.getRules()) {
ruleContexts.add(new RuleContext(kbuilder, packageModel, typeResolver, ruleDescr, i++));
}
KnowledgeBuilderImpl.ForkJoinPoolHolder.COMPILER_POOL.submit(() -> ruleContexts.parallelStream().forEach(context -> processRuleDescr(context, packageDescr))).join();
} else {
int i = 0;
for (RuleDescr ruleDescr : packageDescr.getRules()) {
processRuleDescr(new RuleContext(kbuilder, packageModel, typeResolver, ruleDescr, i++), packageDescr);
}
}
}
use of org.drools.core.addon.TypeResolver in project drools by kiegroup.
the class POJOGenerator method findPOJOorGenerate.
public void findPOJOorGenerate() {
TypeResolver typeResolver = pkg.getTypeResolver();
Set<String> generatedPojos = new HashSet<>();
for (TypeDeclarationDescr typeDescr : packageDescr.getTypeDeclarations()) {
if (!generatedPojos.add(typeDescr.getFullTypeName())) {
builder.addBuilderResult(new DuplicatedDeclarationError(typeDescr.getFullTypeName()));
continue;
}
try {
Class<?> type = typeResolver.resolveType(typeDescr.getFullTypeName());
checkRedeclarationCompatibility(type, typeDescr);
processTypeMetadata(type, typeDescr.getAnnotations());
} catch (ClassNotFoundException e) {
createPOJO(typeDescr);
}
}
for (EnumDeclarationDescr enumDescr : packageDescr.getEnumDeclarations()) {
try {
Class<?> type = typeResolver.resolveType(enumDescr.getFullTypeName());
processTypeMetadata(type, enumDescr.getAnnotations());
} catch (ClassNotFoundException e) {
TypeDeclaration generatedEnum = new EnumGenerator().generate(enumDescr);
packageModel.addGeneratedPOJO(generatedEnum);
addTypeMetadata(enumDescr.getTypeName());
}
}
}
use of org.drools.core.addon.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);
}
}
use of org.drools.core.addon.TypeResolver 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);
}
use of org.drools.core.addon.TypeResolver 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;
}
Aggregations