Skip to content

Bugfix/852 static import family #853

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

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 @@ -35,10 +35,12 @@ protected String getTestSubDir() {
private final String expectedJavaSource =
"""
package com.example.jee.app;


import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatus.Series;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

Expand All @@ -63,6 +65,10 @@ public String getHelloWorldXML(@PathVariable("name") String name) throws Excepti
System.out.println("name: " + name);
return "<xml>Hello "+name+"</xml>";
}

private boolean isResponseStatusSuccessful(HttpStatus.Series family) {
return family == Series.SUCCESSFUL;
}

}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.stream.Collectors;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.Response.Status.Family.SUCCESSFUL;

@Path("/")
public class PersonController {
Expand Down Expand Up @@ -36,4 +38,8 @@ public String getHelloWorldXML(@PathParam("name") String name) throws Exception
return "<xml>Hello "+name+"</xml>";
}

private boolean isResponseStatusSuccessful(Response.Status.Family family) {
return family == SUCCESSFUL;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,23 @@
import org.openrewrite.java.ChangeType;
import org.openrewrite.java.JavaTemplate;
import org.springframework.sbm.java.migration.recipes.RewriteMethodInvocation;
import org.springframework.sbm.java.migration.recipes.openrewrite.ReplaceConstantWithAnotherConstant;

import java.util.HashMap;
import java.util.Map;

public class SwapFamilyForSeries extends Recipe {

public SwapFamilyForSeries() {
Map<String, String> fieldsMapping = new HashMap<>();
fieldsMapping.put("INFORMATIONAL", "INFORMATIONAL");
fieldsMapping.put("SUCCESSFUL", "SUCCESSFUL");
fieldsMapping.put("REDIRECTION", "REDIRECTION");
fieldsMapping.put("CLIENT_ERROR", "CLIENT_ERROR");
fieldsMapping.put("SERVER_ERROR", "SERVER_ERROR");
fieldsMapping.forEach(
(key, value) -> doNext(new ReplaceConstantWithAnotherConstant("javax.ws.rs.core.Response.Status.Family." + key,"org.springframework.http.HttpStatus.Series." + value))
);

// All constants seem to match on both types - let ChangeType take care of type changing for field accesses
doNext(new RewriteMethodInvocation(
Expand Down