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

Feature: Add interface for display name #39

Merged
merged 5 commits into from
Jul 12, 2024
Merged

Conversation

infeo
Copy link
Member

@infeo infeo commented Jul 1, 2024

This PR adds the NamedServiceProvider interface to the commons package.

The interface is intended to mark services as "has a printable, human readable, possibly localized name" with the method getName(). Alongside with the interface, the annotations @DisplayName and @LocalizedDisplayName are added and the default getName() impl checks for these annotation and falls back to the qualified class name otherwise.

Already existing SPIs are not modified, since this would require changes in a lot of different libraries, which should be done in a separate project.

Copy link

coderabbitai bot commented Jul 1, 2024

Walkthrough

The changes introduce new annotations (@DisplayName and @LocalizedDisplayName) to provide human-readable and localized names for classes. Additionally, a new interface NamedServiceProvider is created, which includes a method getName() to retrieve the name of a service provider, leveraging the new annotations for localization.

Changes

File Path Change Summary
src/main/java/org/cryptomator/integrations/common/DisplayName.java Introduced @DisplayName annotation to provide a human-readable name for classes.
src/main/java/org/cryptomator/integrations/common/LocalizedDisplayName.java Introduced @LocalizedDisplayName annotation for specifying a localized name using bundle and key.
src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java Created NamedServiceProvider interface with getName() method to retrieve a service provider's name, utilizing @LocalizedDisplayName and @DisplayName annotations.

Poem

In a world of code, annotations bloom,
Names now shine, no longer doom. 🌟
From DisplayName to localized grace,
NamedServiceProvider finds its place.
Embrace the change, let names be clear,
For every class, a name we cheer! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4bfb945 and aad9c04.

Files selected for processing (2)
  • src/main/java/org/cryptomator/integrations/common/DisplayName.java (1 hunks)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java
Additional comments not posted (21)
src/main/java/org/cryptomator/integrations/common/DisplayName.java (21)

1-1: LGTM!

The package declaration is correct.


2-2: LGTM!

The empty line is acceptable for readability.


3-3: LGTM!

The import statement for Documented is correct.


4-4: LGTM!

The import statement for ElementType is correct.


5-5: LGTM!

The import statement for Retention is correct.


6-6: LGTM!

The import statement for RetentionPolicy is correct.


7-7: LGTM!

The import statement for Target is correct.


8-8: LGTM!

The empty line is acceptable for readability.


9-9: LGTM!

The import statement for ApiStatus is correct.


10-10: LGTM!

The empty line is acceptable for readability.


11-11: LGTM!

The start of the comment block is correctly placed.


12-12: Improve the comment for clarity.

The comment could be more descriptive.

- * A humanreadable name of the annotated class.
+ * Annotation to provide a human-readable name for the annotated class.

13-13: LGTM!

The empty line is acceptable for readability.


14-14: LGTM!

The @Documented annotation is correctly placed.


15-15: LGTM!

The @Retention annotation is correctly placed.


16-16: LGTM!

The @Target annotation is correctly placed.


17-17: LGTM!

The @ApiStatus.Experimental annotation is correctly placed.


18-18: LGTM!

The annotation declaration is correctly placed.


19-19: LGTM!

The method value() is correctly defined.


20-20: LGTM!

The empty line is acceptable for readability.


21-21: LGTM!

The closing brace is correctly placed.

Copy link
Member

@overheadhunter overheadhunter left a comment

Choose a reason for hiding this comment

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

Please add a boolean flag denoting whether value should be used as a localization key or directly.

Maybe it is even worth replacing value by two separate fields name and localizationKey that are mutually exclusive. Then users of the annotation are forced to explicitly decide for either option. (without value, you can't write @DisplayName("whatDoesThisStringMean?"))

@infeo
Copy link
Member Author

infeo commented Jul 4, 2024

@overheadhunter I would rather go with an additional, optional parameter than implementing some if/or logic. My goal is for a simple, easy to use annotation, which can be extended if the implementor wants to.

Something like this:

public @interface DisplayName {
	String value();

	/**
	 * Localization key for the display name.
	 * <p>
	 * Optional parameter. If there is no localization, it returns an empty string.
	 *
	 * @return
	 */
	String localizationKey() default "";

}

The default method in NamedServiceProvider then is adjusted to check first for a localizaion key, then the default value and as a last resort the qualified class name.

@infeo
Copy link
Member Author

infeo commented Jul 11, 2024

After a discussion we decided to move the localization to its own interface (see 750bb02)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (6)
src/main/java/org/cryptomator/integrations/common/DisplayName.java (3)

1-1: Add a blank line after the package declaration.

It is a common convention to separate the package declaration from the import statements with a blank line for readability.

package org.cryptomator.integrations.common;

import org.jetbrains.annotations.ApiStatus;

12-12: Typo: "humanreadable" should be "human-readable".

Correct the typographical error in the comment for clarity.

 * A humanreadable name of the annotated class.
+ * A human-readable name of the annotated class.

19-19: Consider adding a method description.

Adding a description to the value() method improves the documentation and usability of the annotation.

	String value();
+	/**
+	 * The display name for the annotated class.
+	 *
+	 * @return The display name
+	 */
src/main/java/org/cryptomator/integrations/common/LocalizedDisplayName.java (3)

1-1: Add a blank line after the package declaration.

It is a common convention to separate the package declaration from the import statements with a blank line for readability.

package org.cryptomator.integrations.common;

import org.jetbrains.annotations.ApiStatus;

12-12: Typo: "humanreadable" should be "human-readable".

Correct the typographical error in the comment for clarity.

 * A humanreadable, localized name of the annotated class.
+ * A human-readable, localized name of the annotated class.

19-19: Consider adding method descriptions.

Adding descriptions to the bundle() and key() methods improves the documentation and usability of the annotation.

	String bundle();
+	/**
+	 * The name of the localization bundle.
+	 *
+	 * @return The name of the localization bundle
+	 */
	
	String key();
+	/**
+	 * The localization key for the display name.
+	 *
+	 * @return The localization key
+	 */
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aad9c04 and 750bb02.

Files selected for processing (3)
  • src/main/java/org/cryptomator/integrations/common/DisplayName.java (1 hunks)
  • src/main/java/org/cryptomator/integrations/common/LocalizedDisplayName.java (1 hunks)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java

var localizedDisplayName = this.getClass().getAnnotation(LocalizedDisplayName.class);
if (localizedDisplayName != null) {
return ResourceBundle.getBundle(localizedDisplayName.bundle()) //
.getString(localizedDisplayName.key());
Copy link
Member

Choose a reason for hiding this comment

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

if getString throws a MissingResourceException, fallback to @DisplayName?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it in def56fe

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 750bb02 and def56fe.

Files selected for processing (3)
  • src/main/java/org/cryptomator/integrations/common/DisplayName.java (1 hunks)
  • src/main/java/org/cryptomator/integrations/common/LocalizedDisplayName.java (1 hunks)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/main/java/org/cryptomator/integrations/common/DisplayName.java
  • src/main/java/org/cryptomator/integrations/common/LocalizedDisplayName.java
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between def56fe and 9508ee5.

Files selected for processing (1)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java

@infeo infeo merged commit 65abccd into develop Jul 12, 2024
4 checks passed
@infeo infeo deleted the feature/display-name branch July 12, 2024 11:07
@infeo infeo added this to the next milestone Jul 12, 2024
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