-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Cache ResolvedType in MetaProperty #434
Conversation
* Statically defined meta-properties can cache the resolved type
📝 WalkthroughWalkthroughThe changes involve modifications to the Changes
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 and nitpick comments (3)
src/main/java/org/joda/beans/MetaProperty.java (1)
96-106
: Implementation looks good and maintains backwards compatibilityThe new default method provides a clean way to resolve generic types relative to a context class whilst allowing implementations to override if needed.
Walkthrough of Public API Changes:
- Added new public method to MetaProperty interface:
ResolvedType propertyResolvedType(Class<?> contextClass)
- Impact: This is a backwards-compatible change as it's a default method
- Usage: Enables clients to resolve generic types in the context of a specific class
- Example: Useful when dealing with generic type parameters in inheritance hierarchies
src/main/java/org/joda/beans/ResolvedType.java (1)
Line range hint
1-600
: Changes to Public Java APIThe following changes have been made to the public Java API:
- Added new public method
boolean isParameterized()
toResolvedType
class
- Impact: Additive change that provides new functionality without breaking existing code
- Usage: Allows clients to check if a type has generic parameters, regardless of whether they are specified
The update to
isRaw()
refines the implementation without changing its contract, maintaining backwards compatibility.src/main/java/org/joda/beans/impl/direct/MinimalMetaProperty.java (1)
127-130
: Suggestion: Simplify the lambda expressions for readabilityConsider extracting the lambda expressions into separate, named methods to improve readability and maintainability, especially for complex conditional logic.
Apply this refactoring:
return !resolvedType.isParameterized() || Modifier.isFinal(beanType.getModifiers()) ? - contextClass -> resolvedType : - contextClass -> contextClass == beanType ? resolvedType : ResolvedType.from(propertyGenericType, contextClass); + this::resolveTypeForFinalBean : + this::resolveTypeForNonFinalBean; +private ResolvedType resolveTypeForFinalBean(Class<?> contextClass) { + return resolvedType; +} +private ResolvedType resolveTypeForNonFinalBean(Class<?> contextClass) { + return contextClass == beanType ? resolvedType : ResolvedType.from(propertyGenericType, contextClass); +}
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (6)
src/main/java/org/joda/beans/MetaProperty.java
(1 hunks)src/main/java/org/joda/beans/ResolvedType.java
(1 hunks)src/main/java/org/joda/beans/impl/direct/DirectMetaProperty.java
(5 hunks)src/main/java/org/joda/beans/impl/direct/MinimalMetaProperty.java
(6 hunks)src/main/java/org/joda/beans/impl/light/LightMetaProperty.java
(4 hunks)src/test/java/org/joda/beans/TestResolvedType.java
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/main/java/org/joda/beans/MetaProperty.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Favour use of
var
keyword for type declarations.var
may also be used when the value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/main/java/**/*.java
: - This project is mature and must provide a stable backwards-compatible public Java API.
- In the 'Walkthrough' section, you must always provide a list of up to 25 changes to the public Java API that will affect end users.
If there are no changes, you must explicitly state that there are no changes to the public Java API in this PR.
The public Java API is defined as public and protected methods on public classes, plus the filemodule-info.java
.
Provide the list by deeply analysing code flow, which incudes analysing code flow through private methods and calls to Guava and Java 21.
Changes to be reported on include:- New or removed methods in the public Java API
- Changes to method return types or parameter types in the public Java API
- Changes to method behaviour in the public Java API that might affect consumers
- This project uses
System.out.println
instead of logging - This project tends to prefer
for
loops to streams for performance reasons, however either form is acceptable.
Do not make suggestions to change between streams and for loops or vice versa.
src/main/java/org/joda/beans/ResolvedType.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Favour use of
var
keyword for type declarations.var
may also be used when the value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/main/java/**/*.java
: - This project is mature and must provide a stable backwards-compatible public Java API.
- In the 'Walkthrough' section, you must always provide a list of up to 25 changes to the public Java API that will affect end users.
If there are no changes, you must explicitly state that there are no changes to the public Java API in this PR.
The public Java API is defined as public and protected methods on public classes, plus the filemodule-info.java
.
Provide the list by deeply analysing code flow, which incudes analysing code flow through private methods and calls to Guava and Java 21.
Changes to be reported on include:- New or removed methods in the public Java API
- Changes to method return types or parameter types in the public Java API
- Changes to method behaviour in the public Java API that might affect consumers
- This project uses
System.out.println
instead of logging - This project tends to prefer
for
loops to streams for performance reasons, however either form is acceptable.
Do not make suggestions to change between streams and for loops or vice versa.
src/main/java/org/joda/beans/impl/direct/DirectMetaProperty.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Favour use of
var
keyword for type declarations.var
may also be used when the value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/main/java/**/*.java
: - This project is mature and must provide a stable backwards-compatible public Java API.
- In the 'Walkthrough' section, you must always provide a list of up to 25 changes to the public Java API that will affect end users.
If there are no changes, you must explicitly state that there are no changes to the public Java API in this PR.
The public Java API is defined as public and protected methods on public classes, plus the filemodule-info.java
.
Provide the list by deeply analysing code flow, which incudes analysing code flow through private methods and calls to Guava and Java 21.
Changes to be reported on include:- New or removed methods in the public Java API
- Changes to method return types or parameter types in the public Java API
- Changes to method behaviour in the public Java API that might affect consumers
- This project uses
System.out.println
instead of logging - This project tends to prefer
for
loops to streams for performance reasons, however either form is acceptable.
Do not make suggestions to change between streams and for loops or vice versa.
src/main/java/org/joda/beans/impl/direct/MinimalMetaProperty.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Favour use of
var
keyword for type declarations.var
may also be used when the value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/main/java/**/*.java
: - This project is mature and must provide a stable backwards-compatible public Java API.
- In the 'Walkthrough' section, you must always provide a list of up to 25 changes to the public Java API that will affect end users.
If there are no changes, you must explicitly state that there are no changes to the public Java API in this PR.
The public Java API is defined as public and protected methods on public classes, plus the filemodule-info.java
.
Provide the list by deeply analysing code flow, which incudes analysing code flow through private methods and calls to Guava and Java 21.
Changes to be reported on include:- New or removed methods in the public Java API
- Changes to method return types or parameter types in the public Java API
- Changes to method behaviour in the public Java API that might affect consumers
- This project uses
System.out.println
instead of logging - This project tends to prefer
for
loops to streams for performance reasons, however either form is acceptable.
Do not make suggestions to change between streams and for loops or vice versa.
src/main/java/org/joda/beans/impl/light/LightMetaProperty.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Favour use of
var
keyword for type declarations.var
may also be used when the value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/main/java/**/*.java
: - This project is mature and must provide a stable backwards-compatible public Java API.
- In the 'Walkthrough' section, you must always provide a list of up to 25 changes to the public Java API that will affect end users.
If there are no changes, you must explicitly state that there are no changes to the public Java API in this PR.
The public Java API is defined as public and protected methods on public classes, plus the filemodule-info.java
.
Provide the list by deeply analysing code flow, which incudes analysing code flow through private methods and calls to Guava and Java 21.
Changes to be reported on include:- New or removed methods in the public Java API
- Changes to method return types or parameter types in the public Java API
- Changes to method behaviour in the public Java API that might affect consumers
- This project uses
System.out.println
instead of logging - This project tends to prefer
for
loops to streams for performance reasons, however either form is acceptable.
Do not make suggestions to change between streams and for loops or vice versa.
src/test/java/org/joda/beans/TestResolvedType.java (2)
Pattern **/*.java
: - Review code using Java 21 standards, taking into account the rules defined by src/main/checkstyle/checkstyle.xml
.
- Validate that code indentation uses spaces, not tabs, with an indent of multiple of 4.
- Validate that immutable local variables are not annotated with
final
unless the variable is required for use in an inner class. - Favour use of
var
keyword for type declarations.var
may also be used when the value is a castnull
. - Use a coding standard where multi-line expressions have operators and tenary separators at the end of line.
- Propose changes that only use the Java 21 API, not the API of Guava.
- The pattern matching
instanceof
expression safely handlesnull
, returningfalse
.
Pattern **/test/java/**/*.java
: For test code, focus on:
- Correctness of test assertions
- Test coverage of edge cases
- Clear test naming and documentation
- Encourage test methods to be package-scoped where possible
- Be more lenient with code style and minor optimisations
🔇 Additional comments (19)
src/main/java/org/joda/beans/MetaProperty.java (1)
92-92
: LGTM - Documentation update looks correct
The removal of "unmodifiable" from the Javadoc is appropriate since java.lang.reflect.Type is inherently immutable.
src/test/java/org/joda/beans/TestResolvedType.java (1)
266-266
: LGTM! Comprehensive test coverage for isParameterized()
The new assertion correctly validates the parameterised state of ResolvedType by comparing against the raw type's type parameters. The test data in data_resolvedTypes()
provides good coverage with various cases including generic types, arrays, and nested generics.
Let's verify the test data covers all edge cases:
✅ Verification successful
Test coverage for isParameterized() is comprehensive and well-structured
The test data in data_resolvedTypes()
provides excellent coverage for parameterised types, including:
- Raw generic types (
List
,Map
) - Parameterised types with single type argument (
List<String>
) - Parameterised types with multiple type arguments (
Map<String, Number>
) - Nested generic types (
List<List<Address>>
) - Array types with generics (
List<String>[]
,List<String>[][]
) - Complex nested types (
Map<String, List<Number>[]>[]
) - Bounded type parameters with
extends
(Comparable<Object>
) - Collection types from different libraries (
ImmutableList
,ImmutableMap
,ImmutableMultiset
)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify test coverage for parameterized types
# Look for test cases in data_resolvedTypes() that exercise different scenarios
# Test: Search for various generic type patterns in test data
echo "Checking test coverage for different parameterized type scenarios..."
rg -A 3 'ResolvedType\.(of|from|ofFlat)' src/test/java/org/joda/beans/TestResolvedType.java | \
grep -E '(List|Map|ImmutableList|ImmutableMap|Comparable|AbstractResult)'
Length of output: 7544
src/main/java/org/joda/beans/ResolvedType.java (2)
475-484
: Well-implemented new method with clear documentation
The new isParameterized()
method is well-documented with examples and correctly implements the check for generic type parameters. The implementation is efficient and maintains the class's thread-safety.
489-492
: Refined implementation maintains backwards compatibility
The isRaw()
method has been updated to use isParameterized()
, making the code more maintainable whilst preserving backwards compatibility. The change clarifies that a raw type must be both parameterizable and have empty arguments.
src/main/java/org/joda/beans/impl/direct/MinimalMetaProperty.java (6)
21-21
: Imports are necessary and correctly added
The import statements for java.lang.reflect.Modifier
and org.joda.beans.ResolvedType
are appropriately added and are required for the new functionality.
Also applies to: 32-32
48-49
: Definition of 'propertyResolvedTypeFn' field is appropriate
The addition of the propertyResolvedTypeFn
field correctly encapsulates the logic for resolving property types, enhancing the class's functionality.
89-89
: Initialisation of 'propertyResolvedTypeFn' in constructors is correct
The initialisation of propertyResolvedTypeFn
in both constructors ensures that the resolved type function is properly set up for different instantiation scenarios.
Also applies to: 121-121
124-130
: Implementation of 'createResolvedTypeFunction()' is correct
The createResolvedTypeFunction()
method effectively creates a function to determine the resolved type based on whether the property is parameterised and if the bean type is final, ensuring efficient type resolution.
153-156
: Overriding 'propertyResolvedType' method is appropriate
The overridden propertyResolvedType
method correctly utilises the propertyResolvedTypeFn
function to provide dynamic type resolution based on the context class.
Line range hint 1-157
: Walkthrough: Review of Public Java API Changes
There are no changes to the public Java API in this PR. All modifications are confined to internal classes and methods, and do not affect the public or protected methods on public classes.
src/main/java/org/joda/beans/impl/light/LightMetaProperty.java (3)
50-51
: Addition of private field propertyResolvedTypeFn
The new private field propertyResolvedTypeFn
is appropriately declared to cache the resolved type function.
229-233
: Correct initialisation of propertyResolvedTypeFn
The logic for initialising propertyResolvedTypeFn
effectively handles different scenarios based on whether resolvedType
is parameterised and whether beanType
is final.
257-260
: Changes to the Public Java API
In compliance with the project guidelines, the following change to the public Java API may affect end users:
-
Overridden Method: The method
propertyResolvedType(Class<?> contextClass)
is now overridden inLightMetaProperty
.- Potential Impact: This change may alter the behaviour of
LightMetaProperty
instances for consumers who rely on the inherited implementation from the superclassBasicMetaProperty
. Please verify that this alteration maintains backward compatibility and aligns with the expected functionality.
- Potential Impact: This change may alter the behaviour of
src/main/java/org/joda/beans/impl/direct/DirectMetaProperty.java (6)
Line range hint 22-36
: Review of Added Import Statements and Type Declarations
The additional import statements for java.lang.reflect.Modifier
, java.util.function.Function
, and org.joda.beans.ResolvedType
are appropriate and necessary for the implementation of the new functionality.
52-55
: Appropriate Addition of Private Fields
The private fields propertyGenericType
and propertyResolvedTypeFn
are correctly declared and initialised. They effectively cache the generic type information and the function to resolve the property type, enhancing performance and reducing redundant computations.
203-207
: Correct Use of Switch Expression for Initialising propertyGenericType
The utilisation of the switch expression accurately handles the different cases of fieldOrMethod
. The inclusion of null, default
ensures that all possible values are accounted for, defaulting to propertyType
when necessary.
211-215
: Efficient Initialisation of propertyResolvedTypeFn
The initialisation logic for propertyResolvedTypeFn
optimises type resolution by precomputing or deferring computation based on whether the resolved type is parameterised or if the bean class is final. This approach balances performance with flexibility.
236-237
: Optimisation in propertyGenericType()
Method
Returning the cached propertyGenericType
in the propertyGenericType()
method avoids unnecessary recalculations, improving method efficiency.
239-241
: Addition of New Public Method propertyResolvedType(Class<?> contextClass)
The new method enhances the API by allowing clients to obtain the resolved type of the property relative to a given context class. Ensure that this addition maintains backward compatibility and adheres to the project's API stability commitments.
Summary by CodeRabbit
New Features
Bug Fixes
Tests