Search in sources :

Example 1 with GET_CHANNEL_CALL

use of org.drools.modelcompiler.builder.generator.DslMethodNames.GET_CHANNEL_CALL in project drools by kiegroup.

the class Consequence method rewriteChannels.

private void rewriteChannels(BlockStmt consequence) {
    consequence.findAll(MethodCallExpr.class).stream().map(MethodCallExpr::getScope).filter(Optional::isPresent).map(Optional::get).filter(sc -> sc instanceof ArrayAccessExpr).map(aae -> (ArrayAccessExpr) aae).filter(aae -> aae.getName().asNameExpr().getNameAsString().equals("channels")).forEach(aae -> {
        String channelName = aae.getIndex().asStringLiteralExpr().asString();
        MethodCallExpr mce = new MethodCallExpr(new NameExpr("drools"), GET_CHANNEL_CALL);
        mce.addArgument("\"" + channelName + "\"");
        aae.replace(mce);
    });
}
Also used : ArrayAccessExpr(com.github.javaparser.ast.expr.ArrayAccessExpr) BREAKING_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BREAKING_CALL) DrlxParseUtil.isNameExprWithName(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isNameExprWithName) DroolsImpl(org.drools.modelcompiler.consequence.DroolsImpl) CompiledBlockResult(org.drools.mvelcompiler.CompiledBlockResult) NodeList.nodeList(com.github.javaparser.ast.NodeList.nodeList) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ClassUtils.getter2property(org.drools.core.util.ClassUtils.getter2property) ClassUtils.isReadableProperty(org.drools.core.util.ClassUtils.isReadableProperty) ClassUtils.isGetter(org.drools.core.util.ClassUtils.isGetter) ClassUtil.asJavaSourceName(org.drools.modelcompiler.util.ClassUtil.asJavaSourceName) Matcher(java.util.regex.Matcher) AllSetButLastBitMask(org.drools.model.bitmask.AllSetButLastBitMask) Type(com.github.javaparser.ast.type.Type) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) ClassUtils.isSetter(org.drools.core.util.ClassUtils.isSetter) ConsequenceRewriteException(org.drools.modelcompiler.builder.errors.ConsequenceRewriteException) Collectors.toSet(java.util.stream.Collectors.toSet) PackageModel(org.drools.modelcompiler.builder.PackageModel) NodeList(com.github.javaparser.ast.NodeList) SimpleName(com.github.javaparser.ast.expr.SimpleName) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) StaticJavaParser.parseExpression(com.github.javaparser.StaticJavaParser.parseExpression) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) Modifier(com.github.javaparser.ast.Modifier) VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) DrlxParseUtil.findAllChildrenRecursive(org.drools.modelcompiler.builder.generator.DrlxParseUtil.findAllChildrenRecursive) List(java.util.List) MvelCompilerException(org.drools.mvelcompiler.MvelCompilerException) TruthMaintenanceSystemFactory(org.drools.core.common.TruthMaintenanceSystemFactory) Optional(java.util.Optional) CompilationProblemErrorResult(org.drools.modelcompiler.builder.errors.CompilationProblemErrorResult) Pattern(java.util.regex.Pattern) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) DrlxParseUtil.toStringLiteral(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toStringLiteral) ON_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ON_CALL) EXECUTE_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.EXECUTE_CALL) StringUtils(org.drools.core.util.StringUtils) BitMask(org.drools.model.BitMask) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) DOMAIN_CLASS_METADATA_INSTANCE(org.drools.modelcompiler.builder.PackageModel.DOMAIN_CLASS_METADATA_INSTANCE) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Parameter(com.github.javaparser.ast.body.Parameter) DrlxParseUtil.addCurlyBracesToBlock(org.drools.modelcompiler.builder.generator.DrlxParseUtil.addCurlyBracesToBlock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CastExpr(com.github.javaparser.ast.expr.CastExpr) GET_CHANNEL_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.GET_CHANNEL_CALL) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) MvelCompilationError(org.drools.modelcompiler.builder.errors.MvelCompilationError) DslMethodNames.createDslTopLevelMethod(org.drools.modelcompiler.builder.generator.DslMethodNames.createDslTopLevelMethod) ModifyCompiler(org.drools.mvelcompiler.ModifyCompiler) DrlxParseUtil.parseBlock(org.drools.modelcompiler.builder.generator.DrlxParseUtil.parseBlock) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) ClassDefinition(org.drools.core.factmodel.ClassDefinition) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) NameExpr(com.github.javaparser.ast.expr.NameExpr) DOMAIN_CLASSESS_METADATA_FILE_NAME(org.drools.modelcompiler.builder.PackageModel.DOMAIN_CLASSESS_METADATA_FILE_NAME) ParseProblemException(com.github.javaparser.ParseProblemException) ClassUtils.setter2property(org.drools.core.util.ClassUtils.setter2property) Collections(java.util.Collections) MissingDependencyError(org.drools.compiler.compiler.MissingDependencyError) Optional(java.util.Optional) ArrayAccessExpr(com.github.javaparser.ast.expr.ArrayAccessExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

ParseProblemException (com.github.javaparser.ParseProblemException)1 StaticJavaParser.parseExpression (com.github.javaparser.StaticJavaParser.parseExpression)1 Modifier (com.github.javaparser.ast.Modifier)1 NodeList (com.github.javaparser.ast.NodeList)1 NodeList.nodeList (com.github.javaparser.ast.NodeList.nodeList)1 Parameter (com.github.javaparser.ast.body.Parameter)1 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)1 ArrayAccessExpr (com.github.javaparser.ast.expr.ArrayAccessExpr)1 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)1 CastExpr (com.github.javaparser.ast.expr.CastExpr)1 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)1 Expression (com.github.javaparser.ast.expr.Expression)1 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)1 LambdaExpr (com.github.javaparser.ast.expr.LambdaExpr)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 SimpleName (com.github.javaparser.ast.expr.SimpleName)1 VariableDeclarationExpr (com.github.javaparser.ast.expr.VariableDeclarationExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)1