in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/customRecipes/MoveGetterToExtendedCamelContext.java [64:95]
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);
// extendedContext.getModelJAXBContextFactory() -> PluginHelper.getModelJAXBContextFactory(extendedContext)
if (getMethodMatcher(getOldMethodMatcher()).matches(mi, false)) {
mi = JavaTemplate.builder(getNewMethodFromExternalContextContext())
//.contextSensitive()
.build()
.apply(getCursor(), mi.getCoordinates().replace(), mi.getSelect());
mi = mi.withArguments(method.getArguments());
}
return mi;
}
private String getOldMethodMatcher() {
return "org.apache.camel.impl.engine.AbstractCamelContext " + oldMethodName + "(..)";
}
private String getNewMethodFromContext() {
return "PluginHelper." + oldMethodName + "(#{any(org.apache.camel.CamelContext)})";
}
private String getNewMethodFromExternalContextContext() {
return "#{any(org.apache.camel.CamelContext)}.getCamelContextExtension()." + oldMethodName + "()";
}
});
}