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

KON-685 Add missing declaration in KoDeclarationCastProvider for combined types #1547

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

nataliapeterwas
Copy link
Collaborator

@nataliapeterwas nataliapeterwas commented Nov 14, 2024

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:

  1. 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).

  2. New Methods for Casting:
    Introduced methods like asClassOrObjectDeclaration() or asClassOrInterfaceDeclaration() that enable safe casting to specific combined types. This ensures clear and consistent handling of declarations based on their type composition.

  3. 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.

  4. 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:

  • Distinguish between classes, objects, and interfaces in various combinations.
  • Cast or transform declarations to desired combined types.
  • Filter or map lists of declarations using intuitive, high-level abstractions.

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.

Copy link

@nataliapeterwas nataliapeterwas added the improvement nhancements to existing features or code label Nov 14, 2024
@nataliapeterwas nataliapeterwas marked this pull request as ready for review November 14, 2024 21:40
@igorwojda igorwojda merged commit fe50f04 into develop Nov 15, 2024
33 checks passed
@igorwojda igorwojda deleted the update-source-declaration branch November 15, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement nhancements to existing features or code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants