use of org.drools.mvelcompiler.context.MvelCompilerContext in project drools by kiegroup.
the class DrlxParseUtil method createConstraintCompiler.
public static ConstraintCompiler createConstraintCompiler(RuleContext context, Optional<Class<?>> originalPatternType) {
MvelCompilerContext mvelCompilerContext = new MvelCompilerContext(context.getTypeResolver(), context.getCurrentScopeSuffix());
List<DeclarationSpec> allDeclarations = new ArrayList<>(context.getAllDeclarations());
originalPatternType.ifPresent(pt -> {
allDeclarations.add(new DeclarationSpec(THIS_PLACEHOLDER, pt));
mvelCompilerContext.setRootPatternPrefix(pt, THIS_PLACEHOLDER);
});
for (Map.Entry<String, Method> m : context.getPackageModel().getStaticMethods().entrySet()) {
mvelCompilerContext.addStaticMethod(m.getKey(), m.getValue());
}
for (DeclarationSpec ds : allDeclarations) {
mvelCompilerContext.addDeclaration(ds.getBindingId(), ds.getDeclarationClass());
}
return new ConstraintCompiler(mvelCompilerContext);
}
use of org.drools.mvelcompiler.context.MvelCompilerContext in project drools by kiegroup.
the class DrlxParseUtil method createMvelCompiler.
public static MvelCompiler createMvelCompiler(RuleContext context) {
MvelCompilerContext mvelCompilerContext = new MvelCompilerContext(context.getTypeResolver(), context.getCurrentScopeSuffix());
for (DeclarationSpec ds : context.getAllDeclarations()) {
mvelCompilerContext.addDeclaration(ds.getBindingId(), ds.getDeclarationClass());
}
for (Map.Entry<String, Method> m : context.getPackageModel().getStaticMethods().entrySet()) {
mvelCompilerContext.addStaticMethod(m.getKey(), m.getValue());
}
for (MethodDeclaration m : context.getPackageModel().getFunctions()) {
List<String> parametersType = m.getParameters().stream().map(Parameter::getType).map(Type::asString).collect(toList());
mvelCompilerContext.addDeclaredFunction(m.getNameAsString(), m.getTypeAsString(), parametersType);
}
return new MvelCompiler(mvelCompilerContext);
}
Aggregations