Skip to content

Commit 399931b

Browse files
refactor: Move @Nullable method annotations to the return type
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.NullableOnMethodReturnType?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne <[email protected]>
1 parent 3eb8e87 commit 399931b

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
137137
return anno;
138138
}
139139

140-
@Nullable
141-
private String getLiteralAnnotationArgumentValue(J.Annotation anno) {
140+
private @Nullable String getLiteralAnnotationArgumentValue(J.Annotation anno) {
142141
String annotationArgumentValue = null;
143142
if (anno.getArguments() != null && anno.getArguments().size() == 1 && anno.getArguments().get(0) instanceof J.Literal) {
144143
J.Literal literal = (J.Literal) anno.getArguments().get(0);
@@ -147,8 +146,7 @@ private String getLiteralAnnotationArgumentValue(J.Annotation anno) {
147146
return annotationArgumentValue;
148147
}
149148

150-
@Nullable
151-
private String getAnnotationArgumentForInitMethod(J.Annotation anno, String... variableNames) {
149+
private @Nullable String getAnnotationArgumentForInitMethod(J.Annotation anno, String... variableNames) {
152150
String value = null;
153151
if (anno.getArguments() != null && anno.getArguments().size() == 1
154152
&& anno.getArguments().get(0) instanceof J.Assignment
@@ -292,8 +290,7 @@ private J.Annotation maybeReplaceParametersAnnotation(Cursor anno, String method
292290
return anno.getValue();
293291
}
294292

295-
@Nullable
296-
private String getAnnotationArgumentValueForMethodTemplate(J.Annotation anno) {
293+
private @Nullable String getAnnotationArgumentValueForMethodTemplate(J.Annotation anno) {
297294
String annotationArgumentValue = null;
298295
if (anno.getArguments() != null && anno.getArguments().size() == 1) {
299296
Expression annoArg = anno.getArguments().get(0);

src/main/java/org/openrewrite/java/testing/mockito/PowerMockitoMockStaticToMockito.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ private static boolean isFieldAlreadyDefined(J.Block classBody, String fieldName
210210
return false;
211211
}
212212

213-
@Nullable
214-
private static J.MethodDeclaration getFirstTestMethod(List<J.MethodDeclaration> methods) {
213+
private static @Nullable J.MethodDeclaration getFirstTestMethod(List<J.MethodDeclaration> methods) {
215214
for (J.MethodDeclaration methodDeclaration : methods) {
216215
for (J.Annotation annotation : methodDeclaration.getLeadingAnnotations()) {
217216
if ("Test".equals(annotation.getSimpleName())) {
@@ -559,8 +558,7 @@ private J.MethodInvocation modifyWhenMethodInvocation(J.MethodInvocation whenMet
559558
return whenMethod;
560559
}
561560

562-
@Nullable
563-
private String getDeclaringClassName(J.MethodInvocation mi) {
561+
private @Nullable String getDeclaringClassName(J.MethodInvocation mi) {
564562
JavaType.Method methodType = mi.getMethodType();
565563
if (methodType != null) {
566564
JavaType.FullyQualified declaringType = methodType.getDeclaringType();
@@ -569,8 +567,7 @@ private String getDeclaringClassName(J.MethodInvocation mi) {
569567
return null;
570568
}
571569

572-
@Nullable
573-
private J.Identifier getFieldIdentifier(String fieldName) {
570+
private @Nullable J.Identifier getFieldIdentifier(String fieldName) {
574571
return getMockedTypesFields().keySet().stream()
575572
.filter(identifier -> identifier.getSimpleName().equals(fieldName)).findFirst()
576573
.orElseGet(() -> {

0 commit comments

Comments
 (0)