Код: Выделить всё
@Override
public J.MethodInvocation visitMethodInvocation(final J.MethodInvocation method, final ExecutionContext ctx) {
if (method.getSimpleName().equals("permitAll") && isExpressionUrlAuthorizationConfigurer(method.getSelect())) {
final JavaTemplate template = JavaTemplate.builder(
"permitAll().and().anonymous(Customizer.withDefaults()).httpBasic(AbstractHttpConfigurer::disable)")
.imports(
"org.springframework.security.config.Customizer",
"org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer")
.build();
return template.apply(getCursor(), method.getCoordinates().replaceMethod());
}
return super.visitMethodInvocation(method, ctx);
}
Код: Выделить всё
java.lang.IllegalStateException: Expected to find enclosing SourceFile
at org.openrewrite.Cursor.firstEnclosingOrThrow (Cursor.java:178)
at org.openrewrite.Tree.printer (Tree.java:73)
at org.openrewrite.Tree.print(Tree.java:81)
at org.openrewrite.Tree.print(Tree.java:77)
at org.openrewrite.java.internal.template.JavaTemplateParser.parseMethod (JavaTemplateParser.java:187)
Вопросы:
- Что я делаю неправильно при настройке или применении JavaTemplate ?
- Может ли это быть ошибка (например, в org.openrewrite.java.JavaTemplate) или в том, как создается J.MethodInvoction (то же самое происходит в модульном тесте и при применении «по-настоящему» — с указанием этого метода нет исходного файла).
Подробнее здесь: https://stackoverflow.com/questions/793 ... nvocations