Skip to content

Commit

Permalink
Fix a few type validation errors
Browse files Browse the repository at this point in the history
Also fix a bug in `RenameBean` recipe.
  • Loading branch information
knutwannheden committed Sep 27, 2023
1 parent 23e0c1b commit 8453293
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/java/spring/RenameBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static BeanSearchResult isBean(Collection<J.Annotation> annotations, Set

private static boolean anyAnnotationMatches(J.Annotation type, Set<String> types) {
for (String it : types) {
if (!FindAnnotations.find(type, it, true).isEmpty()) {
if (!FindAnnotations.find(type, '@' + it, true).isEmpty()) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NoAutowiredOnConstructorTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new NoAutowiredOnConstructor())
.parser(JavaParser.fromJavaVersion().classpath("spring-beans"));
.parser(JavaParser.fromJavaVersion().classpath("spring-beans", "spring-context", "spring-core"));
}

@Issue("https://github.com/openrewrite/rewrite-spring/issues/78")
Expand Down Expand Up @@ -524,11 +524,12 @@ void noAutowiredAnnotations() {
rewriteRun(
java(
"""
import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
public class DatabaseConfiguration {
private final DataSource dataSource;
@Primary
public DatabaseConfiguration(DataSource dataSource) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public void defaults(RecipeSpec spec) {
void conditionalAnnotationSingleClassCandidateNoChange() {
//language=java
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.builder()
.methodDeclarations(false)
.constructorInvocations(false)
.identifiers(false)
.build()),
java(
"""
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void requestMappingWithMultipleMethods() {
import java.util.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import static org.openrewrite.java.Assertions.java;

Expand All @@ -34,6 +35,7 @@ public void defaults(RecipeSpec spec) {
void dontUseUnavailableMethods() {
//language=java
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
java(
"""
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
Expand Down

0 comments on commit 8453293

Please sign in to comment.