-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
fix(CtDeprecatedRef): removes only unused deprecated methods #3200
Conversation
add tarjans scc algorithm. add detection for deprecated recursiv calls
refactor tests for better testing. And result and input folder for tests. refactor of code for better readability. Add second refactor#removeDeprecatedMethods for different input and output path. Add documentation for public methods.
Removed the cycle detection because the case A->B->C->A does not seem too realistic and produces many problems. |
Thanks a lot, that's super useful. In Spoon, we try to have readable PRs by minimizing formatting changes not related to the core change. Could you set up your editor to not reformat source code and have a nice minimized diff? In Spoon, we try to have high level, large test classes, could you move the test to RefactorTest? Thanks! |
This isn´t really part of the bug but we could give the refactoring method some signature like removeDeprecatedMethods(String input, String output, Class annotationClazz) and allow removing for all annotations. |
I would prefer a method which collects unused methods and returns a list or set. The other methods (remove or add annotation) should accept a list. That way, the solution would be easy to reuse for all kinds of scenarios (find all unused methods and print them, find the methods + filter the result before processing them, etc). |
After @digulla comment I removed the review state for the issue because there is still some more work needed. Splitted the invocationstate analysis for methods in a own class for reusability. |
Added javadoc and fixed typo. Now the deprecated removal should work. wdyt about the new package? |
} | ||
// create Spoon | ||
String input = "src\\test\\resources\\deprecated\\input"; | ||
String resultPath = "src\\test\\resources\\deprecated\\result"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write in target/deprecated-refactoring instead
Thanks a lot for the effort. I'm not sure we need a new package for a single specific feature, it fits nicely in the refactoring package already. |
Fixed output path, as in review wanted. Replaced windows paths with normal /
Thanks. Overall coverage decreases by -0.2%. I'm looking at the coverage report, section "New Missed Lines in Diff" New class MethodInvocationSearch.java has a coverage of 19% which is low. Could you add test cases to cover |
seems like there are some strange java8 issues. Looking into it. |
thanks @MartinWitt for adding tests to your great PR. Do you need help to make CI pass? |
Yeah i still can't find the bug in the CI. Testing with jdk8 is a bit difficult with windows. |
it looks like i lose method "test4" in jdk8. |
Is there some way to get the call and not the target for a CtInvocation?
what do you mean by "the call"?
|
I have created a testcase showcasing the unexpected behavior. In RefactoringTest.showBug() you get different results for the invoked methods depending on the jdk version. |
Interesting. This is not the first time we see behavioral differences across Java versions:
|
Opened an issue #3240, added check in test for jdk version and add doc comment for clarification. |
Thanks a lot for the big and valuable pull-request! |
Fix #3195 for details about the problem.
Edit 21.12 Small update:
Added loop detection for deprecated methods only calling deprecated methods e.g. A->B->C->A
Added detection for recursive calling methods e.g. B(){B()}.
Still need to write tests and catch bugs.