Skip to content

Commit

Permalink
Apply formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Oct 28, 2024
1 parent 2ab940d commit a431e71
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDeclarat
}

@Override
public J.@Nullable MethodDeclaration visitMethodDeclaration(J.MethodDeclaration md, ExecutionContext ctx) {
public J.@Nullable MethodDeclaration visitMethodDeclaration(J.MethodDeclaration md, ExecutionContext ctx) {
// Add JobRepository parameter to method if StepBuilderFactory.get(..) is used further down
if (!FindMethods.find(md, STEP_BUILDER_FACTORY_GET).isEmpty()) {
List<Object> params = md.getParameters().stream()
Expand Down Expand Up @@ -120,13 +120,13 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDeclarat
private boolean isJobRepositoryParameter(Statement statement) {
return statement instanceof J.VariableDeclarations &&
TypeUtils.isOfClassType(((J.VariableDeclarations) statement).getType(),
"org.springframework.batch.core.repository.JobRepository");
"org.springframework.batch.core.repository.JobRepository");
}

private boolean isJobBuilderFactoryParameter(Statement statement) {
return statement instanceof J.VariableDeclarations &&
TypeUtils.isOfClassType(((J.VariableDeclarations) statement).getType(),
"org.springframework.batch.core.configuration.annotation.StepBuilderFactory");
"org.springframework.batch.core.configuration.annotation.StepBuilderFactory");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
}

@Override
public J.@Nullable MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
public J.@Nullable MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
J.MethodDeclaration md = super.visitMethodDeclaration(method, ctx);
if (overridesDefaultBatchConfigurerMethod(md) || callsDefaultBatchConfigurerSuperConstructor(md)) {
// Strip @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getDisplayName() {
@Override
public String getDescription() {
return "As of spring-batch 5.x Listeners has default methods (made possible by a Java 8 baseline) and can be " +
"implemented directly without the need for this adapter.";
"implemented directly without the need for this adapter.";
}

@Option(displayName = "Fully qualified class name",
Expand All @@ -63,7 +63,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl,
ExecutionContext ctx) {
J.ClassDeclaration cd = super.visitClassDeclaration(classDecl, ctx);
if (cd.getExtends() != null &&
TypeUtils.isOfClassType(cd.getExtends().getType(), fullyQualifiedClassName)) {
TypeUtils.isOfClassType(cd.getExtends().getType(), fullyQualifiedClassName)) {
cd = cd.withExtends(null);
updateCursor(cd);
// This is an interesting one... JobExecutionListenerSupport implements
Expand All @@ -77,14 +77,14 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl,
}

cd = JavaTemplate
.builder(JavaType.ShallowClass.build(fullyQualifiedInterfaceName).getClassName())
.imports(fullyQualifiedInterfaceName)
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "spring-batch-core-5", "spring-batch-infrastructure-5"))
.build()
.apply(
getCursor(),
cd.getCoordinates().addImplementsClause()
);
.builder(JavaType.ShallowClass.build(fullyQualifiedInterfaceName).getClassName())
.imports(fullyQualifiedInterfaceName)
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "spring-batch-core-5", "spring-batch-infrastructure-5"))
.build()
.apply(
getCursor(),
cd.getCoordinates().addImplementsClause()
);
cd = (J.ClassDeclaration) new RemoveSuperStatementVisitor().visitNonNull(cd, ctx, getCursor().getParentOrThrow());
maybeRemoveImport(fullyQualifiedClassName);
maybeAddImport(fullyQualifiedInterfaceName);
Expand All @@ -98,8 +98,8 @@ class RemoveSuperStatementVisitor extends JavaIsoVisitor<ExecutionContext> {
final MethodMatcher wm = new MethodMatcher(fullyQualifiedClassName + " *(..)");

@Override
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method,
ExecutionContext ctx) {
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method,
ExecutionContext ctx) {
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
if (wm.matches(method.getMethodType())) {
//noinspection DataFlowIssue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public RemoveTargetAnnotation(J.Annotation targetToRemove) {
}

@Override
public J.@Nullable Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ctx) {
public J.@Nullable Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ctx) {
if (targetToRemove == annotation) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
updateCursor(cd);
}
cd = JavaTemplate.builder("WebMvcConfigurer")
.contextSensitive()
.imports("org.springframework.web.servlet.config.annotation.WebMvcConfigurer")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "spring-webmvc-5.*"))
.build().apply(getCursor(), cd.getCoordinates().addImplementsClause());
.contextSensitive()
.imports("org.springframework.web.servlet.config.annotation.WebMvcConfigurer")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "spring-webmvc-5.*"))
.build().apply(getCursor(), cd.getCoordinates().addImplementsClause());
updateCursor(cd);
cd = (J.ClassDeclaration) new RemoveSuperStatementVisitor().visitNonNull(cd, ctx, getCursor().getParentOrThrow());
maybeRemoveImport("org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter");
Expand All @@ -75,7 +75,7 @@ class RemoveSuperStatementVisitor extends JavaIsoVisitor<ExecutionContext> {
final MethodMatcher wm = new MethodMatcher("org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter *(..)");

@Override
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
if (wm.matches(method.getMethodType())) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public String getDisplayName() {
@Override
public String getDescription() {
return "Remove any calls matching `AuthenticationEntryPointFailureHandler.setRethrowAuthenticationServiceException(true)`. " +
"See the corresponding [Sprint Security 6.0 migration step](https://docs.spring.io/spring-security/reference/6.0.0/migration/servlet/authentication.html#_propagate_authenticationserviceexceptions) for details.";
"See the corresponding [Sprint Security 6.0 migration step](https://docs.spring.io/spring-security/reference/6.0.0/migration/servlet/authentication.html#_propagate_authenticationserviceexceptions) for details.";
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return Preconditions.check(new UsesType<>("org.springframework.security.web.authentication.AuthenticationEntryPointFailureHandler", true), new JavaIsoVisitor<ExecutionContext>() {

@Override
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
method = super.visitMethodInvocation(method, ctx);
if (method.getSelect() != null && method.getArguments().size() == 1 && MATCHER.matches(method)) {
Expression arg0 = method.getArguments().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class UseSha256InRememberMe extends Recipe {
private static final JavaType.Class REMEMBER_ME_TOKEN_ALGORITHM_TYPE = (JavaType.Class) JavaType.buildType("org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices$RememberMeTokenAlgorithm");
private static final MethodMatcher REMEMBER_ME_SERVICES_CONSTRUCTOR_MATCHER =
new MethodMatcher("org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices <constructor>(String, org.springframework.security.core.userdetails.UserDetailsService, " +
REMEMBER_ME_TOKEN_ALGORITHM_TYPE.getFullyQualifiedName() + ")");
REMEMBER_ME_TOKEN_ALGORITHM_TYPE.getFullyQualifiedName() + ")");
private static final MethodMatcher REMEMBER_ME_SERVICES_SET_MATCHING_ALGORITHM_MATCHER =
new MethodMatcher("org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices setMatchingAlgorithm(" +
REMEMBER_ME_TOKEN_ALGORITHM_TYPE.getFullyQualifiedName() + ")");
REMEMBER_ME_TOKEN_ALGORITHM_TYPE.getFullyQualifiedName() + ")");

@Override
public String getDisplayName() {
Expand All @@ -46,7 +46,7 @@ public String getDisplayName() {
@Override
public String getDescription() {
return "As of Spring Security 6.0 the SHA-256 algorithm is the default for the encoding and matching algorithm used by `TokenBasedRememberMeServices` and does thus no longer need to be explicitly configured. " +
"See the corresponding [Sprint Security 6.0 migration step](https://docs.spring.io/spring-security/reference/6.0.0/migration/servlet/authentication.html#servlet-opt-in-sha256-rememberme) for details.";
"See the corresponding [Sprint Security 6.0 migration step](https://docs.spring.io/spring-security/reference/6.0.0/migration/servlet/authentication.html#servlet-opt-in-sha256-rememberme) for details.";
}

@Override
Expand All @@ -65,10 +65,10 @@ public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {

@Override
@SuppressWarnings("DataFlowIssue")
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
public J.@Nullable MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
method = super.visitMethodInvocation(method, ctx);
if (method.getSelect() != null && method.getArguments().size() == 1 &&
REMEMBER_ME_SERVICES_SET_MATCHING_ALGORITHM_MATCHER.matches(method)) {
REMEMBER_ME_SERVICES_SET_MATCHING_ALGORITHM_MATCHER.matches(method)) {
if (isSha256Algorithm(method.getArguments().get(0), getCursor())) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
new JavaIsoVisitor<ExecutionContext>() {

@Override
public J.@Nullable VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) {
public J.@Nullable VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) {
J.VariableDeclarations vd = super.visitVariableDeclarations(multiVariable, ctx);
if (TypeUtils.isOfClassType(vd.getTypeAsFullyQualified(), SPRING_CLASS_RULE) ||
TypeUtils.isOfClassType(vd.getTypeAsFullyQualified(), SPRING_METHOD_RULE)) {
Expand Down

0 comments on commit a431e71

Please sign in to comment.