in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/camel47/Java47Recipes.java [66:99]
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);
//get all mi starts with Exchange.getIn()
if (mi.getSelect() instanceof J.MethodInvocation
&& getMethodMatcher(MATCHER_GET_IN).matches((J.MethodInvocation) mi.getSelect(), false)) {
//apply map of transformations
Optional<J.MethodInvocation> result = HEADERS_MAP.stream()
.filter(triplet ->
getMethodMatcher(triplet.a).matches(mi) && mi.toString().contains(triplet.b))
//rename tag
.map(triplet -> (J.MethodInvocation)JavaTemplate.builder(triplet.c)
.build().apply(getCursor(), mi.getCoordinates().replace(), ((J.MethodInvocation)mi.getSelect()).getSelect())
.withPrefix(mi.getPrefix()))
.findAny();
if(result.isPresent()) {
doAfterVisit(new AddImport<>("org.apache.camel.http.common.HttpMessage", null, false));
return result.get();
}
}
return mi;
}
});
}