in camel-upgrade-recipes/src/main/java/org/apache/camel/upgrade/customRecipes/MoveGetterToPluginHelper.java [65: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);
// extendedContext.getModelJAXBContextFactory() -> PluginHelper.getModelJAXBContextFactory(extendedContext)
if (getMethodMatcher(getOldMethodMatcher()).matches(mi, false)) {
if (mi.getSelect() instanceof J.MethodInvocation && getMethodMatcher(MATCHER_CONTEXT_GET_EXT)
.matches(((J.MethodInvocation) mi.getSelect()).getMethodType())) {
J.MethodInvocation innerInvocation = (J.MethodInvocation) mi.getSelect();
mi = JavaTemplate.builder(getNewMethodFromContext())
//.contextSensitive()
.build()
.apply(getCursor(), mi.getCoordinates().replace(), innerInvocation.getSelect());
doAfterVisit(new AddImport<>("org.apache.camel.support.PluginHelper", null, false));
} else if (mi.getSelect().getType().isAssignableFrom(EXTERNAL_CONTEXT_TYPE)) {
mi = JavaTemplate.builder(getNewMethodFromExternalContextContext())
//.contextSensitive()
.build()
.apply(getCursor(), mi.getCoordinates().replace(), mi.getSelect());
doAfterVisit(new AddImport<>("org.apache.camel.support.PluginHelper", null, false));
}
}
return mi;
}
private String getOldMethodMatcher() {
return "org.apache.camel.ExtendedCamelContext " + oldMethodName + "()";
}
private String getNewMethodFromContext() {
return "PluginHelper." + oldMethodName + "(#{any(org.apache.camel.CamelContext)})";
}
private String getNewMethodFromExternalContextContext() {
return "PluginHelper." + oldMethodName + "(#{any(org.apache.camel.ExtendedCamelContext)})";
}
});
}