Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Recipe nullability best practices #487

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaIsoVisitor;
Expand Down Expand Up @@ -134,7 +133,6 @@ actual, assertion, getArgumentsTemplate(matcherArgumentMethod)))

private final MethodMatcher CLOSE_TO_MATCHER = new MethodMatcher("org.hamcrest.Matchers closeTo(..)");

@NotNull
private String getArgumentsTemplate(J.MethodInvocation matcherArgument) {
List<Expression> methodArguments = matcherArgument.getArguments();
if (CLOSE_TO_MATCHER.matches(matcherArgument)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.List;
import java.util.stream.Collectors;

@SuppressWarnings("NullableProblems")
public class HamcrestOfMatchersToAssertJ extends Recipe {
@Override
public String getDisplayName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.openrewrite.java.search.UsesMethod;
import org.openrewrite.java.tree.J;

@SuppressWarnings("NullableProblems")
public class RemoveIsMatcher extends Recipe {
@Override
public String getDisplayName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
@NonNullFields
package org.openrewrite.java.testing.hamcrest;

import org.openrewrite.internal.lang.NonNullApi;
import org.openrewrite.internal.lang.NonNullFields;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.openrewrite.java.testing.junit5;

import org.jetbrains.annotations.NotNull;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Preconditions;
import org.openrewrite.Recipe;
Expand Down Expand Up @@ -116,7 +115,6 @@ private static boolean isException(Expression expression) {
return expression instanceof J.Identifier && TypeUtils.isAssignableTo("java.lang.Throwable", expression.getType());
}

@NotNull
private J.MethodInvocation replaceWithAssertDoesNotThrowWithoutStringExpression(ExecutionContext ctx, J.Try try_) {
maybeAddImport("org.junit.jupiter.api.Assertions");
maybeRemoveCatchTypes(try_);
Expand All @@ -139,7 +137,6 @@ private void maybeRemoveCatchTypes(J.Try try_) {
}
}

@NotNull
private J.MethodInvocation replaceWithAssertDoesNotThrowWithStringExpression(ExecutionContext ctx, J.Try try_, Expression failCallArgument) {
// Retain the fail(String) call argument
maybeAddImport("org.junit.jupiter.api.Assertions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.openrewrite.java.testing.testcontainers;

import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.openrewrite.*;
import org.openrewrite.java.JavaIsoVisitor;
import org.openrewrite.java.JavaParser;
Expand Down Expand Up @@ -75,7 +74,6 @@ public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
return nc;
}

@NotNull
private Expression getConstructorArgument(J.NewClass newClass) {
if (parseImage != null && parseImage) {
maybeAddImport("org.testcontainers.utility.DockerImageName");
Expand Down