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

fix(CtDeprecatedRef): removes only unused deprecated methods #3200

Merged
merged 29 commits into from Feb 11, 2020

Conversation

MartinWitt
Copy link
Collaborator

@MartinWitt MartinWitt commented Dec 17, 2019

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.

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.
@MartinWitt
Copy link
Collaborator Author

MartinWitt commented Dec 27, 2019

Removed the cycle detection because the case A->B->C->A does not seem too realistic and produces many problems.
The bug mentioned in #3195 should be fixed(?) now.
Maybe someone finds some case i forgot to check.

@MartinWitt MartinWitt changed the title WIP: fix: Refactor for removing of deprecated methods #3195 Review: fix: Refactor for removing of deprecated methods #3195 Dec 27, 2019
@monperrus
Copy link
Collaborator

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!

@MartinWitt
Copy link
Collaborator Author

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.
Maybe someone wants to remove all unused methods with @beta annotation.
We could go even further and allow removing of all unused methods?
And removal of classes with annotations could be worth looking in too.
wdyt?

@digulla
Copy link

digulla commented Jan 7, 2020

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).

@MartinWitt MartinWitt changed the title Review: fix: Refactor for removing of deprecated methods #3195 WIP: fix: Refactor for removing of deprecated methods #3195 Jan 8, 2020
@MartinWitt
Copy link
Collaborator Author

MartinWitt commented Jan 8, 2020

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.

@MartinWitt
Copy link
Collaborator Author

Added javadoc and fixed typo. Now the deprecated removal should work.
I would add the invocation package as subpackage in refactoring, to allow the extension from methods to types. Removing unused top level types could be some feature, if some1 is brav enough to try to implement it.

wdyt about the new package?

@MartinWitt MartinWitt changed the title WIP: fix: Refactor for removing of deprecated methods #3195 Review: fix: Refactor for removing of deprecated methods #3195 Jan 25, 2020
}
// create Spoon
String input = "src\\test\\resources\\deprecated\\input";
String resultPath = "src\\test\\resources\\deprecated\\result";
Copy link
Collaborator

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

@monperrus
Copy link
Collaborator

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 /
@monperrus
Copy link
Collaborator

Thanks.

Overall coverage decreases by -0.2%. I'm looking at the coverage report, section "New Missed Lines in Diff"
https://coveralls.io/builds/28324991

New class MethodInvocationSearch.java has a coverage of 19% which is low.

Could you add test cases to cover MethodInvocationSearch better (say 80%)?

@MartinWitt
Copy link
Collaborator Author

seems like there are some strange java8 issues. Looking into it.

@monperrus
Copy link
Collaborator

thanks @MartinWitt for adding tests to your great PR.

Do you need help to make CI pass?

@MartinWitt
Copy link
Collaborator Author

Yeah i still can't find the bug in the CI. Testing with jdk8 is a bit difficult with windows.
Would be nice to get some help @monperrus .

@MartinWitt
Copy link
Collaborator Author

it looks like i lose method "test4" in jdk8.

@MartinWitt
Copy link
Collaborator Author

MartinWitt commented Feb 9, 2020

After testing with jdk8, i found the problem.
image
The chained methodcall new Foo(v).test4() does not return CtInvocation test4(). Is there some way to get the call and not the target for a CtInvocation?

Edit: (Clarification) in jdk9+ it's working as intended

@monperrus
Copy link
Collaborator

monperrus commented Feb 10, 2020 via email

@MartinWitt
Copy link
Collaborator Author

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.
model.getElements(new TypeFilter<>(CtInvocation.class)) gives the same result on all versions, but the getExecutable().getExecutableDeclaration() creates different results, depending if you use jdk8 or jdk9+.

@monperrus
Copy link
Collaborator

the getExecutable().getExecutableDeclaration() creates different results, depending if you use jdk8 or jdk9+.

Interesting.

This is not the first time we see behavioral differences across Java versions:

@MartinWitt
Copy link
Collaborator Author

Opened an issue #3240, added check in test for jdk version and add doc comment for clarification.
I wouldn't stop a user, using this refactoring with old jdk but instead tell him in the javadoc.

@monperrus monperrus changed the title Review: fix: Refactor for removing of deprecated methods #3195 fix(CtDeprecatedRef): removes only unused deprecated methods Feb 11, 2020
@monperrus monperrus merged commit ad00519 into INRIA:master Feb 11, 2020
@monperrus
Copy link
Collaborator

Thanks a lot for the big and valuable pull-request!

MartinWitt added a commit to MartinWitt/spoon that referenced this pull request Feb 11, 2020
@monperrus monperrus mentioned this pull request Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: removeDeprecatedMethods should not remove the methods that are used somewhere
3 participants