Minor cleanup using the ClassName util to convert dotted or slashed#2805
Minor cleanup using the ClassName util to convert dotted or slashed#2805hazendaz merged 7 commits intospotbugs:masterfrom
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.
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.
This is the opposite of the original change, it would be toSlashedClassName.
There was a problem hiding this comment.
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.
"if not..else" is a double negative, perhaps refactor to "if null then return null else..."
There was a problem hiding this comment.
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.
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
…potbugs#2805) * add ClassName.fromFieldSignatureToDottedClassName * use ClassName.toSlashedClassName where possible * remove unnecessary braces and return * use ClassName.toDottedClassName where possible * use ClassName.fromFieldSignatureToDottedClassName where possible * use ClassName util class in PreorderVisitor * Fixes according to reviews
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
ClassNameutil 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.