|
21 | 21 | import org.openrewrite.java.JavaIsoVisitor;
|
22 | 22 | import org.openrewrite.java.JavaVisitor;
|
23 | 23 | import org.openrewrite.java.MethodMatcher;
|
| 24 | +import org.openrewrite.java.tree.Expression; |
24 | 25 | import org.openrewrite.java.tree.J;
|
25 | 26 | import org.openrewrite.java.tree.J.MethodDeclaration;
|
26 | 27 | import org.openrewrite.java.tree.J.MethodInvocation;
|
@@ -161,12 +162,15 @@ protected TreeVisitor<?, ExecutionContext> getVisitor() {
|
161 | 162 | @Override
|
162 | 163 | public Return visitReturn(Return _return, ExecutionContext p) {
|
163 | 164 | Return r = super.visitReturn(_return, p);
|
164 |
| - MarkReturnType marker = r.getExpression().getMarkers().findFirst(MarkReturnType.class).orElse(null); |
165 |
| - if (marker != null) { |
166 |
| - removeMarker(r.getExpression(), marker); |
167 |
| - MethodDeclaration method = getCursor().firstEnclosing(MethodDeclaration.class); |
168 |
| - if (method != null) { |
169 |
| - doAfterVisit(new ChangeMethodReturnTypeRecipe(m -> m.getId().equals(method.getId()), marker.getExpression(), marker.getImports())); |
| 165 | + Expression expression = r.getExpression(); |
| 166 | + if (expression != null) { |
| 167 | + MarkReturnType marker = expression.getMarkers().findFirst(MarkReturnType.class).orElse(null); |
| 168 | + if (marker != null) { |
| 169 | + removeMarker(expression, marker); |
| 170 | + MethodDeclaration method = getCursor().firstEnclosing(MethodDeclaration.class); |
| 171 | + if (method != null) { |
| 172 | + doAfterVisit(new ChangeMethodReturnTypeRecipe(m -> m.getId().equals(method.getId()), marker.getExpression(), marker.getImports())); |
| 173 | + } |
170 | 174 | }
|
171 | 175 | }
|
172 | 176 | return r;
|
|
0 commit comments