@Test public void convertPatternLambda() throws Exception { CompilationUnit inputCU = parseResource("org/drools/modelcompiler/util/lambdareplace/PatternTestHarness.java"); CompilationUnit clone = inputCU.clone(); new ExecModelLambdaPostProcessor(new HashMap<>(), "mypackage", "rulename", new ArrayList<>(), new ArrayList<>(), new HashMap<>(), clone).convertLambdas(); String PATTERN_HARNESS = "PatternTestHarness"; MethodDeclaration expectedResult = getMethodChangingName(inputCU, PATTERN_HARNESS, "expectedOutput"); MethodDeclaration actual = getMethodChangingName(clone, PATTERN_HARNESS, "inputMethod"); assertThat(actual.toString(), equalToIgnoringWhiteSpace(expectedResult.toString())); }
public void convertLambdas() { clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString()) || FlowExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString())) .forEach(methodCallExpr1 -> { if (containsTemporalPredicate(methodCallExpr1)) { this.convertTemporalExpr(methodCallExpr1); } else { extractLambdaFromMethodCall(methodCallExpr1, () -> new MaterializedLambdaPredicate(packageName, ruleClassName)); } }); clone.findAll(MethodCallExpr.class, mc -> INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> ALPHA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> BETA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCall); clone.findAll(MethodCallExpr.class, mc -> FlowExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCallForFlowDSL); clone.findAll(MethodCallExpr.class, mc -> FROM_CALL.equals(mc.getNameAsString()) || REACTIVE_FROM_CALL.equals(mc.getNameAsString())) .forEach(this::convertFromCall); clone.findAll(MethodCallExpr.class, this::isExecuteNonNestedCall) .forEach(methodCallExpr -> { List<MaterializedLambda.BitMaskVariable> bitMaskVariables = findBitMaskFields(methodCallExpr); extractLambdaFromMethodCall(methodCallExpr, () -> new MaterializedLambdaConsequence(packageName, ruleClassName, bitMaskVariables)); }); }
ExecModelLambdaPostProcessor { public void convertLambdas() { clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString()) || FlowExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString())) .forEach(methodCallExpr1 -> { if (containsTemporalPredicate(methodCallExpr1)) { this.convertTemporalExpr(methodCallExpr1); } else { extractLambdaFromMethodCall(methodCallExpr1, () -> new MaterializedLambdaPredicate(packageName, ruleClassName)); } }); clone.findAll(MethodCallExpr.class, mc -> INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> ALPHA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> BETA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCall); clone.findAll(MethodCallExpr.class, mc -> FlowExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCallForFlowDSL); clone.findAll(MethodCallExpr.class, mc -> FROM_CALL.equals(mc.getNameAsString()) || REACTIVE_FROM_CALL.equals(mc.getNameAsString())) .forEach(this::convertFromCall); clone.findAll(MethodCallExpr.class, this::isExecuteNonNestedCall) .forEach(methodCallExpr -> { List<MaterializedLambda.BitMaskVariable> bitMaskVariables = findBitMaskFields(methodCallExpr); extractLambdaFromMethodCall(methodCallExpr, () -> new MaterializedLambdaConsequence(packageName, ruleClassName, bitMaskVariables)); }); } }
ExecModelLambdaPostProcessor { public void convertLambdas() { clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString()) || FlowExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString())) .forEach(methodCallExpr1 -> { if (containsTemporalPredicate(methodCallExpr1)) { this.convertTemporalExpr(methodCallExpr1); } else { extractLambdaFromMethodCall(methodCallExpr1, () -> new MaterializedLambdaPredicate(packageName, ruleClassName)); } }); clone.findAll(MethodCallExpr.class, mc -> INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> ALPHA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> BETA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCall); clone.findAll(MethodCallExpr.class, mc -> FlowExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCallForFlowDSL); clone.findAll(MethodCallExpr.class, mc -> FROM_CALL.equals(mc.getNameAsString()) || REACTIVE_FROM_CALL.equals(mc.getNameAsString())) .forEach(this::convertFromCall); clone.findAll(MethodCallExpr.class, this::isExecuteNonNestedCall) .forEach(methodCallExpr -> { List<MaterializedLambda.BitMaskVariable> bitMaskVariables = findBitMaskFields(methodCallExpr); extractLambdaFromMethodCall(methodCallExpr, () -> new MaterializedLambdaConsequence(packageName, ruleClassName, bitMaskVariables)); }); } ExecModelLambdaPostProcessor(PackageModel pkgModel,
                                        CompilationUnit clone);  ExecModelLambdaPostProcessor(Map<String, CreatedClass> lambdaClasses,
                                        String packageName,
                                        String ruleClassName,
                                        Collection<String> imports,
                                        Collection<String> staticImports,
                                        Map<LambdaExpr, java.lang.reflect.Type> lambdaReturnTypes,
                                        CompilationUnit clone); }
ExecModelLambdaPostProcessor { public void convertLambdas() { clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString()) || FlowExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString())) .forEach(methodCallExpr1 -> { if (containsTemporalPredicate(methodCallExpr1)) { this.convertTemporalExpr(methodCallExpr1); } else { extractLambdaFromMethodCall(methodCallExpr1, () -> new MaterializedLambdaPredicate(packageName, ruleClassName)); } }); clone.findAll(MethodCallExpr.class, mc -> INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> ALPHA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> BETA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCall); clone.findAll(MethodCallExpr.class, mc -> FlowExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCallForFlowDSL); clone.findAll(MethodCallExpr.class, mc -> FROM_CALL.equals(mc.getNameAsString()) || REACTIVE_FROM_CALL.equals(mc.getNameAsString())) .forEach(this::convertFromCall); clone.findAll(MethodCallExpr.class, this::isExecuteNonNestedCall) .forEach(methodCallExpr -> { List<MaterializedLambda.BitMaskVariable> bitMaskVariables = findBitMaskFields(methodCallExpr); extractLambdaFromMethodCall(methodCallExpr, () -> new MaterializedLambdaConsequence(packageName, ruleClassName, bitMaskVariables)); }); } ExecModelLambdaPostProcessor(PackageModel pkgModel,
                                        CompilationUnit clone);  ExecModelLambdaPostProcessor(Map<String, CreatedClass> lambdaClasses,
                                        String packageName,
                                        String ruleClassName,
                                        Collection<String> imports,
                                        Collection<String> staticImports,
                                        Map<LambdaExpr, java.lang.reflect.Type> lambdaReturnTypes,
                                        CompilationUnit clone); void convertLambdas(); }
ExecModelLambdaPostProcessor { public void convertLambdas() { clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString()) || FlowExpressionBuilder.EXPR_CALL.equals(mc.getNameAsString())) .forEach(methodCallExpr1 -> { if (containsTemporalPredicate(methodCallExpr1)) { this.convertTemporalExpr(methodCallExpr1); } else { extractLambdaFromMethodCall(methodCallExpr1, () -> new MaterializedLambdaPredicate(packageName, ruleClassName)); } }); clone.findAll(MethodCallExpr.class, mc -> INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> ALPHA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> BETA_INDEXED_BY_CALL.contains(mc.getName().asString())) .forEach(this::convertIndexedByCall); clone.findAll(MethodCallExpr.class, mc -> PatternExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCall); clone.findAll(MethodCallExpr.class, mc -> FlowExpressionBuilder.BIND_CALL.equals(mc.getNameAsString())) .forEach(this::convertBindCallForFlowDSL); clone.findAll(MethodCallExpr.class, mc -> FROM_CALL.equals(mc.getNameAsString()) || REACTIVE_FROM_CALL.equals(mc.getNameAsString())) .forEach(this::convertFromCall); clone.findAll(MethodCallExpr.class, this::isExecuteNonNestedCall) .forEach(methodCallExpr -> { List<MaterializedLambda.BitMaskVariable> bitMaskVariables = findBitMaskFields(methodCallExpr); extractLambdaFromMethodCall(methodCallExpr, () -> new MaterializedLambdaConsequence(packageName, ruleClassName, bitMaskVariables)); }); } ExecModelLambdaPostProcessor(PackageModel pkgModel,
                                        CompilationUnit clone);  ExecModelLambdaPostProcessor(Map<String, CreatedClass> lambdaClasses,
                                        String packageName,
                                        String ruleClassName,
                                        Collection<String> imports,
                                        Collection<String> staticImports,
                                        Map<LambdaExpr, java.lang.reflect.Type> lambdaReturnTypes,
                                        CompilationUnit clone); void convertLambdas(); static final PrettyPrinter MATERIALIZED_LAMBDA_PRETTY_PRINTER; }