Skip to content

refine string formatting in dependencyManagementKey #2483

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

XenoAmess
Copy link
Contributor

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

nvl(dependency.getClassifier()),
nvl(dependency.getType()));
}
String hint = "groupId=" + nvl(dependency.getGroupId())
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 even harder to read than what it replaced. I can't look at this code and figure out what it does. So three suggestions:

  1. Break it up with multiple local variables
  2. rename the nvl method
  3. Add detailed doc comment that specifies the format

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rework as you suggested. please tell me if this make it read easier.

"groupId=%s, artifactId=%s, type=%s",
nvl(dependency.getGroupId()), nvl(dependency.getArtifactId()), nvl(dependency.getType()));
if (dependency.getClassifier() == null || dependency.getClassifier().isBlank()) {
hint = "groupId=" + valueToValueString(dependency.getGroupId())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this can really have groupId= rather than groupId="" ?
That seems strange

Copy link
Contributor Author

@XenoAmess XenoAmess Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this can really have groupId= rather than groupId="" ?

according to the original codes, yes.

That seems strange

if you ask me for my ideas, yes, it is strange :)

}
return new SourceHint(hint, null); // DMK
}

private static String nvl(String value) {
private static String valueToValueString(String value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just quote as a method name
Is it OK to have groupId=""? instead?

@@ -2251,23 +2251,20 @@ public static SourceHint gav(String gav) {

public static SourceHint dependencyManagementKey(Dependency dependency) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs javadoc

hint = String.format(
"groupId=%s, artifactId=%s, type=%s",
nvl(dependency.getGroupId()), nvl(dependency.getArtifactId()), nvl(dependency.getType()));
if (dependency.getClassifier() == null || dependency.getClassifier().isBlank()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work better with a StringBuilder that adds a piece at a time. Then there'd be less duplicate code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work better with a StringBuilder that adds a piece at a time. Then there'd be less duplicate code.

yes, but it would make the codes harder to understand as you pointed out before...

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.

2 participants