public TreeVisitor getVisitor()

in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/customRecipes/LiteralRegexpConverterRecipe.java [65:96]


    public TreeVisitor<?, ExecutionContext> getVisitor() {
        return RecipesUtil.newVisitor(new AbstractCamelJavaVisitor() {

            @Override
            protected J.Literal doVisitLiteral(J.Literal literal, ExecutionContext context) {
                J.Literal l  =  super.doVisitLiteral(literal, context);

                // Only handle String literals
                if (TypeUtils.isString(literal.getType()) && literal.getValue() != null) {
                    Matcher m = getPattern(regexp.trim()).matcher((String)literal.getValue());
                    if(m.matches()) {
                        //if no group one group is used
                        String tmp = replacement;
                        for (int i = 1; i <= 100; i++) {
                            if(!tmp.contains("${" + i + "}")) {
                                break;
                            }
                            String tmp2 = tmp.replaceAll("\\$\\{" + i + "}", m.group(i));
                            //if there is no change, return value
                            if(tmp.equals(tmp2)) {
                                break;
                            }
                            tmp = tmp2;
                        }
                        return RecipesUtil.createStringLiteral(tmp);
                    }
                }

                return l;
            }
        });
    }