in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel40/java/CamelBeanRecipe.java [51:105]
public TreeVisitor<?, ExecutionContext> getVisitor() {
return RecipesUtil.newVisitor(new AbstractCamelJavaVisitor() {
@Override
protected J.MethodInvocation doVisitMethodInvocation(J.MethodInvocation method, ExecutionContext context) {
J.MethodInvocation mi = super.doVisitMethodInvocation(method, context);
Pattern findMethodPattern = Pattern.compile("method=.*");
if (mi.getSimpleName().equals("to")) {
List<Expression> arguments = method.getArguments();
for (int i = 0; i < arguments.size(); i++) {
Expression argument = arguments.get(i);
if (argument instanceof J.Literal
&& ((J.Literal) argument).getType().getClassName().equals("java.lang.String")
&& findMethodPattern
.matcher((String) (((J.Literal) method.getArguments().get(i)).getValue()))
.find()) {
String uriWithMethod = (String) (((J.Literal) method.getArguments().get(i)).getValue());
String uriWithoutMethod = uriWithMethod.split("=")[0];
String methodNameAndArgs = uriWithMethod.split("=")[1];
//method without any args, we can simply return the mi in that case.
if (!methodNameAndArgs.contains("(") && !methodNameAndArgs.contains(")")) {
return mi;
}
String methodName = extractMethodName(methodNameAndArgs);
String actualArgs = methodNameAndArgs.substring(
methodNameAndArgs.indexOf("(") + 1,
methodNameAndArgs.indexOf(")"));
String updatedArg = uriWithoutMethod + "=" + methodName + "(" + updateMethodArgument(actualArgs)
+ ")";
doAfterVisit(new ChangeLiteral<>(argument, p -> updatedArg));
return mi;
}
}
}
return mi;
}
});
}