KON-685 Add missing declaration in KoDeclarationCastProvider for combined types #1547
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a comprehensive set of functionalities to enhance type handling within
KoDeclarationCastProvider
, focusing on combined types like classes, interfaces, and objects. The changes aim to improve the clarity, usability, and flexibility of declarations, making it easier to work with complex type combinations in Kotlin.Summary of Changes:
New Properties:
Added Boolean properties such as
isClassOrObject
,isClassOrInterface
, and similar, to allow quick identification of declarations that belong to combined type categories (e.g., whether a declaration is either a class or an object).New Methods for Casting:
Introduced methods like
asClassOrObjectDeclaration()
orasClassOrInterfaceDeclaration()
that enable safe casting to specific combined types. This ensures clear and consistent handling of declarations based on their type composition.Type Predicate Methods:
Added methods like
hasClassOrObjectDeclaration(predicate)
to verify specific conditions on combined types. These allow for flexible filtering and validation based on predicates.Extensions for Lists:
Introduced extension functions for lists of
KoDeclarationCastProvider
to support filtering and mapping based on the newly added properties and methods. Examples include:classAndObjectDeclarations()
for extracting all class or object declarations.withClassOrInterfaceDeclaration(predicate)
to filter elements matching specific criteria for combined types.withoutInterfaceOrObjectDeclarationOf()
to exclude declarations of certain types.Purpose:
This update fills a gap in the
KoDeclarationCastProvider
API by adding essential support for combined type operations. It enables developers to seamlessly:Use Case:
For example, a developer working with a mixed collection of declarations can now easily retrieve all class-and-interface declarations that match a specific condition, avoiding manual type checks and improving code readability.