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-681 Add isGeneric for declarations in declaration site #1510

Merged

Conversation

nataliapeterwas
Copy link
Collaborator

@nataliapeterwas nataliapeterwas commented Nov 4, 2024

This PR improves the isGeneric functionality to encompass not only use-site declarations but also declaration-site declarations in Kotlin. Previously, isGeneric was primarily applicable to use-site declarations, such as parent declarations and types. However, the need for extending this functionality to other declaration types, including classes, interfaces, type aliases, properties, and functions, has been recognized.

Enhancements Overview

  1. Classes:

    Konsist code

    val isGeneric = scope
    	.classes()
    	.first()
    	.isGeneric
    • Example 1 (isGeneric Returns true):
      class GenericClass<T>(val value: T)
    • Example 2 (isGeneric Returns false):
      class NonGenericClass(val value: String)
  2. Interfaces:

    Konsist code

    val isGeneric = scope
    	.interfaces()
    	.first()
    	.isGeneric
    • Example 1 (isGeneric Returns true):
      interface GenericInterface<T> {
          fun doSomething(value: T)
      }
    • Example 2 (isGeneric Returns false):
      interface NonGenericInterface {
          fun doSomething()
      }
  3. Type Aliases:

    Konsist code

    val isGeneric = scope
    	.typeAliases
    	.first()
    	.isGeneric
    • Example 1 (isGeneric Returns true):
      typealias GenericTypeAlias<T, V> = (T, V) -> Unit
    • Example 2 (isGeneric Returns false):
      typealias NonGenericType = List<String>
  4. Properties:

    Konsist code

    val isGeneric = scope
    	.properties()
    	.first()
    	.isGeneric
    • Example 1 (isGeneric Returns true):
      val <T> List<T>.property: T
      	get() = first()
    • Example 2 (isGeneric Returns false):
      val property: String = "Non-generic"
  5. Functions:

    Konsist code

    val isGeneric = scope
    	.functions()
    	.first()
    	.isGeneric
    • Example 1 (isGeneric Returns true):
      fun <T> genericFunction(param: T): T {
          return param
      }
    • Example 2 (isGeneric Returns false):
      fun nonGenericFunction(param: String): String {
          return param
      }

Copy link

@nataliapeterwas nataliapeterwas added the improvement nhancements to existing features or code label Nov 4, 2024
…ric-for-declarations-in-declaration-site

# Conflicts:
#	lib/src/main/kotlin/com/lemonappdev/konsist/core/provider/KoIsGenericProviderCore.kt
@nataliapeterwas nataliapeterwas marked this pull request as ready for review November 4, 2024 14:24
@igorwojda igorwojda merged commit 3a7eca3 into develop Nov 4, 2024
33 checks passed
@igorwojda igorwojda deleted the KON-681-add-isgeneric-for-declarations-in-declaration-site branch November 4, 2024 15:25
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