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

Minor cleanup using the ClassName util to convert dotted or slashed #2805

Merged
merged 7 commits into from Jan 9, 2024

Conversation

JuditKnoll
Copy link
Collaborator

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 the fromFieldSignatureToDottedClassName() method to ClassName, since the fromFieldSignature() and toDottedClassName() methods are used together quite frequently.
I didn't add a changelog entry, since I don't think it's necessary.

// 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());
Copy link
Collaborator Author

@JuditKnoll JuditKnoll Jan 8, 2024

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.

@hazendaz
Copy link
Member

hazendaz commented Jan 9, 2024

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.

@hazendaz hazendaz self-assigned this Jan 9, 2024
@hazendaz hazendaz added this to the SpotBugs 4.8.4 milestone Jan 9, 2024
}

if (signature.indexOf('.') >= 0) {
assert false;
signature = signature.replace('.', '/');
signature = ClassName.toDottedClassName(signature);
Copy link
Contributor

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.

Copy link
Collaborator Author

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) {
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Collaborator Author

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 😄

@hazendaz hazendaz merged commit ddfbaba into spotbugs:master Jan 9, 2024
9 checks passed
@JuditKnoll JuditKnoll deleted the classnameutil branch January 10, 2024 07:23
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.

None yet

3 participants