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
Minor cleanup using the ClassName util to convert dotted or slashed #2805
Conversation
// Lorg/immutables/value/Generated; -> org.immutables.value.Generated | ||
List<String> javaAnnotationNames = Arrays.asList(annotationEntries).stream() | ||
.map((AnnotationEntry ae) -> ClassName.fromFieldSignatureToDottedClassName(ae.getAnnotationType())) | ||
.collect(Collectors.toList()); |
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.
This is the only change where it's not only the usage of the method from the ClassName
util class, but also removing the unnecessary block and return, and moving the comment.
I think due to the size its worth mentioning in a change log just in case something goes wrong users know that it was listed in change log. It otherwise is ok. |
} | ||
|
||
if (signature.indexOf('.') >= 0) { | ||
assert false; | ||
signature = signature.replace('.', '/'); | ||
signature = ClassName.toDottedClassName(signature); |
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.
This is the opposite of the original change, it would be toSlashedClassName
.
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.
Thanks a lot! Fixed it. I checked it once more, and I couldn't find any other mistakes like this.
@DottedClassName | ||
public static @CheckForNull String fromFieldSignatureToDottedClassName(String signature) { | ||
String slashedClassName = ClassName.fromFieldSignature(signature); | ||
if (slashedClassName != null) { |
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.
"if not..else" is a double negative, perhaps refactor to "if null then return null else..."
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.
That and remove the 'else' all together. It doesn't allow proper completion when return is within it. Not a huge deal, we need a large cleanup in general of spotbugs but while at it flip it as noted and remove else as unnecessary then.
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.
Thanks, fixed it.
I agree, we need a cleanup in spotbugs. I think making it in smaller steps makes it is less overwhelming, easier to reivew and less likely to add issues 😄
4e7fa20
to
c6bdae2
Compare
A lot of the times the conversion from dotted to slashed names and wise versa are done on the spot, without much context and adding the annotations. There are already functions for these in the
ClassName
util class. This PR mainly uses these util functions wherever it's possible, and adds thefromFieldSignatureToDottedClassName()
method toClassName
, since thefromFieldSignature()
andtoDottedClassName()
methods are used together quite frequently.I didn't add a changelog entry, since I don't think it's necessary.