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
Removed synthetic methods #1556
Removed synthetic methods #1556
Conversation
Looking at the diff I think it would be a good idea to leave /private/ in the code and put a comment in the default constructors so that a future cleanup wouldn't reverse the changes. How does adding a default scoped ctor help? Without a default scoped ctor (1 method) a private one is generated with an accessor (2 methods)? The 26 PMD violations are likely |
@TWiStErRob And, yes, if we don't have a default scoped ctor, two ctors will be synthesized, one will be the private constructor with no params and one will be a package private constructor with an arbitrary param (its type is dependent on compiler implementation, and hence one addtional empty class to support ctor overloading. Sorry, due to different timezones I was unable to get back to you immediately. |
If you look at this code out of context, what you see is that one of the fields are non-private for seemingly no reason (all usages of it are within the same class). private final Glide glide;
final Lifecycle lifecycle;
private final RequestTracker requestTracker; This would make it more clear that it was supposed to be private, but cannot due to some limitation. private final Glide glide;
/*private*/ final Lifecycle lifecycle;
private final RequestTracker requestTracker; potentially an even better approach would be a Actually, thinking of it, isn't there a library out there which does this automatically? I mean if there is a way to have lambdas in Java 5, some APT code should be able to increase visibility of fields. |
Got it. Like this one: So, I can go forward and implement that source-level annotation and update the code accordingly? Yeah, there should be a library which does this automatically, but I was unable to find something after doing a quick search. |
Yep, that example looks good, hidroh/materialistic#642 is where it was introduced. So the changes are: - private final Type name;
+ @Synthetic final Type name; I like the shorter |
Btw, don't know what @sjudd's stand is on this, I hope he'll accept, but not sure. |
Great. Yeah, even I hope the same about that. |
Btw, I think we should create a new directory named What's your take? |
Also, |
Yes, you can contribute to I would put the annotation in |
@TWiStErRob Will move the annotation directory under |
No worries. I will fix it. |
You can run You'll likely need |
All checks passed locally, but I used What's your take? |
Why suppress if you can write a comment inside? Suppressions usually need to be explained, but if there's a comment, it explains itself. I don't know much either, but based on a quick research it's quite simple. I found this: http://pmd.sourceforge.net/pmd-5.1.1/howtowritearule.html and the source for the rule is https://github.com/pmd/pmd/blob/master/pmd-java/src/main/resources/rulesets/java/design.xml#L1401-L1431 . I don't have time right now, but it looks like it should be as easy as adding I say if you have time or curious go ahead with changing the rule, if not, just go with comments. |
No worries, I will give it a try! |
Nice. Just noticed something: the samples are not part of the API, they're just usage examples. I think it's better to keep synthetics there, so they're more portable (copy-paste). |
Thanks a lot Robert! |
Thanks :) Now, we just have to wait for @sjudd to ack. Note: there are some weird new-lines left in diff |
Yeah, no worries. I will remove those weird lines. |
ohh! |
No, but I mostly saw them in samples after your last push removing code from those. I suggest you squash your commits locally first, then amend the last commit to see if there are irrelevant modifications in the squashed diff. We would squash-merge anyway, so it doesn't matter that the commits are lost. |
Btw, I have to just double sure that you mean to say that I have to get rid of that new line, right? |
If there's no related change (like adding/removing an import or method), then there should no random whitespace changes in the diff either. So, yes, make sure any standalone added/removed newline is not in the diff, especially in files with no other changes. |
8c8da4b
to
6ebfe19
Compare
Btw, looking at the original source files I found that grouping is not applied in imports. Hence, to maintain consistency across the project I think I should also follow the same path. |
6ebfe19
to
7adf263
Compare
Huh, that's interesting. Here's the commit that added groups: f7a6d65, but you're right the current code doesn't have groups, and that's because of 3f5543a. This is a recent change, I haven't been following the |
Yeah! You are right too! |
The current diff looks good, sorry about the confusion. |
No worries at all Robert! I was honored to work on this! Thanks a lot! :) |
Thanks for putting this together! Can you do a quick before/after on the class/method count to verify the changes? |
Yeah Sam, |
Huh, what's that 3 remaining? Btw, I think Sam wanted to see total numbers as well. |
IDEA/AS is not perfect, they are always working to make them better, just check out the EAP release notes. I reported quite a few myself the latest one being what you just found: IDEA-163379. |
Ohh! |
Yep, the class file is what matters in the end, IDE warnings are just helpers. |
Yeah! Will do it right away! 👍 |
7adf263
to
7c4e1dc
Compare
After analyzing both versions of dex files I found total method count as - Before: 3282 Also, The accessor methods count - |
I found class count as - Before: 470 |
LGTM, Thanks! I wonder if it's possible to write a build check for this? |
I am thankful to you too for writing such a great library! :)
|
I think PMD works on class files, so we can check if they have |
@RiteshChandnani bug you found with sibling-synthetics is fixed already. |
Yeah I checked too! Nice that it has been fixed fixed! :) |
Description
This removes all the synthetic methods.
Issue #1555
Motivation and Context
This change helps us reduce the method count and therefore also helps us avoid the trampoline created because of synthetic methods.