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

use generics for AbstractFindByBuilder to avoid excessive casting #15526

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

Conversation

asolntsev
Copy link
Contributor

@asolntsev asolntsev commented Mar 27, 2025

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Refactored AbstractFindByBuilder to use generics for type safety.

  • Updated FindByBuilder classes to leverage generics, reducing casting.

  • Improved method signatures for better clarity and type enforcement.


Changes walkthrough 📝

Relevant files
Enhancement
AbstractFindByBuilder.java
Add generics to `AbstractFindByBuilder` for type safety   

java/src/org/openqa/selenium/support/AbstractFindByBuilder.java

  • Introduced generics to AbstractFindByBuilder class.
  • Updated buildIt method to use generic type T.
  • +2/-2     
    FindAll.java
    Refactor `FindAll.FindByBuilder` to use generics                 

    java/src/org/openqa/selenium/support/FindAll.java

  • Updated FindByBuilder to extend AbstractFindByBuilder with FindAll.
  • Modified buildIt method to accept FindAll type directly.
  • +2/-3     
    FindBy.java
    Refactor `FindBy.FindByBuilder` to use generics                   

    java/src/org/openqa/selenium/support/FindBy.java

  • Updated FindByBuilder to extend AbstractFindByBuilder with FindBy.
  • Modified buildIt method to accept FindBy type directly.
  • +2/-3     
    FindBys.java
    Refactor `FindBys.FindByBuilder` to use generics                 

    java/src/org/openqa/selenium/support/FindBys.java

  • Updated FindByBuilder to extend AbstractFindByBuilder with FindBys.
  • Modified buildIt method to accept FindBys type directly.
  • +2/-3     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 27, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add annotation type bound

    Add a type bound to the generic parameter T to restrict it to annotation types
    only. This would make the API more type-safe and communicate the intended usage
    more clearly.

    java/src/org/openqa/selenium/support/AbstractFindByBuilder.java [25-27]

    -public abstract class AbstractFindByBuilder<T> {
    +public abstract class AbstractFindByBuilder<T extends Annotation> {
     
       public abstract By buildIt(T annotation, Field field);
     
       protected By buildByFromFindBy(FindBy findBy) {
         assertValidFindBy(findBy);

    [To ensure code accuracy, apply this suggestion manually]

    Suggestion importance[1-10]: 7

    __

    Why: Adding a type bound to restrict T to Annotation types improves type safety and makes the API's intent clearer. This is a meaningful enhancement that prevents potential misuse of the generic parameter with non-annotation types.

    Medium
    • Update

    @asolntsev asolntsev added C-java Java Bindings P-enhancement PR with a new feature and removed Review effort 2/5 labels Mar 27, 2025
    @asolntsev asolntsev self-assigned this Apr 3, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    C-java Java Bindings P-enhancement PR with a new feature
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant